Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A complete Collection of basic knowledge points of Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "Linux basic knowledge points Daquan", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux basic knowledge points Daquan" bar!

First, start from the understanding of the operating system

1.1 introduction to the operating system

I will introduce the operating system through the following four points:

Operating system (Operation System, referred to as OS) is a program that manages computer hardware and software resources, and is the core and cornerstone of a computer system.

An operating system is essentially a software program running on a computer.

Provide users with an interface to interact with the system.

The operating system is divided into the kernel and the shell (we can think of the shell as the application around the kernel, which is the program that can operate the hardware).

The operating system is divided into kernel and shell

1.2 simple classification of operating systems

Windows: currently popular personal desktop operating system, do not do much introduction, we all know.

Unix: the earliest multi-user, multi-tasking operating system. According to the classification of operating system, it belongs to time-sharing operating system. Unix is mostly used in servers and workstations, and now it is also used in personal computers. It plays a very important role in creating the Internet, computer network, or client / server model.

Linux: Linux is a free-to-use and freely distributed Unix-like operating system. There are many different versions of Linux, but they all use the Linux kernel. Linux can be installed in a variety of computer hardware devices, such as mobile phones, tablets, routers, video game consoles, desktops, mainframes and supercomputers. Strictly speaking, the word Linux itself only refers to the Linux kernel, but in fact people have become accustomed to using Linux to describe the entire Linux kernel and use GNU to project operating systems with various tools and databases.

II. A preliminary study of Linux

2.1 introduction to Linux

We have already introduced Linux above, and we only emphasize three points here.

Unix-like system: Linux is a free, open source Unix-like operating system

Linux kernel: strictly speaking, the word Linux itself only refers to the Linux kernel

Father of Linux: a legendary figure in the field of programming. He was the earliest author of the Linux kernel and then launched the open source project as the chief architect and project coordinator of the Linux kernel and is one of the most famous computer programmers and hackers in the world today. He also launched the open source project Git and is a major developer.

2.2 introduction to the birth of Linux

In 1991, Finnish computer amateur Linus Torvalds wrote a Minix-like system (a Unix-like operating system based on microkernel architecture) that was named Linux by ftp administrators to join the GNU program of the Free Software Foundation.

Linux takes a lovely penguin as a symbol, symbolizing daring and loving life.

2.3 Classification of Linux

According to the degree of origin, Linux is divided into two types:

Kernel version: Linux is not an operating system. Strictly speaking, Linux is just a kernel in an operating system. What is the kernel? The kernel establishes a platform for communication between computer software and hardware, and the kernel provides system services, such as file management, virtual memory, device Imax O, etc.

Release: a reissued version that is redeveloped by some organizations or companies on the basis of the internal core version. There are many Linux distributions (both ubuntu and CentOS are widely used. It is recommended to choose CentOS for beginners), as shown below:

Linux distribution

III. Overview of Linux file system

3.1 introduction to the Linux file system

In the Linux operating system, all resources managed by the operating system, such as network interface cards, disk drives, printers, input and output devices, ordinary files or directories, are regarded as a file.

In other words, there is an important concept in the LINUX system: everything is a file. In fact, this is an embodiment of UNIX philosophy, and Linux is a rewriting of UNIX, so this concept has been passed on. In UNIX system, all resources are regarded as files, including hardware devices. UNIX system regards each hardware as a file, which is usually called a device file, so that users can access the hardware by reading and writing files.

3.2 File types and directory structure

Linux supports five file types:

The directory structure of Linux is as follows:

The Linux file system is structured like an upside-down tree, with its root directory at the top:

Directory structure of Linux

Common catalog description:

/ bin: stores binary executable files (ls,cat,mkdir, etc.). Commonly used commands are usually here.

/ etc: stores system management and configuration files

/ home: the root directory where all user files are stored, which is the base point of the user's home directory. For example, the home directory of the user user is / home/user, which can be represented by ~ user.

/ usr: used to store system applications

/ opt: the location where additional installed optional application packages are placed. In general, we can install tomcat and so on here.

/ proc: virtual file system directory, which is the mapping of system memory. You can access this directory directly to get system information

/ root: home directory of the superuser (system administrator) (privileged class o)

/ sbin: stores binary executables that can only be accessed by root. What is stored here are system-level management commands and programs used by system administrators. Such as ifconfig, etc.

/ dev: used to store device files

/ mnt: the mount point where the system administrator installs the temporary file system. The system provides this directory for users to mount other file systems temporarily.

/ boot: stores various files used for booting the system

/ lib: stores the library files related to the operation of the system

/ tmp: used to store all kinds of temporary files, which is a common temporary file storage point

/ var: used to store files that need to change data at runtime, and it is also an overflow area for some large files, such as log files for various services (system startup log, etc.). ), etc.

