paulgorman.org/technical

Unix Shell Redirection

Three built-in files/streams usable for redirection:

STDIN  (handle 0)
STDOUT (handle 1)
STDERR (handle 2)

Standard output redirection operators:

>  (right carrot)  (create/overwrite)
    $ ls . > file_list.txt
|  (pipe)
    $ cat file_list.txt | sort | less
>> (double carrot)  (append)
    $ ls ./foo/ >> file_list.txt

Standard input redirection operators:

<  (left carrot)
    $ sort < file_list.txt

Redirecting both input and output:

$ sort < file_list.txt > sorted_file_list.txt

< implicitly refers to STDIN, while > implicitly referes to STDOUT.

Redirect standard error into standard out:

$ make all 2>&1 | less

Redirect error to null:

$ make all 2>/dev/null | less

Redirect both STDOUT and STDERR to null:

$ rm -f $(find / -name core) &> /dev/null