ACSP Command-Line Interface 2 — Questions and Answers
Question 1: Which Terminal command displays the manual page for another command?
- man (Correct answer)
- help
- info
- whatis
Correct answer: man
'man' (manual) displays the detailed manual page for a given command, including syntax, options, and examples. For example, 'man ls' shows the full documentation for the ls command.
The 'man' command is the primary documentation system for Unix/Linux/macOS commands. Manual pages are organized into sections (1=user commands, 8=system admin commands, etc.). You navigate with arrow keys and spacebar, and exit with 'q'. For built-in shell commands that don't have man pages, use 'help [command]' in bash or '--help' flag. The 'whatis' command gives a one-line description, while 'apropos' searches manual page descriptions by keyword.
Question 2: What does the 'sudo' command do in macOS Terminal?
- Executes the following command with superuser (root) privileges (Correct answer)
- Switches the current user account to another user
- Displays a list of commands the current user is allowed to run
- Permanently elevates the current Terminal session to admin level
Correct answer: Executes the following command with superuser (root) privileges
'sudo' (superuser do) runs the immediately following command with root privileges after authenticating with the current user's admin password. The elevated privilege applies only to that single command.
sudo allows authorized users (those in the sudoers file or admin group) to run commands as root without switching to the root account. After entering the admin password, sudo caches the credential for about 5 minutes, so repeated sudo commands don't require re-entering the password immediately. 'sudo -i' or 'sudo -s' opens a root shell session. ACSP technicians use sudo for tasks like modifying system files, running diskutil operations, and managing system-level services.
Question 3: Which command would you use to change file permissions in macOS Terminal?
- chmod (Correct answer)
- chown
- chgrp
- ls -l
Correct answer: chmod
'chmod' (change mode) modifies the read, write, and execute permissions on files and directories. Permissions can be set using numeric (octal) notation like 755 or symbolic notation like u+x.
chmod uses either symbolic (chmod u+x file, chmod go-w file) or numeric/octal notation (chmod 755 file, chmod 644 file). The octal digits represent owner/group/others permissions: 4=read, 2=write, 1=execute. Common permissions: 755 (rwxr-xr-x) for executables and directories, 644 (rw-r--r--) for regular files. 'chown' changes the owner, 'chgrp' changes the group. 'ls -l' shows existing permissions but doesn't change them.
Question 4: What is the function of the 'grep' command in macOS Terminal?
- Search text using patterns and display matching lines from files or input (Correct answer)
- Copy files matching a specific pattern to another directory
- Find files by name in the file system
- Display file contents with line numbers
Correct answer: Search text using patterns and display matching lines from files or input
'grep' (Global Regular Expression Print) searches through text files or piped input for lines matching a specified pattern, printing those matching lines to the terminal output.
grep is one of the most used Unix tools. Common options: -i (case-insensitive), -r (recursive through directories), -n (show line numbers), -v (invert match, show non-matching lines), -E (extended regex), -l (show only file names). Example: 'grep -r "error" /var/log/' searches all files in /var/log for the word 'error'. Combined with pipes: 'ps aux | grep Safari' filters process list for Safari. 'find' is used to locate files by name, while grep searches file contents.
Question 5: Which command displays the current user's username in macOS Terminal?
- whoami (Correct answer)
- id
- users
- who
Correct answer: whoami
'whoami' prints the username of the currently logged-in user running the Terminal session. It's a quick way to verify which account context a command will run under.
'whoami' outputs just the username (e.g., 'john'). The related command 'id' provides more detail including user ID (UID), group ID (GID), and all group memberships. 'who' shows all currently logged-in users with their terminal and login time. 'users' shows a simple list of logged-in usernames. When working with sudo, 'sudo whoami' will return 'root', confirming elevated privileges are working correctly.
Question 6: What does piping (|) do in macOS Terminal commands?
- Sends the standard output of one command as the standard input to the next command (Correct answer)
- Saves the output of a command to a file
- Runs two commands simultaneously in parallel
- Separates two independent commands to run sequentially
Correct answer: Sends the standard output of one command as the standard input to the next command
The pipe character (|) connects commands in a chain, passing the standard output (stdout) of the command on the left as the standard input (stdin) of the command on the right, enabling powerful command combinations.
Pipes are fundamental to Unix philosophy of combining small tools. Example: 'ls -la | grep .plist | wc -l' lists all files, filters for .plist files, then counts them. 'ps aux | grep -v grep | grep Safari' finds Safari processes. The '>' operator redirects output to a file (overwrites), '>>' appends to a file, and '2>' redirects error output. ';' separates sequential commands, '&&' runs the second only if the first succeeds, '||' runs the second only if the first fails.
Which Terminal command displays the manual page for another command?