Chapter 4 Creating, Viewing, and Editing Text Files
Run a command, but throw away all possible terminal displays
&>/dev/null
Send output and errors to the same new, empty file
&>file
Display command output to terminal, ignore all errors
2>/dev/null
Run command, save output in a file, discard error messages
> file 2> /dev/null
Send output and errors to the same file, but preserve existing file content
>>file 2>&1
Send command output to file; errors to different file
>file 2>file2
Standard Input ( stdin)
reads input from the keyboard
Send command output to both the screen and a file at the same time
| tee file
Standard Error can be redirected through a pipe, but the merging redirection operators (&> and &>>) can not be used to do this
True
Pipelines & I/O Redirection
both manipulate standard output and standard input. Redirection sends standard output to or gets standard input FROM FILES. Pipes send standard output to or get standard input from another PROCESS
2>/dev/null
discard stderr error messages by redirecting to /dev/null
tee command
in a pipeline , tee will copy its standard input to its standard output and will also redirect its standard output to the files named as arguments to the command.
2>file
redirect stderr to overwrite a file
&>>file
redirect stdout and stderr to append the same file
>>file 2>&1
redirect stdout and stderr to append the same file
&>file
redirect stdout and stderr to overwrite the same file
>file 2>&1
redirect stdout and stderr to overwrite the same file
>>file
redirect stdout to append to a file
>file
redirect stdout to overwrite a file
I/O redirection
replaces the default channel destinations with file names representing either output files or devices
Standard Error ( stderr)
sends error messages to the terminal
Standard Output ( stdout)
sends normal output to the terminal
Pipeline
sequence of one or more commands separated by |, the pipe character. A pipe connects the standard output of the first command to the standard input of the next command.