Article Directory
1. diff compare text files
Command format:diff [options] files或directorys
1.1 Interpretation of diff output information
输出信息 [num1,num2][a|c|d][num3,num4]
num1,num2 第一个文件中的行
a 添加
c 更改
d 删除
< 第一个文件中的内容
> 第二个文件中的内容
num3,num4 第二个文件中的行
1.2 Detailed explanation of diff parameters
|
|
---|---|
|
Ignore spaces |
|
Ignore blank lines |
|
Ignore case |
|
Show all the contents of the file and mark the difference |
|
Comparison catalog |
|
Merge output |
|
Only show whether there is a difference, do not show detailed information |
1.3 Examples of diff command usage
- Compare files
- Compare files, ignoring spaces -b
- Compare files, ignore blank lines -B
- Compare files, ignore case -i
- Show all the contents of the file and mark the difference
2. patch
Install the patch:dnf install patch -y
Command format:patch 原文件 补丁文件
|
|
---|---|
|
Backup original file |
patch patch example
1. Combine and output files with different contents and import them into a .path file
2. Install the patch program, patch the original file
3. Cut displays the specified content of the file
3.1 cut parameters
|
|
---|---|
|
Specify the separator (the default field separator is "TAB") |
|
Specify the displayed columns |
|
Specify the character to be intercepted |
#-f -c用法相同
5==第5列
3,5==第3和5列
3-5==3到5列
5-==第5列到最后
-5==开始到第5列)
3.2 Examples of cut usage
Experimental material
head /etc/passwd > /mnt/passwd
1. Display the specified column
2. Display the specified characters
3. Filter users who cannot log in, and display user names
grep bash -v /etc/passwd | cut -d : -f 1
4. sort
Sort takes each line of the file/text as a unit and compares each other. The comparison principle is to compare the ASCII code values from the first character to the back, and finally output them in ascending order.
4.1 sort parameter
|
|
---|---|
|
Pure numeric sort |
|
Reverse order |
|
Remove duplication |
|
Output to specified file |
|
Designated segregated house |
|
Specify the sorting column |
4.2 sort example usage
Experimental material
Sorting example 1
Sorting example 2
5. uniq ignore duplicate lines
Used to report or ignore duplicate lines in the file, generally used in conjunction with the sort command
|
|
---|---|
|
Combine duplicates and count the number of duplicates |
|
Show duplicate rows |
|
Show only row |
Experimental material
Combine duplicates and count the number of duplicates
Show duplicate rows
Show only row
Show the number of the most repeated files
sort -n sortfile | uniq -c | sort -k 1 -n | cut -d " " -f 8 | tail -n 1
6. tr replace, compress and delete characters
The tr command can replace, compress, and delete characters from standard input. It can turn a group of characters into another group of characters, and is often used to write beautiful single-line commands, which is very powerful.
tr ‘a-z’ ‘A-Z’
: Lowercase to uppercase
tr ‘A-Z’ ‘a-z’
: Uppercase to lowercase
7. && 与 ||
&&
Eligible actions
||
Unqualified actions
8 test
The test command is a practical tool for testing conditional expressions in the shell environment
test
== [ ]
: [] Equivalent to test command
test \$a = \$b 相当于 ['\$a' = '\$b' ]
8.1 Test number comparison
|
Strings are equal |
|
Strings are not equal |
|
equal |
|
not equal to |
|
Less than or equal to |
|
Less than |
|
greater or equal to |
|
more than the |
8.2 Test condition relationship
|
and |
|
or |
8.3 Test to determine empty
|
Determine the content is not empty nozero |
|
The judgment content is empty zero |
8.4 test judgment on files
|
exist |
|
Whether the file node numbers are consistent |
|
Is file 1 newer than file 2 |
|
Is file 1 older than file 2 |
|
Is it a directory |
|
Socket |
|
Soft link |
|
Normal file |
|
Block device |
|
Character device |
Determine whether the file exists -e
Determine whether the file node numbers are consistent -ef
Determine the new and old files -nt and -ot
Whether it is a directory -d (same as judging whether it is another file type)