010-160 Command Line Navigation 3 — Questions and Answers
Question 1: Which `ls` option shows hidden files (those starting with a dot)?
- -l
- -h
- -a (Correct answer)
- -r
Correct answer: -a
`ls -a` (all) lists all files including those whose names begin with a dot, which are hidden by default.
Question 2: What is the purpose of the `file` command in Linux?
- Creates a new empty file
- Determines the type of a file (Correct answer)
- Lists directory contents
- Copies a file to another location
Correct answer: Determines the type of a file
The `file` command examines a file's contents and reports its type (e.g., ASCII text, ELF binary, JPEG image).
Question 3: Which command lists directory contents in long format showing permissions, owner, and size?
- ls -a
- ls -l (Correct answer)
- ls -r
- ls -d
Correct answer: ls -l
`ls -l` displays a detailed long listing including permissions, link count, owner, group, size, and modification time.
Question 4: What does the `.` (single dot) represent in a Linux filesystem path?
- The root directory
- The parent directory
- The current directory (Correct answer)
- A hidden file prefix
Correct answer: The current directory
A single dot `.` refers to the current directory, so `./script.sh` runs a script in the current location.
Question 5: Which command would you use to find out what type of shell you are currently running?
- echo $SHELL (Correct answer)
- shell --version
- type shell
- cat /etc/shells
Correct answer: echo $SHELL
`echo $SHELL` prints the path to the current user's default shell (e.g., /bin/bash).
Question 6: How would you list all files in /etc that begin with the letter 's' using a wildcard?
- ls /etc/*s
- ls /etc/s* (Correct answer)
- ls /etc/s?
- ls -s /etc/
Correct answer: ls /etc/s*
`ls /etc/s*` uses the `*` wildcard to match any filename in /etc that starts with 's'.
Question 7: What does `ls -lh` display differently than `ls -l`?
- It shows hidden files
- It shows file sizes in human-readable units (KB, MB) (Correct answer)
- It sorts by modification time
- It shows the inode number
Correct answer: It shows file sizes in human-readable units (KB, MB)
The `-h` (human-readable) flag formats file sizes with units like K, M, G instead of raw byte counts.
Which `ls` option shows hidden files (those starting with a dot)?