Sunday, August 17, 2025

file redirection

In Linux, redirecting input and output of command uses  ">" or "<" characters.  For example, 

cat file1 file2 file3 1> outfile 2>&1

redirects the output of cat command to a file called outfile and error message also go to the same outfile.  The numbers 1, 2 etc are actually file descriptors.

Shorthand for 2>&1 is |&

Default file descriptor for ">" is 1 so 1 can be omitted

Default file descriptor for "<" is 0 (standard input)

No comments: