terminal.cab
No.
26
Date
Learning goal
Terminal Start, lesson 11
Level
3 of 3

Command of the day No. 26: 2>&1 and /dev/null

Purpose: Moves error messages elsewhere or makes them vanish.

Syntax: command 2>/dev/null, command 2>&1

Example:

ls todo.txt missing.txt
ls: cannot access 'missing.txt': No such file or directory
todo.txt
ls todo.txt missing.txt 2>/dev/null
todo.txt
ls missing.txt 2>&1 | wc -l
1

Output from the simulator, as on a real Linux.

Options:

Try it in the terminal Share image

Fills in the command. Nothing runs until you press Enter.

Command of the day No. 26: 2>&1 and /dev/null. Purpose: Moves error messages elsewhere or makes them vanish. Example: ls todo.txt missing.txt; ls todo.txt missing.txt 2>/dev/null; ls missing.txt 2>&1 | wc -l. Remember: 1 is the output, 2 the errors; &1 means channel 1, not a file.
The same card as an image, 1080 x 1350 pixels.

Today's card ยท All cards so far