Three fifth lecture-Advanced document management
1. Input and output redirection
Ls-l/dev/stdin-/proc/self/fd/0
Standard input device: keyboard marker: 0
Ls-l/dev/stdout-/PROC/SELF/FD/1
Standard output device: Screen mark: 1
Ls-l/dev/stderr-/PROC/SELF/FD/2
Error output device: Screen mark: 2
LS/ETC/PASSWD/ETC/PASSWD1 1>1.log 2>2.log
Writes the correct output 1 to 1.log, writes the error output to 2.log
LS/ETC/PASSWD/ETC/PASSWD1 &>all.log
Write the correct output and error output together All.log
LS/ETC/PASSWD/ETC/PASSWD1 1>lei.log 2>&1
Write the correct output and error output together Lei.log
Ls/etc/passwd/etc/passwd1/dev/null 2>&1
System black Hole: does not occupy disk space
DD If=/dev/zero Of=aaa.log Bs=1 count=1m
0 transmitter, write 1M data to file
echo "AAA" > Aaa.log
Writing characters to a file
echo "BBB" >>aaa.log
Append character to File
Cat < Aaa.log
Use the contents of the file as input to the cat
| Pipe Refinement
Pass the standard output of the previous command to the next command for standard input
cat/etc/passwd | Head-n 3 | Cut-d:-F 1,3,7 |sort-rt:-K 2 |tr [A-z] [a-z]
--wildcard characters
*: matches any character of any length
? : matches any one character
[]: Any character that belongs to a character group
{}: String in curly braces and leading string and successor string as match criteria
>>: Append to the end of the specified file
: Output redirection
<: Input redirection
|: Pipe character, used to connect multiple commands, the output of the previous command as input to the latter command
|| : Logical OR
&&: Logic and
&: Executing in the background
2.wc:word Count
Function: Calculates the number of words, lines, and characters of a file, and displays the output of the statistical results
Parameter:-c counts bytes.
-L counts the number of rows.
-M counts the number of characters. This flag cannot be used with the-C flag.
-W count words. A word is defined as a string separated by a blank, a jump, or a newline character.
-L Prints the length of the longest line.
-HELP Display Help information
--version displaying version information
Syntax: WC filenm
7 8 Test.txt
Number of Rows Word count bytes file name
3.grep:http://www.cnblogs.com/peida/archive/2012/12/17/2821195.html
Function: A specific character used for filtering/searching. Can use regular expressions can be used with a variety of commands, the use of very flexible
Parameters:-A--text #不要忽略二进制的数据.
-C--count #计算符合样式的列数.
-I.--ignore-case #忽略字符大小写的差别.
-V--revert-match #显示不包含匹配文本的所有行.
-N--line-number #在显示符合样式的那一行之前, indicating the number of columns in the row.
Rule expression: ^ #锚定行的开始 such as: ' ^grep ' matches all lines that begin with grep.
$ #锚定行的结束 such as: ' grep$ ' matches all lines that end with grep.
. #匹配一个非换行符的字符 such as: ' GR.P ' matches gr followed by an arbitrary character followed by P.
* #匹配零个或多个先前字符 such as: ' *grep ' matches all one or more spaces followed by the line of grep.
. * #一起用代表任意字符.
[] #匹配一个指定范围内的字符, such as ' [Gg]rep ' matches grep and grep.
[^] #匹配一个不在指定范围内的字符, such as: ' [^a-fh-z]rep ' matches the beginning of a letter that does not contain a-r and t-z, immediately following the line of the Rep.
\(.. \) #标记匹配字符, such as ' \ (love\) ', Love is marked as 1.
\< #锚定单词的开始, such as: ' \<grep ' matches lines that contain words that begin with grep.
\> #锚定单词的结束, such as ' grep\> ', matches lines that contain words ending with grep.
X\{m\} #重复字符x, M times, such as: ' 0\{5\} ' matches rows containing 5 O.
X\{m,\} #重复字符x, at least m times, such as: ' O\{5,\} ' matches rows with at least 5 O.
X\{m,n\} #重复字符x, at least m times, not more than n times, such as: ' O\{5,10\} ' matches rows of 5--10 O.
\w #匹配文字和数字字符, that is, [a-za-z0-9], such as: ' G\w*p ' is matched with a G followed by 0 or more literal or numeric characters, followed by P.
\w #\w The reverse form, matching one or more non-word characters, such as the dot period, and so on.
\b #单词锁定符, such as: ' \bgrep\b ' only matches grep.
Syntax: grep ' ^string ' file
grep ' string$ ' file
Grep-c ' string ' file
4. TR
Function: Character conversions in standard input by substitution or deletion operations
Syntax: tr-c-d-s ["String1_to_translate_from"] ["string2_to_translate_to"] < Input-file
Parameter:-C replaces this character set with the complement of the character set in string 1, which requires the character set to be ASCII.
-d deletes all input characters in string 1.
-S Delete all occurrences of a sequence of characters, leaving only the first one; the string compression is about to recur to a string.
Input-file is the conversion file name. Although you can enter in other formats, this format is most commonly used.
Character Range: When specifying the contents of string 1 or String 2, only single character or string range or list can be used.
A string that consists of characters in A-Z (A-Z).
[A-z] A string consisting of characters within a-Z.
[0-9] number string.
\octal a three-bit octal number that corresponds to a valid ASCII character.
[O*n] indicates that the character O repeats the specified number of times N. therefore [o*2] matches the OO string.
Different expressions of specific control characters in TR
Shorthand notation meaning octal method
\a ctrl-g Ringtones \007
\b Ctrl-h backspace \010
\f Ctrl-l Walk the line to change page \014
\ ctrl-j New Line \012
\ r Ctrl-m Enter \015
\ t ctrl-i Tab key \011
\v Ctrl-x \030
Syntax: Cat file | TR "ABC" "XYZ" > New_file
Replace ABC in the file with XYZ
Cat File | tr-d "Snail" > New_file
All occurrences of ' S ', ' n ', ' a ', ' I ', ' l ' characters will be removed from the file. Instead of tightly deleting the "Snail" string that appears
Cat File | tr-d "\n\t" > New_file
Remove the newline ' \ n ', tab ' \ t ' characters that appear in file files
Cat File | tr-d "\n\t" > New_file
Remove the newline ' \ n ', tab ' \ t ' characters that appear in file files
Cat File | tr-s [a-za-z] > New_file
Delete "consecutive" repeating letters, leaving only the first one
Cat File | Tr-s "\ n" > New_file
Delete empty lines
5.sort
Function: Sort the contents of a text file, sort it against the contents of a text file, in a unit of behavior
Parameter:-B ignores the space character that begins before each line.
-C checks whether the files are sorted in order.
-D sorts, ignoring other characters, outside of the English alphabet, numbers, and space characters.
-f Sort, lowercase letters are considered uppercase.
When-I sorts, other characters are ignored except for ASCII characters between 040 and 176.
-K selects which interval to sort.
-M merges several sorted files.
-M sorts the first 3 letters according to the abbreviation of the month.
-N Sorts by the size of the numbers.
-o< the output file > The sorted result into the specified file.
-R is sorted in reverse order.
-t< Delimited character > specifies the field separator character to use when sorting.
-U Remove Duplicate rows
+< start >-< End fields > Sort by a specified field, ranging from the Start field to the previous column in the End field.
Syntax: sort-n-t ' ch '-K num file
Paragraph num of ch characters sorted by value
6.cut
Role: Extract Files by column
Parameter:-D indicates the column delimiter-F Select the output region-C to specify the character position
-B: Split in bytes. These byte locations will ignore multibyte character boundaries unless the-n flag is also specified.
-C: Split in characters.
-D: Custom delimiter, default is tab.
-F: Used with-D to specify which area to display.
-N: Cancels splitting multibyte characters. Used only with the-B flag. If the last byte of the character falls within the range of <br/> indicated by the List parameter of the-B flag, the character will be written out;
Syntax: Cut-b 8,3-5
3-5,8:cut command If the-B option is used, then when the command is executed, the cut will sort all the positions after-B and then extract them from small to large. Can not reverse the order of the positioning OH
Cut-b-3
-3 means from the first byte to the third byte
Cut-b 3-
3-Represents the third byte to the end of the line
Cut-b -3,3-
Outputs an entire line without two consecutive overlapping
Cut-c
-C will be in characters, output is normal, and-B will only be silly in bytes (8-bit bits) to calculate, the output is garbled. When multi-byte characters are encountered, the-n option can be used to tell the cut not to disassemble multibyte characters
Cut-d:-F 1,3-5
Extract by: The first column of the split, the third column to the fifth column
Sed-n L File
Whether a space consists of a number of spaces or a tab, the lowercase letter of the L after-n
Linux section Sixth essay