Chapter 5
CREATING, VIEWING, AND EDITING TEXT FILES
STDIN, STDOUT, STDERR
0
stdin
Standard input
Keyboard
read only
1
stdout
Standard output
Terminal
write only
2
stderr
Standard error
Terminal
write only
3+
filename
Other files
none
read and/or write
command > file
redirect and overwrite to file
command >> file
redirect and append to file
command 2> file
redirect stderr and overwrite file
command 2>/dev/null
redirect stderr to /dev/null
command > file 2>&1
1) redirect stdout and overwrite file, then 2) redirect stderr to stdout (same file) file contains both stdout and stderr
command &> file
same with above example
command >> file 2>&1
1) redirect stdout and append file, then 2) redirect stderr to stdout (same file) file contains both stdout and stderr
command &>> file
same with above example
command 2>&1 > file
1) redirect stderr to stdout (terminal), then 2) redirect stdout to file stderr prints to terminal, file only contains stdout
Redirectionu pipe ilə işlətdiyimiz vaxt, pipe-dan sonrakı komandaya stdin daxil olmur.
Bu kimi hallarçün tee
işlətmək lazımdır. tee özündən əvvəlki komandadan gələn stdout-u stdin kimi qəbul edir, və özündən sonrakı pipe-a stdout kimi ötürür.

ls > file | less # empty output
ls -l | tee file | less # writes to file, prints to output
# Merge commands should not be used with pipe commands:
find / -name passwd 2>&1 | less # normal
find -name / passwd &> | less. # syntax error
-bash: syntax error near unexpected token `|'
# adding /home/user/bin directory to PATH variable:
export PATH=${PATH}:/home/user/sbin
# to see currently set variables:
set
# to see all environment variables:
env
To set persistent variables look for these files:
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
Last updated
Was this helpful?