0
0
Linux CLIscripting~20 mins

locate for fast filename search in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Locate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of locate command with a simple filename
What is the output of the following command if the file notes.txt exists in /home/user/documents and /var/log directories?

locate notes.txt
Linux CLI
locate notes.txt
Anotes.txt not found
B
/home/user/documents/notes.txt
/var/log/notes.txt
C/home/user/documents/notes.txt
Dlocate: command not found
Attempts:
2 left
💡 Hint
The locate command lists all paths containing the filename quickly from its database.
💻 Command Output
intermediate
1:30remaining
Effect of updating locate database
What happens if you create a new file /tmp/testfile.txt and immediately run locate testfile.txt without updating the database?
Linux CLI
touch /tmp/testfile.txt
locate testfile.txt
ANo output because the database is not updated yet
B/tmp/testfile.txt
CError: database missing
Dlocate: command not found
Attempts:
2 left
💡 Hint
locate uses a database updated periodically, not real-time file system scanning.
📝 Syntax
advanced
2:00remaining
Correct syntax to search for files ending with .log using locate
Which command correctly finds all files ending with .log using locate?
Alocate --regex '\.log$'
Blocate .log$
Clocate '*.log'
Dlocate -r '\.log$'
Attempts:
2 left
💡 Hint
Use the -r option to enable regex search in locate.
🔧 Debug
advanced
1:30remaining
Why does locate not find a recently created file?
You created a file /home/user/newfile.txt but locate newfile.txt returns no results. What is the most likely reason?
AThe filename is case sensitive and must be uppercase
BThe file permissions prevent locate from seeing the file
CThe locate database is outdated and needs updating with updatedb
DThe locate command only searches system files, not user files
Attempts:
2 left
💡 Hint
locate uses a database updated periodically, not real-time scanning.
🚀 Application
expert
2:30remaining
Automate locate database update and search
You want to write a script that updates the locate database and then searches for files named report.csv. Which script snippet correctly does this?
Asudo updatedb && locate report.csv
Bsudo locate report.csv && updatedb
Cupdatedb locate report.csv
Dlocate report.csv && sudo updatedb
Attempts:
2 left
💡 Hint
The database must update before searching to include new files.