Home > Article > Operation and Maintenance > Must-see Linux commands (summary)
What is Linux
Linux commands are commands for managing Linux systems. For a Linux system, whether it is the central processor, memory, disk drive, keyboard, mouse, or user, they are all files, and the commands for Linux system management are the core of its normal operation. There are two types of Linux commands in the system: built-in shell commands and Linux commands.
In the Linux operating system, one thing to note is that Linux commands (including file names, etc.) have requirements for capitalization. If the entered command has incorrect capitalization, the system will not will produce the response you expect.
Linux command line format
1. Common command line format
命令字 【选项】 【参数】
Options
Short format options: Use the "-" symbol to guide multiple single-character options that can be used together (such as: ls -l ls -al);
Long format command options: Use the "--" symbol to guide (such as: --help).
Parameters
The processing object of the command word;
can be a file name, directory name or user name, etc.;
The number can be zero to multiple.
[root@localhost ~]# means:
root: currently logged in system user
@: delimiter
localhost: host name
~: The current directory location
# key: Indicates the administrator
$: Ordinary user
2, Linux command line Edit
Tab key: Automatically complete
Backslash " \ ": Force a line break
Shortcut key Ctrl U: Clear to the beginning of the line u
Shortcut key Ctrl K: Clear to the end of the line
Shortcut key Ctrl L: Clear the screen
Shortcut key Ctrl C: Cancel this command editing
3. How to get command help
Internal command help: View help information for Bash internal commands
--help: Applicable to most external commands
Man command to read the manual: Use the up and down arrow keys to scroll the text;
Use the Page Up and Page Down keys to turn pages;
Press the Q or key to exit the reading environment, and press "/" to find the content.
Common directory/file operation commands
1. Switch the working directory cd
cd. Switch to the target location
cd ~ If the target location is not specified, switch to the current user's home directory
cd - Switch to the directory where the cd command was last executed
cd.. View the upper directory
cd../../ View the upper directory
cd / root directory
2. Display directory list command ls
ls -l displays file details
ls -a View hidden files
ls -A View hidden files except...
ls -d displays information about this directory
ls -h displays information with units in a friendly form
ls -R displays in reverse (if there are subdirectories, the subdirectories will be Files are displayed in sequence)
pwd displays the user’s current working directory
3. Use color to distinguish file types
Blue----Directory, Folder red ---- compressed package green ---- executable file/command file/script
sky blue ---- soft link file/shortcut file yellow ---- device file/disk File black/white----data file
4, statistics directory and file space usage du
du [Option] [File or directory]
-a Count all files when disk space is occupied
-h Display the statistical results (counted in kB by default)
-s Only count the total size of the occupied space, not statistics The size of each subdirectory file
For example: du -sh /var/log/ Statistics of the total space occupied by var/log files
5. Directory creation mkdir
For example: mkdir test creates a test directory in the current directory
mkdir -p /aa/bb/cc creates the directory aa, the subdirectory bb under aa, and cc under the bb subdirectory
6. File creation (touch) and deletion (rm)
touch test.txt Create a test.txt file in the current directory
touch demo {1..10}.txt Create multiple new empty files
rm -f test.txt Directly delete the text.txt file
rm -r Recursively delete, that is Delete the directory and its subdirectories
rm -rf Directly delete the directory and its subdirectories
7, copy the file or directory cp
-f Overwrites the target file with the same name and does not prompt, copy and paste directly
-i Overwrites the target file with the same name and prompts the user to confirm
-p Keeps the permissions of the source file when copying, and the attributes are not Change
-r This option must be used when copying a directory, which means recursively copy all files
8. Find data files or directoriesfind
By file Name search-name
Search by file size-size
Search by file owner-user
Search by file type-type
File type: Ordinary file (f), directory (d), block device file (b), character device file (c)
9. View file content
cat displays the file content starting from the first line
more Displays the file content page by page, used to display the file content in pages in full screen mode
less is similar to more, but is better than more in terms of extended functions More
head View part of the content at the beginning of the file (default 10 lines) Example: head -n file name (n indicates which line)
tail View a small part of the content at the end of the file
10. Statistics of file content wc
Statistics of the number of words in the file and other information
-l Statistics of the number of lines
-w Statistics of the number of words
-c Count the number of bytes
The difference between wc and du:
wc: The number of statistical contents
du: The size of the statistical file
11. File archiving command tar
-C: Create compressed package -x: Decompress -f: Execute -v: Show detailed process -p: Keep original file permissions
-t: View the compressed content -C: Decompression path -Z: gzip format -j: bzip2 format
Compression command: gzip, bzip2
-q: High compression ratio -d: Unzip the compressed file
12. Three working modes of vim editor
a: represents after the cursor. Insert
i: Insert
before the cursor. o: Insert
in the next line under the cursor. O: Insert
## in the line above the cursor. #Basic operations in command mode:
home key or ^, number 0: jump to the beginning of the file End key or $: jump to the end of the line 1G or gg: jump to the end of the file First line G: jump to the end line of the file #G: jump to the #th line of the file : set nu displays the line number in the editor :set nonu Cancel line number:set nu! Cancel the line number13. The meaning of Linux startup level init0-6
init 0: Shutdown init 1: Single user mode (root only) for maintenance)init 2: Multi-user mode without network character interfaceinit 3: Full multi-user mode with network character interfaceinit 4: Safe mode (reserved) init 5: Multi-user mode graphical interfaceinit 6: RebootThere are many commands to learn Linux. You need to memorize and practice more so that you will not forget them. , you also need to understand the meaning of each command to know what you need to configure. For more Linux knowledge, please visit theLinux Tutorial column!
The above is the detailed content of Must-see Linux commands (summary). For more information, please follow other related articles on the PHP Chinese website!