Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
25 Practical Examples of Linux Find Command
The Linux find command is a powerful utility that enables you to search for files and directories on your system. The command searches for files and directories based on various criteria, including file name, type, size, date modified, ownership, and permissions, among others.
This article provides 25 practical examples of how to use the Linux find command to search for files and directories based on specific criteria. Each example demonstrates real-world scenarios that system administrators and users encounter daily.
Basic File and Directory Search
1. Find Files by Name
The simplest way to use the Linux find command is to search for files by name. To search for all files named example.txt, use the following command:
find / -name example.txt
This command searches for the file example.txt in the root directory and all subdirectories.
2. Find Directories by Name
You can search for directories by name using the -type d option:
find / -type d -name example
3. Find Files by Name (Case Insensitive)
Use -iname to ignore case sensitivity when searching for files:
find / -iname example.txt
Search by File Type and Extension
4. Find Files by Extension
To find all files with a specific extension, use wildcards:
find / -type f -name "*.txt"
5. Find PDF Files
Search for all PDF files on your system:
find / -type f -name "*.pdf"
6. Find Symbolic Links
To find all symbolic links in the system:
find / -type l
Search by File Size
7. Find Large Files (10MB+)
Search for files larger than 10 megabytes:
find / -type f -size +10M
8. Find Very Large Files (100MB+)
Find files larger than 100 megabytes:
find / -type f -size +100M
9. Find Files by Exact Size
Find files exactly 1 megabyte in size:
find / -type f -size 1M
Search by Time-Based Criteria
10. Find Recently Modified Files (24 hours)
Find files modified within the last 24 hours:
find / -type f -mtime -1
11. Find Recently Modified Files (7 days)
Find files modified within the last 7 days:
find / -type f -mtime -7
12. Find Old Files (30+ days)
Find files older than 30 days:
find / -type f -mtime +30
13. Find Recently Modified Files (by minutes)
Find files modified in the last 10 minutes:
find / -type f -mmin -10
14. Find Recently Accessed Files
Find files accessed within the last 7 days:
find / -type f -atime -7
15. Find Recently Accessed Files (by minutes)
Find files accessed in the last 24 hours (1440 minutes):
find / -type f -amin -1440
Search by Ownership and Permissions
16. Find Files by User
Find all files owned by a specific user:
find / -type f -user john
17. Find Directories by User
Find all directories owned by a specific user:
find / -type d -user john
18. Find Files by Group
Find files owned by a specific group:
find / -type f -group users
19. Find Directories by Group
Find directories owned by a specific group:
find / -type d -group users
20. Find Files by Permissions
Find files with specific permissions (owner read/write):
find / -type f -perm 600
21. Find Directories by Permissions
Find directories with specific permissions (owner read/write/execute):
find / -type d -perm 700
Special Search Cases
22. Find Empty Files
Find all empty files in the system:
find / -type f -empty
23. Find Empty Directories
Find all empty directories:
find / -type d -empty
24. Find Files with Multiple Criteria
Combine multiple search criteria to find specific files. This example finds files modified in the last 24 hours, owned by user john, and larger than 1 megabyte:
find / -type f -user john -size +1M -mtime -1
25. Find Files and Execute Commands
Find files and execute commands on them. This example finds all .log files and displays their details:
find /var/log -name "*.log" -exec ls -la {} \;
Practical Tips
| Option | Description | Example Usage |
|---|---|---|
-name |
Case-sensitive name search | -name "*.txt" |
-iname |
Case-insensitive name search | -iname "*.TXT" |
-type f |
Regular files only | -type f |
-type d |
Directories only | -type d |
-size +10M |
Files larger than 10MB | -size +10M |
-mtime -7 |
Modified within 7 days | -mtime -7 |
Conclusion
The Linux find command is an essential tool for system administration and file management. With these 25 practical examples, you can efficiently search for files and directories based on name, size, modification time, ownership, and permissions. Mastering the find command will significantly improve your productivity when working with Linux systems.
