Home

Search IconIcon to open search

Redirection in Bash

img

> redirects output read from a file descriptor to a file. Default descriptor is 1 (stdout), so >name means 1>name. Example:

1
ls -a > result.txt

< redirects input. So wc < file.txt means wc will treat data from file.txt as stdin.

2>& redirects file handle “2” (almost always stderr) to some other file handle (it’s generally written as 2>&1, which redirects stderr to the same place as stdout).

&> and >& redirect both stdout and stderr to a file. It’s normally written as &>file (or >&file). It’s functionally the same as >file 2>&1. (todo: so why do they have different syntax?)

&>file is equivalent to 1>file 2>&1.

# Notes

# See also

Terminal tips

More advanced: