Abbreviation of common parameters | Full name of parameter | describe |
---|
-a | --all | List all files in the directory, including "." Implied file at the beginning |
-l | | In addition to the file name, the file permission, owner, file size and other information are listed in detail |
-h | --human-readable | List file sizes in an easy to understand format |
-t | | Sort by file modification time |
# Lists the details of all files and directories in the / usr folder
$ ls -al /usr
# Lists the details of all file directories starting with "y" in the current directory
$ ls -al y*
# List the sizes of all files and directories in the / usr directory in an easy to understand format
$ ls -alh /usr
# Enter the system root directory from the current directory
$ cd /
# Enter parent directory from current directory
$ cd ..
# Enter the current user's home directory from the current directory
$ cd ~
# Enter the last directory from the current directory
$ cd -
Abbreviation of common parameters | Full name of parameter | describe |
---|
-P | | Displays the actual physical path instead of using the link path |
-L | | When the directory is a connection path, the connection path is displayed |
# Displays the path where the current directory is located
$ pwd
# Displays the physical path of the current directory
$ pwd -P
# Displays the connection path of the current directory
$ pwd -L
Abbreviation of common parameters | Full name of parameter | describe |
---|
-m | --mode | Set permissions < mode > |
-p | --parents | Can be a path name. If some directories in the path do not exist, after adding this option, the system will automatically establish those directories that do not exist, that is, multiple directories can be established at a time |
-v | --verbose | Information is displayed each time a new directory is created |
# Create multiple directories recursively
$ mkdir -p yohann/test
# Create a directory with permission 777
$ mkdir -m 777 yohann
# Create directory display information
$ mkdir -vp yohann/test
Abbreviation of common parameters | Full name of parameter | describe |
---|
-f | --force | Ignore nonexistent files and never prompt |
-i | --interactive | Interactive deletion |
-r | --recursive | Instructs rm to recursively delete all directories and subdirectories listed in the parameter |
-v | --verbose | Show the steps in detail |
# Delete file
$ rm test.txt
# Forcibly delete files
$ rm -f test.txt
# Delete the suffix log all
$ rm *.log
Abbreviation of common parameters | Full name of parameter | describe |
---|
-b | --back | If the file needs to be overwritten, backup it before overwriting |
-f | --force | If the target file already exists, it will not be queried but directly overwritten |
-i | --interactive | If the target file already exists, you will be asked whether to overwrite it |
-u | --update | If the target file already exists and the source file is relatively new, it will be updated |
-t | --target | This option is applicable to moving multiple source files to a directory. At this time, the target directory is first and the source file is second |
# The file test Rename log to error log
$ mv test.log error.log
# The file error Log is moved to the log directory
$ mv error.log log
# The file info Log is moved to the log directory. If the file exists, you will be asked whether to overwrite it before overwriting
$ mv -i info.log log
Abbreviation of common parameters | Full name of parameter | describe |
---|
-t | --target-directory | Specify target directory |
-i | --interactive | Ask before overwrite (invalidate the previous - n option) |
-n | --no-clobber | Do not overwrite existing files (invalidate the previous - i option) |
-s | --symbolic-link | Establish symbolic links to source files instead of copying files |
-f | --force | Forcibly copy files or directories, regardless of whether the destination file or directory already exists |
-u | --update | After using this parameter, the source file will be copied only when the modification time of the source file is newer than that of the destination file, or the corresponding destination file does not exist |
# For file index HTML to create a symbolic link home html
$ cp -s index.html home.html
# Copy all files in the image directory to the upload directory. Ask before overwriting
$ cp -i image/* upload
# Copy the recently updated files in the image directory to the upload directory. Ask before overwriting
$ cp -iu image/* upload
Abbreviation of common parameters | Full name of parameter | describe |
---|
-A | --show-all | Equivalent to - vET |
-b | --number-nonblank | Number non empty output lines |
-e | | Equivalent to - vE |
-E | --show-ends | Show at the end of each line$ |
-n | --number | Number all output lines, starting from 1 |
-s | --squeeze-blank | If there are more than two consecutive blank lines, replace them with one blank line |
-t | | Equivalent to - vT |
-T | --show-tabs | Show skip characters as ^ I |
-u | | (ignored) |
-v | --show-nonprinting | Use ^ and M-references, except LFD and TAB |
# Put error-20220101 After adding the line number to the file content of log, enter error Log in this file
$ cat -n error-20220101.log > error.log
# Put error-20220101 After adding the line number to the file content of log, enter error In the log file, multiple blank lines are replaced with one line for output
$ cat -ns error-20220101.log > error.log
# Set error The contents of the log file are displayed in reverse
$ tac error.log
Abbreviation of common parameters | Full name of parameter | describe |
---|
-ba | --body-numbering=a | Indicates that the line number is also listed whether it is empty or not (similar to cat -n) |
-bt | --body-numbering=t | If there is an empty line, do not list the line number of the empty line (default value) |
-n ln | --number-format=ln | The line number is displayed on the far left of the screen |
-n rn | --number-format=rn | The line number is displayed on the rightmost side of its own field without adding 0 |
-n rz | --number-format=rz | The line number is displayed on the rightmost side of its field, plus 0 |
-w | --number-width | Number of digits occupied by line number field |
# Put error The contents of the log file are displayed after adding the line number, and blank lines are not added with the line number
$ nl -b t error.log
# Put error Log file content is displayed after adding the line number. The line number is displayed on the leftmost, rightmost without 0 and rightmost with 0 respectively
$ nl -n ln error.log
$ nl -n rn error.log
$ nl -n rz error.log
# Put error The file content of log is displayed after adding the line number. The line number is displayed by adding 0 to the right of the screen, and the occupation number of line number column is 3
$ nl -n rz -w 3 error.log
Abbreviation of common parameters | Full name of parameter | describe |
---|
+n | | Display from line n |
-n | | Defines the screen size as n lines |
+ | | Search for the string before each file display, and then display it after the first two lines of the string |
-c | | Clear the screen from the top and display |
-d | | Disable ringing function |
-p | | Page feed the file by clearing the window instead of scrolling, similar to the - c option |
-s | | Displays consecutive blank lines as one line |
-u | | Remove the underline from the contents of the document |
Common operation symbols | describe |
---|
= | Output the line number of the current line |
q | Exit more |
Space bar | Scroll down one screen |
b | Return to previous screen |
# Error is displayed from the fifth line Contents in log file
$ more +5 error.log
# From error Log file to find the first line where the "y" string appears, and display the output from the first two lines there
$ more +/y error.log
# Set the number of lines per screen to 10
$ more -10 error.log
# Use the ll and more commands to display the / etc/nginx directory information
$ ll /etc/nginx | more -10
Abbreviation of common parameters | Full name of parameter | describe |
---|
-e | | When the file display ends, it will leave automatically |
-f | | Force the opening of special files, such as peripheral codes, directories, and binaries |
-i | | Ignore case when searching |
-m | | Displays the percentage similar to the more command |
-N | | Displays the line number of each line |
-s | | Displays a row of consecutive empty rows |
Common operation symbols | describe |
---|
/String | Ability to drill down on "string" |
? character string | The ability to search up for "string" |
n | Repeat the previous search (related to / or?) |
N | Reversely repeats the previous search (related to / or?) |
b | Turn one page forward |
d | Turn back half a page |
q | Exit the less command |
Space bar | Turn back one page |
Up key | Flip up a line |
Down key | Flip down one line |
# Display error Log file and display the line number
$ less -N error.log
# Display error Log file, search string "500"
$ less error.log
/500
# ps view the process information and display it in less pages
$ ps -f | less
Abbreviation of common parameters | Full name of parameter | describe |
---|
-q | --quiet | Hide file name |
-v | --verbose | Display file name |
-C < byte > | --bytes | Display bytes |
-N < number of lines > | --lines | Number of rows displayed |
# Display error The first 10 lines in the log file
$ head -n 5 error.log
# Error-2020-01-01 is displayed Log and error-2021-01-01 The first 5 lines in the log file
$ head -n 5 error-2020-01-01.log error-2021-01-01.log
Abbreviation of common parameters | Full name of parameter | describe |
---|
-f | | Cyclic reading |
-q | | Do not display processing information |
-v | | Displays detailed processing information |
-C < byte > | | Number of bytes displayed |
-N < number of lines > | | Display rows |
# Display error The last 10 lines in the log file
$ tail -n 10 error.log
# Display error The last 10 lines in the log file, when error The log file automatically updates the display when new content is added
$ tail -n 10 -f error.log
# Confirm that php is installed
$ which php
# View the location and path of python commands
$ which python
Abbreviation of common parameters | Full name of parameter | describe |
---|
-b | | Locate executable |
-m | | Locate help files |
-s | | Locate source code files |
-u | | Search for files other than executable files, source code files and help files in the default path |
-B | | Specifies the path to search for executable files |
-M | | Specifies the path to search for help files |
-S | | Specifies the path to search for source code files |
# Search the path of the php executable
$ whereis -b php
# Search the path to the php help file
$ whereis -m php
# Search the path of php source code
$ whereis -s php
Abbreviation of common parameters | Full name of parameter | describe |
---|
-q | --quiet | Quiet mode, no error messages will be displayed |
-n | | Display up to n outputs |
-r | --regexp | Use regular expressions to find conditions |
-V | --version | display version information |
# Search all files starting with p in / usr/bin directory
$ locate /usr/bin/p*
# Search for files whose file name contains log in the / var/log directory
$ locate /var/log/*log*
Abbreviation of common parameters | Full name of parameter | describe |
---|
-print | | The find command outputs the matching file to standard output |
-exec | | The find command executes the shell command given by this parameter on the matching file |
-name | | Find files by file name |
-type | | Find a type of file |
-prune | | Use this option to make the find command not search in the currently specified directory. If you use the - depth option at the same time, then - prune will be ignored by the find command |
-user | | Find files by file owner |
-group | | Find files by the group to which they belong |
-mtime -n +n | | Find the file according to the file change time, - N indicates that the file change time is less than n days now, + n indicates that the file change time is more than n days now. The find command also has - atime and - ctime options |
# Print the list of files in the current directory
$ find . -print
# Print all in the current directory File name ending in c
$ find . -name "*.c" -print
# Print all in the current directory jpg or png ending file name
$ find . \( -name "*.jpg" -or -name "*.png" \)
# Print all files in the current directory File name at the end of pdf
$ find . ! -name "*.pdf"
# Print all php files with 777 permissions in the current directory
$ find . -type f -name "*.php" -perm 777
# Print all files owned by root in the current directory
$ find . -type f -user root
# Print all files with permissions other than 777 and 664 in the current directory
$ find . -type f \( ! -perm 777 -and ! -perm 644 \)
# Find all c files in the current directory and display their details
$ find . -name "*.c" -exec ls -l {} \;
# Write all c language code files into one file
$ find . -name "*.c" -exec cat {} \; > all.c
# Check all c language code files and execute the script
$ find . -name "*.c" -exec ./command.sh {} \;
Abbreviation of common parameters | Full name of parameter | describe |
---|
-n | --max-args | Specifies the maximum number of parameters per row |
-d | --delimiter | Specify separator |
# Convert multi line input to single line output
$ cat info.txt | xargs
# Convert single line input to multi line output
$ echo "1 2 3 4 5 6 7" | xargs -n 3
# Convert single line input to multi line output, specifying the separator as a space
$ cat info.txt | xargs -d " " -n 3
# Find all vue code files in the current directory and count the total number of rows
$ find . -type f -name "*.vue" | xargs wc -l
Abbreviation of common parameters | Full name of parameter | describe |
---|
-c | --bytes | Count bytes |
-l | --lines | Count rows |
-m | --chars | Count the number of characters. This flag cannot be used with the - c flag |
-w | --words | Count the number of words. A word is defined as a string separated by white space, skip, or newline characters |
-L | --max-line-length | Prints the length of the longest line |
# Count the number of bytes, lines and characters of the file
$ wc -c info.txt
$ wc -l info.txt
$ wc -m info.txt
# Count the number of bytes, lines and characters of the file. Only numbers are printed, not the file name
$ cat c.txt | wc -c
$ cat c.txt | wc -l
$ cat c.txt | wc -m
# Count the number of commands in the / bin directory
$ ls /bin | wc -l
Abbreviation of common parameters | Full name of parameter | describe |
---|
-c | --count | Count the number of times a 'search string' (i.e. pattern) is found |
-i | --ignore-case | The case difference is ignored, so the case is considered the same |
-n | --line-number | Output line number |
-v | --invert-match | Reverse selection to print unmatched lines |
-r | --recursive | Recursively searching |
--color=auto | | Color the found keywords |
# Take out the line where root appears in the / etc/passwd file, and the keyword part is displayed in color
$ grep "root" /etc/passwd \-\-color=auto
$ cat /etc/passwd | grep "root" \-\-color=auto
# Take out the lines in the / etc/passwd file where root and nologin do not appear
$ grep -v "root" /etc/passwd | grep -v "nologin"
# Recursively search for files containing "login()" in the current directory
$ grep -r "login()".
Abbreviation of common parameters | Full name of parameter | describe |
---|
-b | --bytes | Split in bytes |
-c | --characters | Split in characters |
-d | --delimiter | Custom separator, tab by default |
-f | --fields | Custom field |
--complement | | Extract the entire line of text, except those specified by the - c or - f option |
# Remove info Txt file
$ cut -f 1,3 -d ' ' info.txt
# Remove info Txt file
$ cut -f 1 -d ' ' info.txt
# Remove info Txt file
$ cut -f 1-3 -d ' ' info.txt
# Remove info Txt file except the first column
$ cut -f 1 -d ' ' info.txt \-\-complement
Abbreviation of common parameters | Full name of parameter | describe |
---|
-s | --serial | Merge each file into a line instead of pasting by line |
-d | --delimiters | Custom separator, tab by default |
# Set member Txt and phone The contents of TXT file are spliced by column
$ paste member.txt phone.txt
# Set member Txt and phone The contents of TXT file are spliced by column, and the specified separator is ":
$ paste member.txt phone.txt -d ':'
# Set member Txt and phone The contents of the txt file are spliced into a line
$ paste -s member.txt phone.txt
Abbreviation of common parameters | Full name of parameter | describe |
---|
-d | --delete | Delete the matching content without replacing it |
# Converts the entered characters from uppercase to lowercase
$ echo 'THIS IS YOHANN!' | tr 'A-Z' 'a-z'
# Delete the number from the input character
$ echo 'THIS IS YOHANN001!' | tr -d '0-9'
# ROT13 encryption
$ echo 'yohann' | tr 'a-zA-Z' 'n-za-mN-ZA-M'
Abbreviation of common parameters | Full name of parameter | describe |
---|
-n | --numeric | Sort based on the length of the string, using this option allows sorting based on numeric values rather than alphabetic values |
-k | --key | Specify sort key |
-b | --ignore-leading-blanks | By default, the entire row is sorted, starting with the first character of each row. This option causes the sort program to ignore the space at the beginning of each line and sort from the first non white space character |
-m | --merge | Merge only multiple input files |
-r | --reverse | Sort in reverse order, and the results are in descending order, not ascending order |
-t | --field-separator | Custom separator, tab by default |
# List the top 10 directory files that use the most space in the / usr/share / directory
$ du -s /usr/share/* | sort -nr | head -10
# Sort the space size field in the output information of ls command
$ ls -l /usr/share/ | sort -nr -k 5 | head -1
Abbreviation of common parameters | Full name of parameter | describe |
---|
-c | --count | Prefix each line with a number indicating the number of occurrences of the corresponding line item |
-d | --repeated | Only duplicate rows are output |
-u | --unique | Show only unique rows |
-D | | Show all duplicate rows |
-f | --skip-fields | Skip the first n columns during comparison |
-i | --ignore-case | The comparison is case insensitive |
-s | --skip-chars | Skip the first n characters during comparison |
-w | --check-chars | The contents after the nth character of each line are not compared |
# Find all the same commands in the / bin directory and / usr/bin directory
$ ls /bin /usr/bin | sort | uniq -d
Abbreviation of common parameters | Full name of parameter | describe |
---|
-j FIELD | | Equivalent to - 1 FIELD -2 FIELD, - j specifies a field as the matching field |
-1 FIELD | | Match with the FIELD field in file1 |
-2 FIELD | | Match with the FIELD field in file2 |
-t | | Custom separator, tab by default |
# Connect the two files by using the first field in the two files as the matching field
$ join member.txt phone.txt
Abbreviation of common parameters | Full name of parameter | describe |
---|
-1 | | Do not output lines specific to file 1 |
-2 | | Do not output lines specific to file 2 |
-3 | | Do not output lines common to two files |
# Compare old Txt and new Txt the contents of the two files
$ comm old.txt new.txt
# Compare old Txt and new Txt the contents of two files. Only the contents common to the two files are displayed
$ old.txt and new.txt
Abbreviation of common parameters | Full name of parameter | describe |
---|
-c | --context | Context mode, display all the text and mark the differences |
-u | --unified | Unified mode to display the first mock exam file in a combined way. |
-a | --text | Only text files are compared line by line |
-N | --new-file | When comparing directories, if file A only appears in A directory, the default will display: Only in directory. If you use the - N parameter, diff compares file A with A blank file |
-r | --recursive | Recursive comparison of files in the directory |
# Display old Txt and new Txt difference between two files
$ diff old.txt new.txt
# Context mode displays old Txt and new Txt difference between two files
$ diff -c old.txt new.txt
# The first mock exam shows old.. Txt and new Txt difference between two files
$ diff -u old.txt new.txt
Abbreviation of common parameters | Full name of parameter | describe |
---|
-p num | --strip | Ignore several layers of folders |
-E | --remove-empty-files | If an empty file is found, delete it |
-R | --reverse | Cancel the patch |
# Generate old Txt and new Txt difference file
$ diff -Naur old.txt new.txt > patchdiff.txt
# Update old with the patch command Txt file
$ patch < patchdiff.txt
# Cancel the patch above
$ patch < patchdiff.txt
Abbreviation of common parameters | Full name of parameter | describe |
---|
-a | --all | List of all file systems |
-h | --human-readable | Easy to read display |
-i | --inodes | Display inode information |
-T | --print-type | file system type |
-T < file system type > | --type | Displays only disk information for the selected file system |
-X < file system type > | --exclude-type | Do not display disk information for the selected file system |
# Display disk usage
$ df
# Display disk usage in inode mode
$ df -i
# Lists the types of file systems
$ df -T
# Displays disks of the specified type
$ df -t ext4
Abbreviation of common parameters | Full name of parameter | describe |
---|
-a | --all | Displays the size of all files in the directory. |
-b | --bytes | Displays the size of the directory or file in byte s. |
-c | --total | In addition to displaying the size of individual directories or files, it also displays the sum of all directories or files. |
-k | | Output in kilobytes (1024 bytes). |
-m | | Output in MB. |
-s | --summarize | Show only totals and list only the last summed value. |
-h | --human-readable | Take K, M and G as units to improve the readability of information. |
# Displays the space occupied by the specified file in a format that is easy to read
$ du -h error.log
# Displays the space occupied by the specified directory in a format that is easy to read
$ du -h /usr/bin
# Displays the disk space occupied by several files or directories, and counts the total
$ du -ch error.log info.log
# Display in reverse order of space size
$ du -h | sort -nr | head -10
# Measure the running time of ps command
$ time ps
# Save the execution result of the time command to a file
$ (time date) 2>2.txt