Question 1
You want to find all .log files modified in the last 2 days in /var/log and display their full paths. Which command is correct?
find /var/log -name "*.log" -mtime 2
find /var/log -type f -mtime -2 -name "*.log"
find /var/log -type d -mtime -2 -name "*.log"
find /var/log -mtime +2 -name "*.log"
Question 2
You need to find all files with permission 777 inside /home, but skip hidden directories. Which command will achieve this?
find /home -type f -perm 777 -not -path "*/.*"
find /home -perm 777 -a ! -name ".*"
find /home -perm 777 -exclude hidden
find /home -type f -perm 777 --skip-hidden
Question 3
The command below is executed:
find . -type f -name "*.conf" -exec grep -l "Listen" {} \;
Print all .conf files that contain “Listen”
Display the number of lines matching “Listen”
Delete all .conf files that contain “Listen”
Print matching lines instead of filenames
Question 4
Which of the following grep commands will search for “error” (case-insensitive) inside all .log files in /var/log, and also show line numbers?
grep -in "error" /var/log/*.log
grep -ni error /var/log
grep -l "error" /var/log/*.log
grep "error" -n -r /var/log/*.log
Question 5
The command locate sample.txt shows results that include files you recently deleted. Why?
locate command is showing cached results from a database that hasn’t been updated.
File recovery feature of locate retrieves deleted files.
The database of locate is corrupted.
The /tmp folder keeps deleted file paths for 24 hours.
Question 6
You want to display only filenames that contain the word “admin” but not show the actual matched lines.
grep -o "admin" *
grep -l "admin" *
grep -n "admin" *
grep -v "admin" *
Question 7
You run this command:
find /home/user -empty
Only empty files
Only empty directories
Both empty files and directories
Only hidden empty files
Question 8
Which of the following is the correct syntax to find .tmp files and delete them after confirmation?
find . -name "*.tmp" | rm -i
find . -type f -name "*.tmp" -exec rm -i {} \;
find . -delete "*.tmp"
rm -i $(find . "*.tmp")
Question 9
You want to find all .txt files under /documents but limit the search depth to only one subdirectory level.
find /documents -maxdepth 1 -name "*.txt"
find /documents -depth 1 -name "*.txt"
find /documents -mindepth 1 -name "*.txt"
find /documents -onlydepth 1 -name "*.txt"
Question 10
You want to count the number of times the word “root” appears in /etc/passwd.
grep -n "root" /etc/passwd
grep -c "root" /etc/passwd
grep -o "root" /etc/passwd | wc -l
Both B and C
There are 10 questions to complete.