shell commonly used basic commands

A, diff

Use the diff command:
Here Insert Picture Descriptionvimdiff command
Here Insert Picture Descriptioncontents of the file are as follows wang
Here Insert Picture Descriptioncontents of the file are as follows wang1
Here Insert Picture Descriptioncontrast with two diff command file
Here Insert Picture Descriptioncontent changes in the file wang
Here Insert Picture Descriptionagain compare two files
Here Insert Picture Descriptionresults therefore use the diff command comparison of the two files displayed meaning contains different characters in the following table

character meaning
The results in the first number numb1 The number of lines of the first file
a Add to
d delete
c change
< The first file
> The second file
After a, d, c contact numbers numb2 The number of rows of the second file

diff parameters commonly used
when two files shown below, there are two spaces in Document 2, consistent with the rest
Here Insert Picture Description-b: space indicates not detected
Here Insert Picture Descriptionparameters -c: show all the contents of the file and identify the different
Here Insert Picture Descriptionparameters -i: Ignore sensitive detection
Here Insert Picture Descriptionparameters -r: detecting a directory
Here Insert Picture Descriptionparameters -u: combined output
Here Insert Picture Description

Two, patch

Usage: patch the original file patch file
patch and diff -u in combination with
Here Insert Picture Descriptionpatch
Here Insert Picture Descriptioncommon parameters -b: Backup the original file
Here Insert Picture Description

Three, cut

typically cut command to intercept the data
common parameters are as follows:

parameter meaning
-d Specify the delimiter
-f Specifies the lie displayed
-c The interception of a specified character

Specifies that the column then use numbers or characters

Digital format meaning
3 Selected in the third column
3,5 Selected third and fifth columns
3-5 Selected third column to the fifth column
-3 From the beginning to the third column
3- The third column from the beginning to the end

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

Four, sort

Requirements can achieve the sort of
common parameters are as follows:

parameter meaning
-n Sort pure digital
-r Reverse order
-u Remove duplicate
-The Output to the specified file
-t Specify the delimiter
-k Specify the sort sequence

Write the following numbers in a file
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Descriptionsort order and combination uniq
Here Insert Picture DescriptionHere Insert Picture Descriptionuniq command parameters used in the following table

parameter meaning
-c The combined number of repeat and statistics
-d Display duplicate rows
-u Show only line

Five, tr

tr command is mainly used to change the character of the case
Here Insert Picture Description

Six, test

In the script, [] the equivalent of the test command
Here Insert Picture Description

Comparative figures in the 6.1 test
parameter meaning
= equal
!= not equal to
-eq equal
-born not equal to
-the Less than or equal
-lt Less than
-give greater or equal to
-gt more than the

Here Insert Picture Description

6.2 test conditions in relation
parameter meaning
-a and
-The or

Here Insert Picture Description

6.3 test for an empty judgment in
parameter meaning
-n Detection is not empty
-from Detection is empty

Here Insert Picture Description

6.4 test for determination of file
parameter meaning
-if If the file node number is consistent, one file to another file hard link
-nt File 1 File 2 is not better than new
-ot File 1 File 2 is not better than the old
-d table of Contents
-S Sockets
-L Soft links
-e Detect the presence
-f Trivial File
-b Block device
-c Character device

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

Published 28 original articles · won praise 0 · Views 756

Guess you like

Origin blog.csdn.net/weixin_43834060/article/details/105098552