1.find find the desired file or directory
Format: find [path] [-OPTION] [-exec | grep | xargs -ok -print | ......] [command {} \;]
parameter:
-type lookup to type
f file
d directory
Find -name file name
-size to find the ask price according to size. eg: find / data -size 5M
Find -perm based on the file permissions. eg: find / data -perm 755
-maxdepth maximum number of layers n displayed. (This parameter is usually placed first, otherwise there will be a warning). eg: find / data / -maxdepth 2 -type d
-exec command {} \; match command file for execution of the given parameter. Form command {} \;
-ok with -exec same effect. The difference is that, before executing the command prompt will allow users to confirm whether to execute.
-mtime -n / + n according to find the corresponding file modification time. -n means within n days; n + n refers days ago. In front of the number of days must have a plus or minus sign, otherwise there will be no search results.
eg:find -type f -name "*.log" -mtime +7|xargs ls -l 或 ls -l $(find -type f -name "*.log" -mtime 7) 或 find -type f -name "*.log" -mtime 7 -exec ls -l {} \;
! Negate. Note: at least one space before and after the symbol. eg: find / data -maxdepth 2 -type d -name! "."
find no arguments ----- displays all files in the current directory (including subdirectories and files in subdirectories)
2.grep filter. Find what you want in the file
Format: grep parameters used to find the key characters in the file name
parameter:
-v excluded. eg: grep -v "num" test.txt test.txt within the file, num contains non-character line displayed
-An character line where the match to show up and show times below the row n rows. eg: grep A15 "num" test.txt test.txt within the text, characters matched num line display, and displays the line below the line 15
-n display line to match the content of the character is located, and the line number.
-o grep execution of the display, i.e., each of the matched contents. Involves regular, then, is a regular each match to the content.
egrep supports advanced regular. Equivalent to grep -E
3.sed take the line. Used for replacement. The default displays the entire contents of the file. Can also be used to find content (that use less)
Format: sed parameters matching rows / replace / find characters filenames
parameter:
-n cancel the default output. That the abolition of the default display the entire contents, generally with the use of p.
-r expressed support for extended regular.
-i modify the contents of the file
eg:
Row fetching: Sed -n '20, 30P 'test.txt line display content of 30 to 20 test.txt file row.
sed -n '20p' test.txt line 20 of the display content test.txt file.
sed -n '3, $ p' test.txt third display line to the last line.
Note: How many lines before or after how many rows to display, you can use head or tail command. Sed show with a specific row or range of rows. View line on the display can be completely buttoned.
Alternatively: Sed -i 'Why # S # whom Alternatively #g' test.txt eg: sed -i ' s # nm # DDD # g' test.txt test.txt the paper will replace all the DDD nm
NOTE: sg When replacing the middle three symbols can be anything, but the commonly used or # @, i.e. s @@@ g or s ### g
Find an alternative with multiple file contents:
find / data / -type f -name "* .sh" | xargs sed -i 's # abc # kpl # g' find / data folder of all the files in the ending .sh, replace abc in all files kpl.
sed -n '2s # abc # 123 # gp' abc 2 test.txt second line is replaced with 123, is displayed. If added, then -i Here, the contents of the entire file will be replaced by the result of the processing line, such as: sed -n '2s # abc # 123 # gp' test.txt -i, it will be in the second row all abc replace after 123, empty file, the contents of the second write line, shown below:
'=' Indicates the row number for each row plus
Replace a line specific content, you can not add parameters p, -i as long as you can, otherwise it will go wrong, it will be more than one row. Here still we need research study:
sed -i '2s # abc # 123 # g' test.txt so that no parameters p, will replace the normal line 123 is 2 abc.
. Sed -i '2s # abc # 123 # gp' test.txt such parameters are p, will be more in the line to replace, and consistent content Line Figure 2:
Find: Sed -n '/ abc / P' abc test.txt row containing a display of the paper.
Line sed '/ abc / d' test.txt will not contain abc characters in the document are displayed (plus here if -n, then it shows nothing). ----- generally based on the characters to find the line with grep, sed so inconvenient to use, but also with less.
4.awk take column. Take the line. Calculation.
Format: awk parameter takes the row / column take / find characters filenames
awk 'whom do {}' file eg: awk 'NR == 2 {print $ 3}' test.txt take the first three rows of the second content file test.txt
parameter:
-F specify the delimiter (not specified, the default space as a separator). eg: awk -F "," '{print $ 3}' test.txt comma as a delimiter, the display section 3
-F "[,]" specify multiple delimiters. eg: awk -F "[,]" '{print $ 3, $ 5}' test.txt comma or space as a separator, and a display of 3 5
-F "[,] +" specify multiple delimiters. Here the + sign in consecutive spaces or commas as separators.
$ N n-th column
$ 0 represents the contents of an entire row
NR indicates the line number
{print }
Take columns:
awk '{print $ 3]' test.txt Showing page 3
awk '{print $ 2, $ 6}' test.txt Showing page 2, column 6
awk '{print $ 2 ", aa" $ 4}' tets.txt Showing page 2, column 4. Braces, double quotes will output the contents intact.
Togyo:
awk 'NR == 20, NR == 30' test.txt display line 20, line 30 to
awk 'NR == 20' test.txt shown in line 20
Find:
awk '/ 123 /' test.txt comprising 123 display lines of characters in the document
awk '! / 123 /' test.txt display line 123 does not contain the characters in the document