A, IO redirection
1, data entry: keyboard --- standard input, but is not the only way to enter
echo " 123456 " | passwd -stdin # username and password while adding users the while Line; do loop $ Line ... DONE </ etc / passwd
2, the data output: --- standard output display, but not the only output
ls /etc/ > a.txt
3, fd file identifier: 0-9, the file identifier is defined to have a document classification acts as 0,1,2
0 represents the standard output
1 represents the standard input
2 represents a standard error (standard error)
4, common redirection symbols:
a) Standard Output:
>: Redirect coverage (very risky)
Close cover This command causes the redirection set -C not cover enabled set + C
> |: Forced redirection
>>: append redirection
b) Standard Input:
<Input
<< The multiple rows of data simultaneously input
cat >> a.txt <<EOF
tr: replace the contents of the file
# The passwd file are replaced with the abc ABC, the output to passwd.bak, abc single character is replaced by one matching
tr abc ABC < /etc/passwd > /etc/passwd.bak
c) error output:
2>: no output, but only to the output state, the output is redirected to the content of / dev / null
2>> : ls 12345 2>> a.txt
d) mixed output, regardless correct errors output redirection
&>
&>>
ls /etc/ &> /dev/null
Second, the pipeline break
The results of the implementation of the previous command to a command execution
[Linux Thought: The Combination achieve great little feature function]
free -m | grep “^Men” | cut -d” “ -f19 free -m | grep "^Mem" | awk '{print $3}'
Command: tee one input, two outputs (screen printing once, save the file once)
If no file is created, by default, overwrites the file if there is content
Exercise:
The front row of content 5 / etc / passwd file and converts the file saved to /tmp/passwd.out uppercase;
head -5 /etc/passwd | tr [a-z] [A-Z] > /tmp/passwd.out
Log on to the system after the current user information aggregated information into three /tmp/who.out saved to a file after uppercase;
who | tail -3 | cut -d' ' -f1 | tr [[:lower:]] [[:upper:]] | tee /tmp/who.out
Third, the text processing tools
1, wc (word count) text statistics
Usage: wc textfile view the number of lines, number of characters, file size, file name
parameter:
-l: number of lines
-w: Number of characters
-c: File Size
2, cut file segmentation
-d specified delimiter
-f specify which column to extract
- -output-delimiter = 'xxx' output from the separator, you want to use to replace delimiter
cut limitations
A plurality of separators can not be specified at the same time
You can not do high-level formatted output
3, sort ordering, sorting according to ASCII
parameter:
-r reverse order
-n numerical size of the sort
-f Ignore character case
-t specify the delimiter
-k Specify the first few paragraphs sort
-u sort to repeat
4, uniq deduplication
And the same was seen as a continuous repetition
It is recommended to sort the duplicates removed
parameter:
-c count the number of times certain characters appear
-d display only duplicate rows