Redirect
Program = Instruction + Data
Command + variable
In the process, how the data input? How output
Keyboard Input: Keyboard - standard input, but is not the only way to enter
--stdin
useradd abc;passwd abc
echo "123456" | passwd --stdin "username" password
For example: add a user function txt text document 1000 users
./useradd.sh a
./useradd.sh b
...
./useradd.sh<user.txt
while line:do
Loop $ line
done</etc/passwd
Output data: Display - standard output, but the output is not the only way
ls /etc/>a.txt
fd file identifier 0-9-- equivalent to the document classification:
0 1 2 3
0-- standard output
1-- standard input
2-- O error (standard error)
Common redirection symbols
1, the standard output
> Cover redirection, very dangerous
set-C off cover redirection set + C open redirection
> | Forced redirection
>> append redirection
2, the standard input
<Tr replace the contents of a file
tr set1 [set2]<file.txt
<< cat will be multiple rows of data simultaneously input
cat>>a.txt<<EOF
>1
>2
>3
>EOF
3, error output
2> 2>>
Extended: no output content, only the output state
ls /etc/ >/dev/null
#echo$?#
if[$? -eq 0];then
Loop
be
&> &>> == 2&>1
ls /etc/ &> /dev/null
2, the pipe character -tee
After the results of the previous command to a command to execute;
[ LINUX idea: combine functions to achieve large small function]
free -m| grep "^Mem"|cut -d ' '-f19
free -m|grep"^Mem"|awk'{print $3}'
find [范围] -name ab* -type f -perm 600 -mtime +7|xarge
tee one input, two outputs
tee /tmp/tee.out
If no file is created, the default file if there is content, will be covered;
Exercise:
1, the front / etc / passwd file 5 after storage content into rows uppercase /tmp/passwd.out file;
head -5 /etc/passwd |tr[a-z][A-Z]>/tmp/passwd.out
2, after the log in to the system user aggregated information 3-bit information is saved to convert after Thanks /tmp/who.out file;
who |tail -3| cut -d' ' -f1 | tr [[:lower:]][[:upper:]]| tee /tmp/who.out
3, tail end of the file to see how many lines (default 10 lines)
-n tail -n 5 / etc / passwd == abbreviated tail -5 / etc / passwd
-f view real-time file updates
tail -f /var/log/message
head to see how many lines the file header (default ten lines)
-n # before #-line shorthand - #
Take line 10 --20 line: head -20 / etc / the passwd | tail -10