- Processes are connected to three standard files
- Many programs open other files as well
Nguyen Hai Chau
Vietnam National University
stdin
stdin
stdout
stderr
|
stdin
and write to stdout
as normal$ echo Happy Birthday! | rev
!yadhtriB yppaH
<
symbol indicates the file to read input from:$ wc < thesis.txt
>
symbol indicates the file to write output to:$ who > users.txt
$ filter < input-file > output-file
>>
to append to a file:$ date >> log.txt
Name | File descriptor |
---|---|
Standard input | 0 |
Standard output | 1 |
Standard error | 2 |
stdin
and stdout
$ program 2> file
$ program > file 2>&1
$ program > `stdout`.txt 2> `stderr`.txt
xargs
xargs
reads pieces of text and runs another program with them as its arguments
xargs command [initial args]
-l
n to use n
items each time the command is run
xargs
is very often used with input piped from find
$ find /tmp/rubbish/ | xargs -l10 rm -f
tee
tee
program makes a 'T-junction' in a pipelinestdin
to stdout
, and also to a file>
and |
combined$ last | tee everyone.txt | grep bob > bob.txt
rev
to reverse some text.whoami
).rev
with cat
? You might like to try running cat
with no arguments
and entering some text.ls --color
in a directory with a few files and directories. Some Linux distributions
have ls
set up to always use the --color
option in normal circumstances, but in this case we will give
it explicitly.cat
or less
). You
should spot two differences in the output. ls detects whether its output is going straight to a terminal
(to be viewed by a human directly) or into a pipe (to be read by another program).