This is an old revision of the document!
Table of Contents
BASH - Redirection
Output Redirection
The '>' symbol is used for output (STDOUT) redirection.
ls -al > listings
Here the output of command ls -al is re-directed to file “listings” instead of your screen.
NOTE: Use the correct file name while redirecting command output to a file.
If there is an existing file with the same name, the redirected command will delete the contents of that file and then it may be overwritten.
If you do not want a file to be overwritten but want to add more content to an existing file, then you should use '»' operator.
Redirect standard output to devices
You can redirect standard output, to not just files, but also devices!
cat music.mp3 > /dev/audio
The cat command reads the file music.mp3 and sends the output to /dev/audio which is the audio device.
If the sound configurations in your PC are correct, this command will play the file music.mp3.
Input redirection
The '<' symbol is used for input(STDIN) redirection.
Mail -s "Subject" to-address < Filename
This would attach the file with the email, and it would be sent to the recipient.