ACSP Command-Line Interface 4 — Questions and Answers
Question 1: Which command displays the current user's username in macOS Terminal?
- whoami (Correct answer)
- id -n
- echo $HOME
- users
Correct answer: whoami
The `whoami` command prints the effective username of the currently logged-in user.
Question 2: A technician wants to view only the last 20 lines of a large log file. Which command achieves this?
- tail -n 20 logfile.log (Correct answer)
- head -20 logfile.log
- cat -20 logfile.log
- less +20 logfile.log
Correct answer: tail -n 20 logfile.log
`tail -n 20` outputs the last 20 lines of the specified file.
Question 3: Which command would you use to change the ownership of a file to a different user in macOS?
- chown newuser filename (Correct answer)
- chmod u+newuser filename
- chgrp newuser filename
- usermod filename newuser
Correct answer: chown newuser filename
`chown` (change owner) sets the user and/or group ownership of a file.
Question 4: What does the `&&` operator do when used between two shell commands?
- Runs the second command only if the first succeeds (Correct answer)
- Runs both commands simultaneously
- Runs the second command regardless of the first
- Pipes output from the first to the second
Correct answer: Runs the second command only if the first succeeds
`&&` is a logical AND; the second command executes only when the first exits with status 0 (success).
Question 5: Which `find` command locates all `.log` files modified within the last 7 days under `/var/log`?
- find /var/log -name '*.log' -mtime -7 (Correct answer)
- find /var/log -name '*.log' -atime 7
- locate /var/log -type f -mtime 7
- search /var/log -modified -7 -name '*.log'
Correct answer: find /var/log -name '*.log' -mtime -7
`find` with `-mtime -7` matches files modified less than 7 days ago.
Question 6: A user runs `sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder`. What is the purpose of this command sequence?
- Flush the DNS cache on macOS (Correct answer)
- Restart the directory services daemon
- Reset all network interfaces
- Clear the ARP table
Correct answer: Flush the DNS cache on macOS
This two-command sequence flushes the DNS cache and restarts mDNSResponder to apply the change on modern macOS.
Question 7: Which command can be used to compress a folder named `reports` into a gzip-compressed tar archive called `reports.tar.gz`?
- tar -czf reports.tar.gz reports (Correct answer)
- zip -r reports.tar.gz reports
- gzip -r reports reports.tar.gz
- compress -o reports.tar.gz reports
Correct answer: tar -czf reports.tar.gz reports
`tar -czf` creates (`c`) a gzip-compressed (`z`) archive file (`f`) from the specified directory.
Which command displays the current user's username in macOS Terminal?