Introduction to the Find Command
The Linux find command is one of the most powerful and frequently used commands for searching files and directories. It supports searching by name, size, modification time, permissions, and much more.
This guide provides 25 practical examples of the find command with realistic outputs to help you master file searching in Linux.
1. Find Files by Name
find /home/user -name "*.txt"
/home/user/document.txt
/home/user/notes.txt
/home/user/docs/report.txt
2. Case-Insensitive Search
find . -iname "*.JPG"
./vacation/beach.jpg
./photos/SUNSET.Jpg
3. Find Directories Only
find /var -type d -name "log*"
/var/log
/var/log/apt
4. Find Regular Files Only
find . -type f -name "config*"
./project/config.json
./app/config.ini
5. Find Files Modified in Last 24 Hours
find /tmp -type f -mtime -1
/tmp/temporary_file.tmp
/tmp/cache_data.dat
6. Find Files Modified More Than 30 Days Ago
find /var/log -type f -mtime +30
/var/log/syslog.2.gz
/var/log/auth.log.3.gz
7. Find Files by Size (Greater than 10MB)
find /home -type f -size +10M
/home/user/videos/movie.mp4
/home/user/backup.tar.gz
8. Find Empty Files and Directories
find . -empty
./empty_dir
./temp/empty_file.txt
9. Find Files with Specific Permissions
find . -type f -perm 644
./index.html
./style.css
./script.js
10. Find Executable Files
find /usr/bin -type f -executable
/usr/bin/ls
/usr/bin/cp
/usr/bin/mv
11. Find Files and Execute Command
find . -name "*.tmp" -exec rm {} \;
(No output if successful, files are deleted)
12. Find Files and Display Info
find . -name "*.conf" -exec ls -l {} \;
-rw-r--r-- 1 user user 1024 Jan 15 10:30 ./app.conf
-rw-r--r-- 1 user user 2048 Feb 20 14:25 ./server.conf
13. Find Files and Copy Them
find /source -name "*.jpg" -exec cp {} /destination \;
(Files are copied silently)
14. Find Files by Multiple Criteria
find . -name "*.log" -size +1M -mtime +7
./logs/application.log
./logs/error.log
15. Find Files and Count Them
find /var/www -name "*.php" | wc -l
42
16. Find Files and Sort by Size
find . -type f -name "*.mp4" -exec du -h {} \; | sort -rh
1.5G ./movies/movie1.mp4
800M ./videos/tutorial.mp4
250M ./clips/demo.mp4
17. Find Files by Owner
find /home -user john -name "*.docx"
/home/john/documents/report.docx
/home/john/work/proposal.docx
18. Find Files by Group
find /var/www -group www-data -name "*.php"
/var/www/html/index.php
/var/www/html/config.php
19. Find Files and Archive Them
find . -name "*.log" -mtime +30 -exec tar -czf old_logs.tar.gz {} +
(Creates archive file)
20. Find Files and Change Permissions
find . -name "*.sh" -exec chmod +x {} \;
(Permissions changed silently)
21. Find Files and Search Within
find . -name "*.txt" -exec grep -l "error" {} \;
./logs/system.txt
./errors/application.txt
22. Find Files and Delete with Confirmation
find /tmp -name "*.tmp" -ok rm {} \;
< rm ... /tmp/file1.tmp > ? y
< rm ... /tmp/file2.tmp > ? n
23. Find Files by Depth
find . -maxdepth 2 -name "*.conf"
./app.conf
./config/database.conf
24. Find Files with Custom Format
find . -name "*.py" -printf "%p - %s bytes - %Tb %Td %TY\n"
./script.py - 1024 bytes - Jan 15 2023
./utils/helper.py - 2048 bytes - Feb 20 2023
25. Find Files and Exclude Directories
find . -name "*.js" -not -path "./node_modules/*"
./app.js
./src/main.js
./public/script.js
Find Command Options Summary
| Option |
Description |
-name |
Search by filename |
-iname |
Case-insensitive name search |
-type |
File type (f=file, d=directory) |
-size |
File size (+n = larger, -n = smaller) |
-mtime |
Modification time (days) |
-user |
File owner |
-exec |
Execute command on found files |
-delete |
Delete found files |
-maxdepth |
Limit search depth |
-perm |
Search by permissions |