Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (31 sloc) 1.39 KB
layout title date type published status categories tags
post
Redirection in Linux
2014-07-17 22:34:46 +0500
post
true
publish
Bash
Linux

In Linux, everything is a file. Redirection comes in very handy because you can move data from a file to another file, from the resulting output of a command to a file. You can also redirect the output of one command and feed it as an input to another command.

Output >

The > symbol is used for redirecting output of one command to a new file or another command.

For example:

ls -al > listing.txt

or

echo 'hello, this is some info' > hello.txt

> writes the output. Meaning, if there is anything already in that file, or if there is an existing file with the same name, it'll be overwritten. To append the redirected output at the end of a file, use >>.

For example:

echo 'my name is Aamnah, add this at the end' >> hello.txt

Notes:

  • >& redirects the outputs of one file to another while < is the input redirection operator.
  • You can use error using its corresponding File Descriptor 2.
  • &> redirects stdout as well as stderr

Links