When working with Linux, efficiency is everything. In this tutorial, we’re diving into one of the most powerful and flexible tools available: the find command in Linux. Whether you’re managing thousands of files or just trying to locate a single forgotten document, this command-line tool has you covered.
The find command in Linux is used to search for files and directories based on various criteria such as name, size, type, date modified, and more. It’s extremely versatile and can search through an entire filesystem or just specific directories.
You can read more about this find utility here.
The find command in Linux is a must-know for:
DevOps Engineers
Linux System Administrators
Cybersecurity Analysts
Developers and QA Engineers
Data Analysts and Scientists
If your daily grind involves managing files or troubleshooting systems, mastering the find command will save you tons of time.
The basic structure of the find command in Linux is:
find [path] [options] [expression]
Example:
find /home -name notes.txt
This searches for a file named notes.txt
starting in the /home
directory.
find / -name "example.txt"
Case-insensitive version:
find / -iname "example.txt"
Use this to find a specific file anywhere on the system. It’s a lifesaver when you forget where you saved that config!
find /var/log -name "*.log"
Perfect for locating all log files, especially when doing system audits.
find /tmp -type f -name "*.tmp" -delete
Clean up temp files quickly. Great for system maintenance. Always double-check before using -delete
.
find / -size +100M
Hunt down large files taking up space. Useful for freeing up disk space.
find /home -mtime -7
Handy for tracking recent changes or uploads.
find /var/log -type f -name "*.log"
Searches for all .log
files in /var/log
. Great for auditing or cleanup.
find /etc -type f
Lists all files (not directories) in /etc
. Helps focus your search.
find /var -type d
Finds only directories. Useful for checking structure or empty folders.
find / -size +100M
Identifies large files over 100MB. Useful when running out of disk space.
find /tmp -size -10k
Finds tiny files. Useful for cleanup or analyzing unnecessary small files.
find /home -atime -1
Great for seeing what files were accessed recently (useful for forensic checks).
find /var/log -name "*.log" -exec gzip {} \;
Compresses each .log
file found. Replace gzip
with any command.
find /tmp -name "*.tmp" -ok rm {} \;
Like -exec
but safer — asks before deleting each file.
find /home -type f -empty
Useful for identifying and removing zero-byte files.
find /var -type d -empty
Helps clean up unused directories.
find / -user username
Lists all files belonging to a specific user — great for audits.
find / -type f -perm 644
Finds files with permission 644
. Helps check for insecure or misconfigured files.
find / -type f ! -perm 644
Shows files not having 644
permissions — great for security checks.
find /home -mtime +7 -mtime -14
Narrows down modification time to a specific week range.
find /home -type f -exec ls -lh {} \;
Lists each found file with size and permissions — combines find
with ls
.
Why You Should Use the find Command in Linux
Using the find command in Linux can:
Stay tuned for part two, where we’ll explore advanced find options like -exec, searching by permissions, and combining find with grep!