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:

  1. echo: to output text to the terminal Example: echo "Hello world"

  2. cat: to display the contents of a file Example: cat file.txt

  3. : to redirect standard output to a file (overwrites file if it exists) Example: ls > file.txt

  4. : to redirect standard output to a file (appends to file if it exists) Example: ls >> file.txt

  5. <: to redirect standard input from a file Example: sort < file.txt

  6. |: to redirect standard output from one command to standard input of another command Example: ls -l | less

  7. 2>: to redirect standard error to a file (overwrites file if it exists) Example: ls /etc/shadow 2> error.txt

  8. 2>>: to redirect standard error to a file (appends to file if it exists) Example: ls /etc/shadow 2>> error.txt

  9. &: 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

  10. &>>: 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

You should also read:

redirection

John Coltrane is the IT Director at Goldman Sachs. He is teaching a GNU/Linux class to a class full of new hires. He…