0
0
Linux CLIscripting~5 mins

find command basics in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to search for files or folders on your computer quickly. The find command helps you look through folders and find exactly what you want by name, type, or other details.
When you want to find all files with a certain name in your documents folder.
When you need to locate all images in a directory and its subdirectories.
When you want to find files modified in the last day to check recent changes.
When you want to delete all temporary files in a folder safely.
When you want to list all directories inside a specific folder.
Commands
This command searches inside /home/user/Documents and all its subfolders for files named exactly report.txt.
Terminal
find /home/user/Documents -name "report.txt"
Expected OutputExpected
/home/user/Documents/work/report.txt /home/user/Documents/personal/report.txt
-name - Search files by exact name pattern.
This command finds all files (-type f) ending with .jpg inside /home/user/Pictures and its subfolders.
Terminal
find /home/user/Pictures -type f -name "*.jpg"
Expected OutputExpected
/home/user/Pictures/vacation/photo1.jpg /home/user/Pictures/events/birthday.jpg
-type f - Limits search to files only.
-name - Search files matching the pattern.
This command finds files in /tmp modified in the last 1 day (-mtime -1).
Terminal
find /tmp -type f -mtime -1
Expected OutputExpected
/tmp/tempfile1 /tmp/logs/recent.log
-mtime - Find files modified less than 1 day ago.
This command lists all directories (-type d) inside /home/user/Downloads and its subfolders.
Terminal
find /home/user/Downloads -type d
Expected OutputExpected
/home/user/Downloads /home/user/Downloads/music /home/user/Downloads/music/rock
-type d - Limits search to directories only.
Key Concept

If you remember nothing else from this pattern, remember: find searches folders recursively and filters results by conditions like name or type.

Common Mistakes
Using find without quotes around the name pattern
Shell may expand wildcards before find runs, causing wrong or no results.
Always put the pattern in quotes, like -name "*.txt".
Not specifying -type when looking for files or directories
find returns both files and directories, which may confuse results.
Use -type f for files or -type d for directories to get precise results.
Running find in a very large folder without limits
It can take a long time and produce too many results.
Narrow search by folder path, name, or modification time to speed it up.
Summary
Use find to search folders and subfolders for files or directories by name or type.
Put name patterns in quotes to avoid shell expansion issues.
Use -type to specify if you want files (-type f) or directories (-type d).
Use -mtime to find files by modification time.
Check results with simple commands before using find for actions like delete.