Syntax
>file write standard output to file
>>file append standard output to file
>&m write standard output to file descriptor m
<file read standard intput from file
<&m read standard input from file descriptor m
<<word read standard input from a "here document"
 
 
Any of the file redirection syntaxes can be prefixed with a file descriptor to specify a file to be used in place of the default file for that syntax.
command 2> file write standard error to file

#discard both standard output and standard error
command > /dev/null 2>&1
#wrong
command  2>&1    > /dev/null
 

Reading Files
while read LINE
do
command
done < file
 

Truncate a File
> file

: > file
cat /dev/null > file

Web Page Copyright: 亞洲大學資訊電機學院 連耀南 yaonanlien@asia.edu.tw  redirect2.htm,  Thu Sep 7 16:18:53 CST 2023