And redirection pipe character
1, the redirection
program instructions + data =
command variable
in the program, how to enter data? How output?
Data Output: keyboard - standard input? How output?
--stdin
echo "123456" | --stdin passwd "username '
for example: function add user useradd.sh user.txt text document 1000 user
./useradd.sh A
./useradd.sh b
...
./useradd. sh <user.txt
while line; do
loop Line $
DONE </ etc / the passwd
data output: Display - standard output, but not the only output
ls / etc /> a.txt
fd file identifier 0-9-- classification corresponds to the file;
is defined as 1 2 0
0 - Standard Output
1 - Standard Input
2 - O error (standard error)
common redirection symbols
1, standard output
> coverage redirection
set-C (closed cover redirection)
> | (forced redirection)
>> append redirection
does not cover
2, the standard input
<tr replace the contents of the file
TR setl [SET2] <file.txt
<< plurality line data simultaneously input
CAT >> << a.txt the EOF
>. 1
> 2
>. 3
> the EOF
. 3, the error output
2>2>>
Extended: no content output, only the output state;
LS / etc /> / dev / null 2> / dev / null
IF [-eq $ 0?]; The then
loop
fi
&> &>> == 2&>1
ls /etc/ $> /dec/null
2, pipeline -tee
command1 | command2 | command3 | ......
the results of the previous command to a command to execute;
[linux idea: combine functions to achieve large male security features]
free -m | grep "Mem" | cut -d '' -f19
free -m | grep "Mem" | awk '{print $ 3}'
tee one input, two outputs
tee /tmp/tee.out // If no file is created, the default file if there is content, will be covered;
tail end of the file to see how many lines (default 10 lines)
-n tail -n 5 / etc / passwd == -5 short tail / etc / passwd
-f file to view real-time updates
tail -f / var / log / the Message
head to see how many lines the file header (default ten lines)
# line -n # ago, shorthand - #
take 10 - 20 lines: head -20 / etc / the passwd | tail -10
. 3, text processing tools - wc, cut, sort, uniq
wc
the number of characters word count statistics in the text file
usage wc filename
line number of characters File Size (bytes) filename
the -l
-w
-c
cut
used for the partition file
-d specified delimiter (DELIMITER)
Data outputted from the column specified -f
--output-delimiter='xx'
[Cut of limitations: 1, -d to specify delimiters, you can not specify more than 2, we can not do high-level formatted output; so I need to master awk]
sort
order, a default view of characters (including alphanumeric and special characters and spaces), and ASCLL sort code (not the case)
-n sorted by size digital
-r reverse
-t -k specifies that specified in the separator, and a sort
-f ignore the case of characters
-u uniq to repeat
uniq
Continuous and the same commands are treated as repeated
recommendations, the first sort, after reprogramming