RHCSA RHCSA Linux Essentials 5 — Questions and Answers
Question 1: Which command searches for the string 'error' case-insensitively in all .log files under /var/log?
- find /var/log -name '*.log' | xargs grep 'error'
- grep -ri 'error' /var/log/*.log
- grep -ri 'error' /var/log/ (Correct answer)
- locate -i 'error' /var/log/
Correct answer: grep -ri 'error' /var/log/
`grep -r` recurses through directories and `-i` makes the search case-insensitive, covering all .log files.
Question 2: What does the `tar -xzf archive.tar.gz -C /opt/` command do?
- Compresses /opt/ into archive.tar.gz
- Extracts archive.tar.gz into the /opt/ directory (Correct answer)
- Lists the contents of archive.tar.gz
- Creates archive.tar.gz from files in /opt/
Correct answer: Extracts archive.tar.gz into the /opt/ directory
The flags -x (extract), -z (gzip), -f (file) combined with -C specify the extraction destination directory.
Question 3: Which command sets a user account to expire on December 31, 2026?
- passwd --expiredate 2026-12-31 username
- usermod --expiredate 2026-12-31 username
- chage -E 2026-12-31 username
- Both B and C are correct (Correct answer)
Correct answer: Both B and C are correct
Both `usermod -e` and `chage -E` accept a YYYY-MM-DD date and set the account expiration date.
Question 4: A volume group `vg_data` has 10 GiB free. Which command creates a 4 GiB logical volume named `lv_logs`?
- lvcreate -L 4G -n lv_logs vg_data (Correct answer)
- lvcreate -s 4G -n lv_logs vg_data
- lvmake -L 4G vg_data/lv_logs
- vgcreate -L 4G lv_logs vg_data
Correct answer: lvcreate -L 4G -n lv_logs vg_data
`lvcreate -L 4G -n lv_logs vg_data` creates a new 4 GiB logical volume named lv_logs in the specified volume group.
Question 5: Which configuration file defines the DNS search domain and nameservers for a RHEL system?
- /etc/hosts
- /etc/nsswitch.conf
- /etc/resolv.conf (Correct answer)
- /etc/sysconfig/network
Correct answer: /etc/resolv.conf
/etc/resolv.conf contains the `nameserver` and `search` directives used by the resolver library.
Question 6: What is the correct way to redirect both stdout and stderr to a file named output.txt?
- command > output.txt 2> output.txt
- command &> output.txt (Correct answer)
- command > output.txt | 2> output.txt
- command 1> output.txt 2> output.txt
Correct answer: command &> output.txt
`&>` is bash shorthand that redirects both file descriptor 1 (stdout) and 2 (stderr) to the same file.
Question 7: Which command would display the last 50 lines of the journal for the sshd service?
- journalctl -u sshd -n 50 (Correct answer)
- journalctl --service=sshd --lines=50
- systemctl log sshd -n 50
- tail -50 /var/log/sshd.log
Correct answer: journalctl -u sshd -n 50
`journalctl -u sshd -n 50` filters journal entries for the sshd unit and limits output to the last 50 lines.
Which command searches for the string 'error' case-insensitively in all .log files under /var/log?