Linux find Command: 32 Examples, From Beginner to Pro Level
Learn how to easily locate, filter, and manage files in Linux using the powerful find command. This beginner-friendly guide covers 32 practical examples with clear explanationsโperfect for anyone new to the Linux terminal.
๐ Master Linux find Command
The find command in Linux is used to search for files and directories based on different criteria such as name, size, permissions, modification time, and more. This guide explains 32 powerful find command examples that will make you pro in it.
1. ๐ Find Files by Name
find /home/user/documents -name "example.txt"
This searches for a file named example.txt inside /home/user/documents.
2. ๐ Find Files by Extension
find /var/log -name "*.log"
Finds all files ending with .log in /var/log directory.
3. ๐ Find Files Modified in the Last 7 Days
find /etc -mtime -7
Lists files in /etc that were modified in the past 7 days.
4. ๐ Find Files Modified More Than 30 Days Ago
find /usr/local -mtime +30
Searches for files not modified in the last 30 days.
5. ๐๏ธ Find and Delete Files
find /tmp -name "oldfile.txt" -delete
Deletes a file named oldfile.txt in /tmp.
6. ๐ Find Empty Files or Directories
find /var/www -empty
Shows all empty files and folders under /var/www.
7. ๐ฆ Find Files Larger Than 100MB
find /home/user/downloads -size +100M
Finds files bigger than 100MB in the downloads folder.
8. ๐ค Find Files Owned by a Specific User
find /home -user username
Lists all files owned by the given username in /home.
9. ๐ Find Files with 0644 Permissions
find /etc -perm 0644
Finds files with read/write permissions for the owner and read-only for others.
10. โ๏ธ Find Files and Run a Command (Gzip Example)
find /var/log -name "*.log" -exec gzip {} \;
Compresses all .log files in /var/log using gzip.
11. ๐งน Delete Empty Files Using Command
find /home/user/documents -type f -empty -exec rm {} \;
Deletes all empty files in the documents folder.
12. ๐ Find and Print File Details
find /home/user/documents -type f -exec ls -lh {} \;
Shows file sizes and details of all files in the folder.
13. ๐ซ Exclude a Specific Directory While Searching
find / -path "/proc" -prune -o -name "*.conf" -print
Searches for .conf files, but skips /proc directory.
14. ๐ Find Files Modified in the Last Hour
find /var/www -mmin -60
Shows files modified in the last 60 minutes.
15. ๐ฆ Archive Files with a Specific Extension
find /home/user/pictures -name "*.jpg" | xargs tar -czvf archive.tar.gz
Archives all .jpg images in a tar.gz file.
16. ๐ Find Symbolic Links
find /usr/bin -type l
Shows all symbolic (soft) links in /usr/bin.
17. ๐ข Find Files by Inode Number
find / -inum 456332
Finds a file using its inode number (advanced).
18. ๐ซ Exclude a File Type
find /home/user -not -name "*.txt"
Finds all files except .txt files.
19. ๐ฅ Find Files by Group Ownership
find /var/log -group syslog
Finds all files belonging to the syslog group.
20. ๐ Find Files Between 50MB and 100MB
find /home/user/downloads -size +50M -size -100M
Searches for files between 50MB and 100MB.
21. ๐ Find and Sort by Modification Time
find /var/log -type f -exec ls -lt {} +
Shows files sorted by most recently modified.
22. ๐ Find Files Modified in Last 2 Hours
find /var/log -mmin -120
Finds files updated in the last 2 hours.
23. ๐งโโ๏ธ Find Files by User and Group
find /home -user username -group groupname
Finds files owned by a specific user and group.
24. ๐ Find Files Only Readable by Owner
find /var/log -perm 600
Finds files with read/write access only for the owner.
25. ๐งน Delete Files Larger Than 1GB
find /var/log -size +1G -exec rm -f {} \;
Deletes files over 1GB in size.
26. ๐ Limit Search Depth to 1 Level
find /home/user -maxdepth 1 -name "*.txt"
Searches for .txt files only in the top-level directory.
27. ๐ Find Files Accessed Over 90 Days Ago
find /var/log -atime +90
Lists files that havenโt been accessed in 90+ days.
28. ๐ป Find Hidden Files
find /home/user -name ".*"
Finds hidden files (those starting with a dot).
29. ๐ Find Files Created More Than 1 Day Ago
find /home/user -ctime +1
Finds files created more than one day ago.
30. ๐พ Find Block Devices
find /dev -type b
Lists block devices (hard disks, USBs, etc).
31. ๐ Exclude Files with Certain Permissions
find / -perm /a=w -not -perm /a=w
Finds files that do not have write permission for all.
32. ๐ Find Files Containing a String in Their Name
find /home/user -name "*config*"
Searches for files with config in their name.
โ Thatโs it
The find command is incredibly flexible and powerful. With it, you can locate, manage, and even delete files with precision. Play around with these commands in a test directory to get comfortable.Try here Blogrc Term or on your terminal.
Note: Always be cautious with delete operations (-delete, -exec rm)โuse them only when youโre sure.