0
Command to find the largest directory in the current directory
du -a | sort -n -r | head -n 5
2>&1, like inls foo > /dev/null 2>&1.cat a file, its output will be printed in the screen, by default:$ cat foo.txt
foo
bar
baz
output.txt:$ cat foo.txt > output.txt
$ cat output.txt
foo
bar
baz
cat we don’t see any output in the screen. We changed the standard output (stdout) location to a file, so it doesn’t use the screen anymore.stderr), to where programs can send their error messages. So if we try to cat a file that doesn’t exist, like this:$ cat nop.txt > output.txt
cat: nop.txt: No such file or directory
stdout to a file, we still see the error output in the screen, because we are redirecting just the standard output, not the standard error.stdout) and Standard Error (stderr).1 for stdout and 2 for stderr.cat foo.txtto output.txt, we could rewrite the command like this:$ cat foo.txt 1> output.txt
1 is just the file descriptor for stdout. The syntax for redirecting is [FILE_DESCRIPTOR]>, leaving the file descriptor out is just a shortcut to 1>.stderr, it should be just a matter of adding the right file descriptor in place:# Using stderr file descriptor (2) to redirect the errors to a file
$ cat nop.txt 2> error.txt
$ cat error.txt
cat: nop.txt: No such file or directory
2>&1 idiom is doing, but let’s make it official.&1 to reference the value of the file descriptor 1 (stdout). So when you use 2>&1 you are basically saying “Redirect the stderr to the same place we are redirecting the stdout”. And that’s why we can do something like this to redirect both stdout and stderr to the same place:$ cat foo.txt > output.txt 2>&1
$ cat output.txt
foo
bar
baz
$ cat nop.txt > output.txt 2>&1
$ cat output.txt
cat: nop.txt: No such file or directory
stdout) and Standard Error (stderr);stdout (1) and stderr (2);command > output is just a shortcut for command 1> output;&[FILE_DESCRIPTOR] to reference a file descriptor value;2>&1 will redirect stderr to whatever value is set to stdout (and 1>&2 will do the opposite).

