Lesson 3.9: Searching the filesystem: find and locate
Finding files by name, type, size, age and owner with find, acting on every match with -exec, and the fast database search of locate; plus which for commands.
17 min
You will learn to
- Search by name and type with find (-name, -iname, -type)
- Search by size and age (-size, -mtime)
- Act on results with -exec
- Use locate for fast name searches and which for commands
Key terms
- find
- Walks the directory tree from a starting point right now and prints every path that passes all the tests you give.
- Test
- A condition in find: -name, -iname, -type, -size, -mtime (days since last change), -user, -empty… Several tests together must all be true.
- Action
- What find does with each match: -print (default), -ls, -exec COMMAND {} \;, -delete.
- locate / updatedb
- locate searches a database of every path on the system; updatedb rebuilds that database, usually once a day automatically.
- which
- Shows which program file a command name runs, by searching the directories in $PATH.
← Compressing and archiving files · All lessons · Working with users and groups →