Linux+ CompTIA Linux+ Linux GNU and Unix Commands 3 — Questions and Answers
Question 1: Which command displays currently logged-in users along with what they are doing?
- w (Correct answer)
- who
- users
- id
Correct answer: w
The w command shows who is logged in and their current activity including load averages.
Question 2: A technician needs to compare two files line by line. Which command should be used?
- diff file1 file2 (Correct answer)
- cmp -l file1 file2
- comm file1 file2
- grep -c file1 file2
Correct answer: diff file1 file2
diff compares two files line by line and shows the differences with context markers.
Question 3: What does 'chown alice:developers report.txt' do?
- Sets owner to alice and group to developers (Correct answer)
- Sets owner to developers and group to alice
- Creates a user named alice in group developers
- Changes permissions for alice in the developers group
Correct answer: Sets owner to alice and group to developers
chown user:group sets the file's owner to alice and its group to developers.
Question 4: Which command creates a symbolic link named 'link.txt' pointing to 'original.txt'?
- ln -s original.txt link.txt (Correct answer)
- ln original.txt link.txt
- link -s original.txt link.txt
- mklink link.txt original.txt
Correct answer: ln -s original.txt link.txt
ln -s creates a symbolic (soft) link; without -s it creates a hard link.
Question 5: Which pipeline counts the number of lines in a file named 'data.txt'?
- cat data.txt | wc -l (Correct answer)
- cat data.txt | count -l
- cat data.txt | grep -c .
- cat data.txt | nl -l
Correct answer: cat data.txt | wc -l
wc -l counts lines; piping cat output through wc -l gives the total line count.
Question 6: What does the 'umask 022' setting mean for newly created files?
- Files are created with permissions 644 (Correct answer)
- Files are created with permissions 022
- Files are created with permissions 755
- Files are created with permissions 777
Correct answer: Files are created with permissions 644
umask 022 subtracts from 666 (default file perms), yielding 644 (rw-r--r--).
Question 7: Which command searches for the string 'ERROR' in all .log files recursively?
- grep -r 'ERROR' *.log
- grep -rE 'ERROR' --include='*.log' . (Correct answer)
- find . -name '*.log' | grep 'ERROR'
- grep 'ERROR' **/*.log
Correct answer: grep -rE 'ERROR' --include='*.log' .
grep -rE with --include='*.log' recursively searches only .log files for the pattern.
Which command displays currently logged-in users along with what they are doing?