010-160 Command Line Navigation 5 — Questions and Answers
Question 1: Which command would create a new directory called 'projects' in the current location?
- touch projects
- mkdir projects (Correct answer)
- newdir projects
- create projects
Correct answer: mkdir projects
`mkdir` (make directory) creates a new directory with the specified name in the current or given path.
Question 2: What does the `echo $PATH` command show?
- The current working directory
- A colon-separated list of directories searched for executables (Correct answer)
- The path to the user's home directory
- The system's default text editor
Correct answer: A colon-separated list of directories searched for executables
$PATH is an environment variable containing a colon-delimited list of directories where the shell looks for executable commands.
Question 3: Which `find` command option specifies the type of object to search for (file or directory)?
- -name
- -type (Correct answer)
- -size
- -perm
Correct answer: -type
`find -type f` finds regular files and `find -type d` finds directories, filtering results by object type.
Question 4: What is a relative path?
- A path that always starts with a forward slash
- A path described in relation to the current working directory (Correct answer)
- A path that uses the ~ shortcut
- A path stored in an environment variable
Correct answer: A path described in relation to the current working directory
A relative path does not start with `/` and is interpreted relative to the current working directory (e.g., `docs/report.txt`).
Question 5: Which command searches for the string 'error' inside a file named 'syslog.txt'?
- find 'error' syslog.txt
- search error syslog.txt
- grep error syslog.txt (Correct answer)
- locate error syslog.txt
Correct answer: grep error syslog.txt
`grep <pattern> <file>` searches through file contents and prints lines that match the given pattern.
Question 6: How do you run a shell script named 'setup.sh' located in the current directory?
- run setup.sh
- setup.sh
- ./setup.sh (Correct answer)
- /setup.sh
Correct answer: ./setup.sh
`./setup.sh` explicitly tells the shell to run the script from the current directory, since `.` is not typically in $PATH.
Question 7: What does the `clear` command do in the terminal?
- Deletes all files in the current directory
- Clears the terminal screen display (Correct answer)
- Removes all environment variables
- Empties the command history
Correct answer: Clears the terminal screen display
`clear` scrolls the terminal output up and redraws an empty screen, giving you a clean working view.
Which command would create a new directory called 'projects' in the current location?