Detailed explanation of common file management commands in Linux

cat

catCommands are used to concatenate files and print to standard output.

Command syntax:cat [参数] [文件名]

Parameter Description:

parameter illustrate
-n Numbers all output lines starting from 1.
-b All output lines are numbered starting from 1, blank lines are not numbered.
-s When there are more than two consecutive blank lines, it is replaced with a blank line.
-E Display $ at the end of each line.
-T Display TAB characters as ^I

Example of use:

  1. Write one 万猫学社line for each word into the one.txt file, and then view the content of the file one.txt.
echo -e '万\n猫\n学\n社' > one.txt
cat one.txt

The effect is as follows:

  1. Add the file content of one.txt to the more.txt file after adding the line number, and then view the content of the file more.txt.
cat -n one.txt > more.txt
cat more.txt

The effect is as follows:

  1. Empty the contents of the one.txt file and view the contents of the one.txt file.
cat /dev/null > one.txt
cat one.txt

The effect is as follows:

You can see that the one.txt file has no content.

file

fileCommands are used to identify file types.

Command syntax:file [参数] [文件]

Parameter Description:

parameter illustrate
-b When listing identification results, file names are not displayed
-c Display the instruction execution process in detail, which is convenient for debugging or analyzing the execution of the program.
-L directly display the category of the file pointed to by the symlink
-v Display version information
-with Deciphering the contents of a compressed file

Example of use:

  1. Displays the onemore.txt file type.
echo '万猫学社' > onemore.txt
file onemore.txt

The effect is as follows:

  1. The file type of the Baidu logo is displayed and the file name is not displayed.
wget https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
file -b PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png

The effect is as follows:

find

findThe command is used to find files in the specified directory. Any string preceding the parameter will be treated as the directory name to look for. If you use this command without setting any parameters, the find command will search for subdirectories and files in the current directory. And all the found subdirectories and files will be displayed.

Command syntax:find [参数] [文件]

Parameter Description:

parameter illustrate
-mount Only check files in the same file system as the specified directory, avoid listing files in other file systems
-amin The file has been read in the past n minutes
-type file type Specify the file type to search, d: directory, c: font device file, b: block device file, p: named storage, f: general file, l: symbolic link, s: socket
-cmin n Modified in the last n minutes
-name name Find the file with the file name name
-size n  File size

Example of use:

  1. List all files with the suffix .txt in the current directory and its subdirectories.
touch one.txt more.txt
find . -name "*.txt"

The effect is as follows:

  1. List the common files in the current directory and its subdirectories three days ago.
find . -type f -mtime +3

The effect is as follows:

cmp

cmpThe command is used to compare two files for differences. This command does not display any information when comparing two files that are identical to each other. Otherwise, the character and column number of the first difference is marked. When no file name is specified, or the file name is "-", the cmp command will read data from the standard input device.

Command syntax:cmp [-clsv][-i <字符数目>][--help][第一个文件][第二个文件]

Parameter Description:

parameter illustrate
-c In addition to the decimal code indicating the difference, the corresponding character of the character is displayed together
-i <number of characters> specify a number
-l Mark all the differences
-s do not display error messages
-v Display version information
--help show help

Example of use:

Write one 万猫学社77line per word into one.txt file:

echo -e '万\n猫\n学\n社\n77' > one.txt

Write one 万猫学社88line per word into the more.txt file:

echo -e '万\n猫\n学\n社\n88' > more.txt

Compare if one.txt file and more.txt file are the same:

cmp one.txt more.txt

The effect is as follows:

You can see the difference between line 5 of the one.txt file and the more.txt file.

diff

diffcommand to compare files for differences. The diff command compares text files for similarities and differences line by line. If you specify that you want to compare directories, diff compares files with the same filename in the directory, but not subdirectories.

Command syntax:diff [参数] [文件或目录1] [文件或目录2]

Parameter Description:

parameter illustrate
-<number of lines> Specifies how many lines of text to display, this parameter must be used together with the -c or -u parameter
-c Show full text and highlight differences
-u Display differences in file content in a merged manner
-a will only compare text files line by line
-b Do not check for differences in whitespace characters
-d Use different algorithms to compare in smaller units
-i Do not check for differences in case
-and Display similarities and differences of documents in a side-by-side manner
-W<width> When using the -y parameter, specify the column width

Example of use:

Compare one.txt file and more.txt file, output in side-by-side format.

diff one.txt more.txt -y -W 10

The effect is as follows:

Finally, thank you for being so handsome, and for giving me likes and attention .

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324125232&siteId=291194637