stderr
Redirect the output of stderr (descriptor 2) to /dev/null:
# save this file as testnull
# chmod 755 testnull
ls -garbage 2>/dev/null
# try ./testnull
Diagram below shows a demo
Notice that
1) redirecting to /dev/null from command line has no effect
2) redirecting error from shell script works !!
stdout
[raja@AGRAJA ~] ls 1>file_list.txt
[raja@AGRAJA ~] ls > same_file_list.txt
This is the default option during redirecting output.
i.e “1>” and “>” mean the same.
stdin
[raja@AGRAJA ~] ls 0>empty_file
[raja@AGRAJA ~] ls
The above prints to standard terminal.
Note that “empty_file” will be emptied.
Redirect everything to file
Redirect all console output texts (stdout, stderr, stdlog …) to file
For sh shell
at command line:
[raja@AGRAJA ~] make > & ! make.log
inside shell script:
illegal junk text as command > junk.spam 2>&1
[or]
illegal junk text as command > & ! junk.spam
For csh shell
Note: The below works on the command line, as well as inside a script
[raja@AGRAJA ~] make > & ! make.log
[raja@AGRAJA ~] ls > & ! files.lst
[raja@AGRAJA ~] illegal junk text as command > & ! junk.spam