In the Linux world, the most indispensable is the Linux Command Line application. The Linux Command Line can help us quickly find what we want, complete what we want to do, and complete various tedious tasks in batches. It is a powerful tool for system management and application. This article mainly introduces the most common Linux commands for a large Linux Command literacy.
Su
The su command is one of the most basic commands and is often used for switching between different users. For example, to switch to user2 if user1 is logged on, use the following command:
$su user2
Then the system prompts you to enter the user2 password. after entering the correct password, you can switch to user2. After that, you can use the exit command to return to user1.
The common usage of the su command is to become the root user or Super User. If the su command without the user name is issued, the system prompts you to enter the root password. after entering the root password, you can switch to the root user.
If you log on as the root user, you can use the su command to become any user on the system without a password.
Pwd
The pwd command is also one of the most common and basic commands used to display the current directory of the user.
Cd
The cd command not only displays the current status, but also changes the current status. It is basically the same as the cd command in dos.
Cd .. you can enter the previous directory cd-you can enter the previous directory cd ~ You can access the user's home directory
Ls
Like the dir command in dos, the ls command is used to display the content of the current directory.
If you want to obtain detailed information, you can use the ls-l command to display detailed information about the directory content.
If the directory contains too many files and cannot be displayed on one screen, use ls-l | more split screen.
Find
The find command is used to find files. This command can be searched by file name, creation or modification date, owner (usually the user who creates the file), file length, or file type.
The basic structure of the find command is as follows:
$find
Specify the directory from which to start searching. Specify search criteria. Indicates how to locate the file. Generally, use the-print action to display the path and name of the entire file. If this action is not performed, the find Command performs the search without displaying the result.
For example, to search for all files named ye on the system, run the following command:
$find / -name ye -print
In this way, all files named ye can be displayed.
Tar
Tar was originally used to create a tape backup system and is currently widely used to create file publishing files. You can use the following method to create a tar file:
$tar cvf
For example, to save all files in the current directory to ye.tar, run the following command:
$tar cvf ye.tar *.*
To browse the file content, change the c option to t. To view the content in the ye.tar file, run the following command:
$tar tvf ye.tar
To retrieve the content in the file, convert the c option to x. To retrieve the content in the ye.tar file to the current directory, run the following command:
$tar xvf ye.tar
Gzip
The gzip command is used to compress files. For example, to compress the ye.txt file, run the following command:
$gzip ye.txt
In this example, you can compress the file and add a gzextension name after the file name to convert it into a file ye.txt.gz.
Decompress the file using the gzip-d command:
$gzip -d ye.txt.gz
In this way, you can decompress the file and delete the gz extension. In addition, you can use the gunzip command to decompress the file. The effect is the same as that of the gzip-d command.
The old tar command does not compress files and can be compressed using gzip. For example:
$tar cvf ye.tar *.txt$gzip ye.tar
You can create a compressed file ye.tar.gz.
The new version of tar can directly access and create gzip compressed tar files, as long as you add the z option in the tar command. For example:
$tar czvf ye.tar *.txt
Generated archives ye.tar.gz,
$tar tzvf ye.tar *.txt
Displays the content of the compressed file ye.tar.gz, while
$tar xzvf ye.tar *.txt
Obtain the content of the compressed file ye.tar.gz.
Mkdir
This command is very simple. It is used almost the same as the dos md command to create a directory.
Cp
The cp command is used to copy files or directories.
The cp command can copy multiple files at a time, for example:
$cp *.txt *.doc *.bak /home
Copy all the files with the extension txt, doc, and bak in the current directory to the/home directory.
To copy the entire directory and all its subdirectories, run the cp-R command.
Rm
The rm command is used to delete files or directories.
The rm command forcibly deletes the file. If you want to confirm the deletion, run the rm-I command.
To delete a directory, run the rm-r command. When the rm-r command deletes a directory, a prompt is displayed for each file or directory to be deleted. If the directory is too large, it is unrealistic to respond to each prompt. In this case, you can use the rm-rf command to forcibly Delete the directory. In this case, the-I flag is used and the process is invalid.
Mv
The mv command is used to move files and rename files. For example:
$mv ye.txt /home
Move the ye.txt file under the current directory to the/home directory,
$mv ye.txt ye1.txt
Rename the ye.txt file to ye1.txt.
Similar to the cp command, the mv command can also move multiple files at a time.
Reboot
Restart command. Needless to say.
Halt
Shutdown command. Needless to say.