How to Find Files and Directories with the Linux find Command
The find command searches the filesystem for files and directories that match conditions you give it. The classic form is find /path -name "pattern". It is the most flexible way to locate files, because it can filter by name, type, size and modification time — and then run a command on every result.
Find by name
Search a starting directory with -name. The pattern can include wildcards, so *.conf matches every file ending in .conf.
Find directories only with -type
Use -type to filter by file type: f for regular files, d for directories, l for symbolic links. This is how you find every empty folder or all log files in a tree.
Find by size and age
Conditions combine naturally. Find large files with -size (use +100M for larger than) or old files with -mtime (use +30 for older than 30 days).
Ignore case with -iname
Filesystem names are case-sensitive. Use -iname when you are not sure about the case, so Report.TXT matches a search for report.txt.
Run a command on results with -exec
To act on every match, use -exec followed by the command and a literal {} for the file. This deletes every .bak file in the tree:
Test carefully — there is no undo. The find reference page documents all tests and actions.
Keep learning
Related guides: The Linux ls Command: List Files Like a Pro · How to Search Files for Text with the Linux grep Command · How to Copy Files and Directories with the Linux cp Command. Read all tutorials on the Learn Linux blog.