010-160 Searching and Extracting Data 3 — Questions and Answers
Question 1: Which find option is used to search by file modification time within the last 2 days?
- find . -time 2
- find . -mtime -2 (Correct answer)
- find . -atime 2
- find . -newer 2
Correct answer: find . -mtime -2
find -mtime -2 finds files whose modification time is less than 2 days ago.
Question 2: What does the `tr 'a-z' 'A-Z'` command do?
- Deletes lowercase letters
- Translates lowercase letters to uppercase (Correct answer)
- Counts lowercase letters
- Reverses the alphabet
Correct answer: Translates lowercase letters to uppercase
tr translates characters; 'a-z' to 'A-Z' converts every lowercase letter to its uppercase equivalent.
Question 3: Which grep option prints the line number before each matching line?
- -c
- -l
- -n (Correct answer)
- -v
Correct answer: -n
grep -n prefixes each matching line with its line number in the file.
Question 4: What does `uniq` do by default when given sorted input?
- Sorts the lines alphabetically
- Removes consecutive duplicate lines (Correct answer)
- Counts all unique words
- Reverses the order of lines
Correct answer: Removes consecutive duplicate lines
uniq removes consecutive duplicate lines, so input should be sorted first to eliminate all duplicates.
Question 5: Which command searches for files larger than 100MB?
- find . -size +100M (Correct answer)
- find . -size 100MB
- find . -larger 100M
- find . -gt 100M
Correct answer: find . -size +100M
find -size +100M finds files whose size exceeds 100 megabytes.
Question 6: How do you use grep to search recursively through all files in a directory?
- grep -a pattern dir/
- grep -r pattern dir/ (Correct answer)
- grep -f pattern dir/
- grep -d pattern dir/
Correct answer: grep -r pattern dir/
grep -r (or --recursive) searches through all files in the directory and its subdirectories.
Question 7: What does `tail -f /var/log/syslog` do?
- Shows the first 10 lines and exits
- Follows the file and prints new lines as they are written (Correct answer)
- Filters lines matching 'syslog'
- Shows lines in reverse order
Correct answer: Follows the file and prints new lines as they are written
tail -f follows a file in real time, printing new content as it is appended.
Which find option is used to search by file modification time within the last 2 days?