/ lost+found: this directory is usually empty, and the "homeless" file (.chk under windows) is here when the system is not shut down properly.

IV. Basic Linux commands

Here are just some of the more commonly used commands. Recommend a Linux command quick check website, very good, if you forget some commands or do not understand some commands can be solved here.

4.1 Directory switching command

Cd usr: change to the usr directory under this directory

Cd.. (or cd../): switch to the previous directory

Cd /: switch to the system root

Cd ~: switch to the user home directory

Cd -: switch to the directory where the previous operation is located

4.2 directory operation command (add, delete, change and check)

Mkdir directory name: add directory

Ls or ll (ll is an alias for ls-l, and the ll command can see the details of all directories and files in this directory): view directory information

Find directory parameter: find directory (check)

Example:

List all files and folders in the current directory and subdirectories: find.

Look in the / home directory for the file name ending in .txt: find / home-name "* .txt"

Ditto, but ignore case: find / home-iname "* .txt"

Find all files ending in .txt and .pdf in the current directory and subdirectories: find. \ (- name "* .txt"-o-name "* .pdf"\) or find. -name "* .txt"-o-name "* .pdf"

Mv directory name new directory name: modify the name of the directory (change)

Note: the syntax of mv can rename not only directories but also various files, compressed packages, etc. The mv command is used to rename a file or directory or to move a file from one directory to another. Another use of the mv command will be covered later.

New location of the mv directory name directory: move the location of the directory-cut (change)

Note: mv syntax can cut not only directories, but also files and compressed packages. In addition, the result of mv is different from that of cp. Mv is like a file "moving", and the number of files has not increased. While cp copies files, the number of files increases.

Cp-r directory name destination location of directory copy: copy directory (modified),-r represents recursive copy

Note: the cp command can copy not only directories but also files, compressed packages, etc., without writing-r recursion when copying files and compressed packages.

Rm [- rf] directory: delete directory (delete)

Note: rm can delete not only directories, but also other files or files. In order to enhance everyone's memory, no matter delete any directory or file, use rm-rf directory / file / package directly.

4.3 the operation command of the file (addition, deletion, modification and search)

Touch file name: creation of files (added)

View of cat/more/less/tail file name file (check)

Cat: viewing the contents of the display file

More: you can display the percentage, enter can go to the next line, spaces can go to the next page, and Q can exit the view.

Less: you can use the PgUp and PgDn on the keyboard to page up and down, and Q ends the view.

Tail-10: view the last 10 lines of the file, ending with Ctrl+C

Note: the command tail-f file can dynamically monitor a file, such as the log file of tomcat. The log will change with the running of the program. You can use tail-f catalina-2016-11-11.log to monitor the changes of the document.

Vim files: modifying the contents of a file (change)

Vim editor is a powerful component of Linux, is an enhanced version of vi editor, vim editor commands and shortcuts there are many, but not one by one here, we do not need to study very thoroughly, the way to edit and modify files using vim will basically use it.

In actual development, the main purpose of using the vim editor is to modify the configuration file. Here are the general steps:

Vim file-> enter file-> command mode-> press I to enter edit mode-> edit file-> press Esc to enter bottom line mode-> input: wq/q! (enter wq for writing and exit, that is, save; enter Q! Represents a forced exit without saving. )

Rm-rf files: delete files (delete)

Delete in the same directory: just memorize the rm-rf file

4.4 Operation commands for compressed files

1) package and compress the file:

Package files in Linux typically end with .tar, and compressed commands typically end with .gz.

In general, packaging and compression are carried out together, and the suffix name of the packaged and compressed file is generally .tar.gz.

Command: tar-zcvf package compressed file name to package compressed file

Where:

Z: call the gzip compression command to compress

C: package the file

V: show the running process

F: specify a file name

For example, there are three files under the test directory: aaa.txt bbb.txt ccc.txt. If we want to package the test directory and specify that the compressed package name is test.tar.gz, we can use the command: tar-zcvf test.tar.gz aaa.txt bbb.txt ccc.txt or: tar-zcvf test.tar.gz / test/

2) decompress the compressed package:

Command: tar [- xvf] compressed file

Where: X: represents decompression

Example:

1 decompress the test.tar.gz under / test to the current directory using the command: tar-xvf test.tar.gz

2 extract the test.tar.gz under / test to the root directory / usr: tar-xvf xxx.tar.gz-C / usr (- C represents the specified location for decompression)

4.5 permission commands for Linux

Each file in the operating system has specific permissions, users, and groups. Permission is a mechanism used by the operating system to restrict access to resources. In Linux, permissions are generally divided into readable, writable and excutable, which are divided into three groups. Corresponding to the file owner (owner), group (group) and other users (other), this mechanism is used to restrict which users and which groups can perform what operations on specific files. Through the ls-l command, we can view the permissions of files or directories in a directory.

