input-output redirection
Ptah is a Linux Sysadmin at Red Hat. He wants to master input-output direction before he teaches it to a class of LFCS-candidates in 2 months. What shuuld he practice? Please list all commands.
To master input-output redirection, Ptah should practice the following commands:
echo: to output text to the terminal Example:
echo "Hello world"
cat: to display the contents of a file Example:
cat file.txt
: to redirect standard output to a file (overwrites file if it exists) Example:
ls > file.txt
: to redirect standard output to a file (appends to file if it exists) Example:
ls >> file.txt
<: to redirect standard input from a file Example:
sort < file.txt
|: to redirect standard output from one command to standard input of another command Example:
ls -l | less
2>: to redirect standard error to a file (overwrites file if it exists) Example:
ls /etc/shadow 2> error.txt
2>>: to redirect standard error to a file (appends to file if it exists) Example:
ls /etc/shadow 2>> error.txt
&: to redirect both standard output and standard error to the same file (overwrites file if it exists) Example:
ls /etc 1> output.txt 2>&1
&>>: to redirect both standard output and standard error to the same file (appends to file if it exists) Example:
ls /etc 1>> output.txt 2>&1