The find
command is one of the most powerful and flexible utilities in the Linux terminal. Whether you’re searching for files by name, size, type, or modification date—or performing operations on them like deletion, execution, or permission change—find
makes it easy to locate exactly what you need. It’s especially helpful when working on large filesystems, cleaning up old logs, or scripting administrative tasks. In this guide, we’ll explore 10 practical and real-world find
command examples that every Linux user should know.
1. Find Files by Name
To search for a file with a specific name in a directory and its subdirectories, use the -name
option.
$ find /home/myuser -name "notes.txt" /home/myuser/documents/notes.txt
Use wildcards to match patterns, such as "*.log"
to find all log files.
2. Case-Insensitive Name Search
To ignore case sensitivity when searching for filenames, use the -iname
flag.
$ find /home/myuser -iname "readme.md" /home/myuser/Projects/README.md
This is helpful when working on systems where filename casing varies.
3. Find Files by Extension
You can search for all files of a specific extension by using wildcard patterns.
$ find /var/log -type f -name "*.log" /var/log/syslog.log /var/log/apache2/error.log
This is commonly used for log rotation, backup, or cleanup scripts.
4. Find Files by Size
Use the -size
option to find files larger or smaller than a specific size. Add +100M
for files larger than 100MB, or -50k
for smaller than 50KB.
$ find /home/myuser/videos -type f -size +500M
This is useful when trying to free up disk space by targeting large files.
5. Find Files by Last Modified Time
You can locate files based on how recently they were modified using the -mtime
flag. -mtime +10
means modified more than 10 days ago; -mtime -3
is within the last 3 days.
$ find /var/log -type f -mtime +30
This is particularly useful for cleaning up old files in automated maintenance tasks.
6. Find Empty Files or Directories
Use -empty
to find zero-length files or empty folders. This can help identify junk or placeholder files in your projects.
$ find /home/myuser -type f -empty $ find /home/myuser -type d -empty
Combine with -delete
to remove them automatically, after reviewing carefully.
7. Execute Commands on Found Files
find
allows you to perform operations on the files it finds using -exec
. This is perfect for batch operations.
$ find /home/myuser/docs -type f -name "*.bak" -exec rm {} \;
This command removes all .bak
files. Replace rm
with any other command to perform different actions.
8. Find Files by Permissions
You can search for files with specific permission settings using -perm
.
$ find /home/myuser -type f -perm 0777
This finds all files with full read/write/execute permissions, which might be a security risk on multi-user systems.
9. Find Recently Accessed Files
Use the -atime
flag to find files based on the last access time. -atime 0
shows files accessed today, -atime +30
finds files not accessed in the last 30 days.
$ find /home/myuser -type f -atime +90
Great for identifying files that are no longer in use and may be archived or deleted.
10. Find and Archive Files
You can combine find
with tar
to archive files that meet certain criteria, such as all logs older than 30 days.
$ find /var/log -type f -name "*.log" -mtime +30 -print0 | tar -czvf old_logs.tar.gz --null -T -
-print0
handles spaces in filenames safely. This is a clean way to archive based on age or other attributes.
Conclusion
The find
command is more than just a file search utility—it’s a foundational Linux tool for system administration, scripting, performance optimization, and even security audits. By understanding its many flags and combining it with other commands like rm
, tar
, or chmod
, you can automate complex tasks and gain full control over your file systems. Whether you need to clean up space, detect vulnerabilities, or simply locate a missing document, these examples will give you practical ways to harness the power of find
.
Pro tip: When using destructive actions like -exec rm
or -delete
, always test your find
command first without execution to confirm the correct files are selected. Add -print
at the end of your command to preview the matches.
With regular practice and thoughtful use, find
will become one of your most trusted tools in the Linux terminal.