Example: ls-l in a random directory

The information in the first column is explained as follows:

The following will explain in detail the types of files, permissions in Linux, and what are the owners, groups, and other groups of files?

Type of file:

D: representative directory

-: representative document

L: stands for soft links (can be thought of as shortcuts in window)

There are several kinds of permissions in Linux:

R: indicates that the permission is readable, and r can also be represented by the number 4

W: indicates that the permission is writable, and w can also be represented by the number 2

X: indicates that the permission is executable, and x can also be represented by the number 1

The difference between file and directory permissions:

Read and write execution means different things to files and directories.

For files:

For directories:

It should be noted that superusers can ignore the permissions of ordinary users and can still be accessed even if the file directory permission is 000.

Each user in linux must belong to a group and cannot be independent of the group. In linux, each file has the concept of owner, host group, and other groups.

Owner

Generally speaking, the creator of the file, who created the file, will naturally become the owner of the file. With the ls-ahl command, you can see that the owner of the file can also use the chown user name file name to modify the owner of the file.

Group in which the file belongs

When a user creates a file, the group of the file is the group that the user belongs to. You can see all the groups of the file with the ls-ahl command, and you can also use the chgrp group name to modify the group of the file.

Other groups

Except for the owner of the file and the users of the group, the other users of the system are all other groups of the file.

Let's take a look at how to modify the permissions of files / directories.

Command to modify permissions for files / directories: chmod

Example: modify the permissions of aaa.txt under / test so that the owner has full permissions, the group to which the owner belongs has read and write permissions, and other users only have read permissions.

Chmod uprirwx aaa.txt gendrwm obsolete

The above example can also be represented by numbers:

Chmod 764 aaa.txt

Add a more common thing:

What if we install a zookeeper and ask it to start automatically every time we turn it on?

Create a new script zookeeper

To add executable permissions to the newly created script zookeeper, the command is: chmod + x zookeeper

Add the script zookeeper to the boot entry with the command: chkconfig-- add zookeeper

If you want to see if the addition is successful, the command is: chkconfig-- list

4.6 Linux user Management

Linux system is a multi-user and multi-task time-sharing operating system. Any user who wants to use system resources must first apply for an account from the system administrator, and then enter the system as this account.

On the one hand, users' accounts can help system administrators track users who use the system and control their access to system resources; on the other hand, they can also help users organize files and provide security protection for users.

Linux user management related commands:

Useradd option user name: add user account

Userdel option username: delete user account

Usermod option user name: modify account

Passwd user name: change or create a user's password

Passwd-S user name: displays user account password information

Passwd-d user name: clear user password

The useradd command is used for new system users created in Linux. Useradd can be used to set up user accounts. After the account is set up, use passwd to set the password of the account. You can use userdel to delete the account. The account created using the useradd directive is actually saved in the / etc/passwd text file.

The passwd command is used to set the user's authentication information, including user password, password expiration time, and so on. System managers can use it to manage the passwords of system users. Only the administrator can specify the user name, and the average user can only change his or her password.

4.7 Management of user groups in Linux system

Each user has a user group, and the system can centrally manage all users in a user group. Different Linux systems have different rules for user groups, for example, users under Linux belong to a user group with the same name, which is created at the same time as the user is created.

The management of user groups involves the addition, deletion and modification of user groups. Group additions, deletions, and modifications are actually updates to the / etc/group file.

Commands related to the management of Linux system user groups:

Groupadd option user group: add a new user group

Groupdel user group: to delete an existing user group

Groupmod option user group: modify the properties of a user group

4.8 other common commands

Pwd: displays the current location

Grep string to search the file to be searched-- color: search command,-- color stands for highlighting

Ps-ef/ps aux: both commands check to see that the current system is running a process, but the difference is that the presentation format is different. If you want to view a specific process, you can use this format: ps aux | grep redis (view processes including redis strings)

Note: if you use the ps ((Process Status)) command directly, the status of all processes will be displayed, usually in conjunction with the grep command to check the status of a process.

Pid of the kill-9 process: kills the process (- 9 indicates forced termination. )

First use ps to find the process, then use kill to kill

Network communication commands:

View the network card information of the current system: ifconfig

Check the connection to a machine: ping

View the port usage of the current system: netstat-an

Shutdown: shutdown-h now: specify the shutdown now; shutdown + 5 "System will shutdown after 5 minutes": specify the shutdown after 5 minutes, and send a warning message to the logged-in user.

Reboot: reboot: restart. Reboot-w: do a simulation of rebooting (only records don't really reboot).

Thank you for your reading, the above is the content of "Linux basic knowledge points Daquan", after the study of this article, I believe you have a deeper understanding of the problem of Linux basic knowledge points Daquan, the specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report