About this exam
One of the two exams that make up LPIC-1 from the Linux Professional Institute (LPI); passing 101 and 102 within five years of each other earns LPIC-1. It covers system architecture, Linux installation and package management, GNU and Unix commands, and devices and Linux filesystems.
Try a sample question
This is an original sample question written by itmoshi based on the exam objectives.
A nightly batch job runs ./backup.sh. You want both standard output and standard error saved in the same file, out.log, with nothing shown on the screen; overwriting the file on each run is fine. Which command meets these requirements?
- A./backup.sh 2>&1 > out.log
- B./backup.sh > out.log 2>&1
- C./backup.sh | tee out.log
- D./backup.sh > out.log 2>/dev/null
Show answer and explanation
Answer:B Use ./backup.sh > out.log 2>&1.
Why it is correct
Redirections are processed left to right. First, > out.log points standard output (1) at out.log; then 2>&1 points standard error (2) at wherever standard output currently goes, which is out.log. Both streams end up in the same file and nothing reaches the screen. Because it uses >, the file is overwritten each time.
The other options
- ✗ A The order is reversed. When 2>&1 is processed, standard output still points to its original destination (the screen, if run from a terminal), so standard error stays there; only standard output is then switched to out.log. This form is handy when you want errors to stay on the original output.
- ✗ C A pipe carries only standard output, so errors go to stderr's original destination instead of the file, and tee writes what it receives to its own standard output as well as the file. Use it when you want to watch the output while logging it.
- ✗ D Standard error is discarded to /dev/null, so errors are not kept in the file. Use this when errors can be ignored and only normal output should be saved.
Key takeaway
Redirections apply left to right. > file 2>&1 → both into the file. 2>&1 > file → errors stay on stdout's original destination. Pipe → only stdout is passed (use 2>&1 | or |& to pass errors too).
Try 20 questions like this for free
Most frequent topics
- Booting the system11 questions
- Using streams, pipes, and redirects9 questions
- Working on the command line8 questions
- Performing basic file management8 questions
- Using Debian package management6 questions
- Managing file permissions and ownership6 questions
Number of questions per topic among the 107 in this bank (top topics), as classified by itmoshi.
Exam domains
- System Architecture18 questions
- Linux Installation and Package Management21 questions
- GNU and Unix Commands48 questions
- Devices, Linux Filesystems, and the Filesystem Hierarchy Standard20 questions
← All exams
itmoshi is an unofficial study service and is not affiliated with Lpi or any exam provider.