Find command example in Linux

Bits Lovers
Written by Bits Lovers on
Find command example in Linux

I’ll be straight with you: the find command is probably the tool I use most often as a DevOps engineer. Sure, newer tools like fd (written in Rust and blazingly fast) have come along since I originally wrote this in 2021, but find remains indispensable for serious system work. Why? It’s available everywhere, handles complex operations that simpler tools can’t touch, and combines beautifully with other commands.

Let me walk you through how I actually use find in daily work.

Find Files by Type

The -type flag is your friend. Not only does it narrow down results, but it also makes searches run faster since find skips anything that doesn’t match your type.

Remember that on Linux, everything is a file—regular files, directories, sockets, you name it. Here’s what you can search for:

  • f: regular files
  • d: directories
  • c: character devices
  • p: named pipes (FIFOs)
  • l: symbolic links
  • s: sockets
  • b: block devices

Example: Find all directories in your home folder:

find ~/ -type d

Find Files and Directories by Name

Search a specific directory

This looks for files starting with “image” in the bitslovers directory:

find ./bitslovers -name "image*"

Find a specific file by name

Search from root (/) for a file named “bitslovers-info.txt”:

find / -name "bitslovers-info.txt"

Find files by extension

Find all PNG files in the current directory:

find . -name "*.png"

Find files AND directories by name

Search for anything starting with “bits”:

find ./ -name "bits*"

Find only files (or only directories)

When you know what you want, be specific. It’s faster and cleaner.

Files only:

find ./ -type f -name "bits*"

Directories only:

find ./ -type d -name "bits*"

By default, find is case-sensitive. Want to match “Bits”, “bits”, or “BITS”? Use -iname:

find ./ -iname "bits*"

Find multiple file types at once

Use -o (OR) to combine patterns:

find . -type f \( -name "*.zip" -o -name "*.tar" -o -name "*.pdf" \)

Search multiple directories

List the directories you want to search:

find ./Documents ./Pictures -name "bitslovers-logo.png" -type f

Find Files Containing Specific Text

Need to find a file but only remember what’s inside it? Combine find with grep:

find / -type f -exec grep -l -i "bitslovers" {} \;

The -l flag tells grep to print only matching filenames, not the matching lines.

Find Files by Size

Size comparisons use these prefixes:

  • c: bytes
  • k: kilobytes
  • M: megabytes
  • G: gigabytes

And these operators:

  • No prefix: exact size
  • -: less than
  • +: greater than

Find files smaller than 25MB

find . -type f -size -25M

Find files exactly 25MB

find . -size 25M

Find files larger than 2MB

find . -size +2M

Find files in a size range (50-100MB)

find / -size +50M -size -100M

Find directories larger than 1GB

find / -type d -size +1G

Find empty files

find ./ -type f -size 0

Find Files by Modification Time

Time-based searches are incredibly useful for cleanup tasks and troubleshooting.

Files modified in the last 10 hours

find . -mtime -10 -type f

Directories modified in the last 2 days

find . -mtime -2 -type d

Files older than 10 days

find ~/ -type f -name '*.zip' -mtime +10

Files not accessed in 30 days

find ~/ -atime +30

Files accessed exactly 30 days ago

find ~/ -atime 30

Files accessed in the last 30 days

find ~/ -atime -30

Files modified between 30 and 60 days ago

find ~/ -type f -mtime +30 -mtime -60

Files accessed in the last 5 minutes

find . -amin -5 -type f

Find Files by Permissions

The permission search is powerful for security audits.

Find files with permission 777

find . -perm 777

Find files writable by anyone

find . -perm /222

Find files owned by a specific user

find /tmp -user mike

Find specific file types owned by a user

find /home -user mike -iname "*.png"

Perform Actions on Search Results

This is where find really shines. The -exec flag lets you run commands on matching files.

Change permissions on matching files

Make all shell scripts executable:

find . -name "*.sh" -type f -exec chmod 755 {} \;

Find and copy files

Copy all PDFs to your Documents folder:

find . -iname '*.pdf' -exec cp {} ~/Documents \;

Find and delete files

Warning: Be careful with this one. I always run the command without -delete first to see what will be matched.

find /tmp -name "*.bkp" -delete

Pro tip: If you put -delete at the beginning of your expression, it will delete everything from your starting point downward. Always place it at the end.

A Note on Modern Alternatives

Since I first wrote this guide, tools like fd have gained popularity. Here’s when I use each:

Use fd when:

  • You want simple, fast searches
  • You appreciate colorized output
  • You like intuitive syntax (regular expressions by default)
  • You’re doing interactive searches

Use find when:

  • You need complex conditions (size + time + permissions)
  • You’re on a minimal system without extra tools
  • You need POSIX compatibility
  • You’re combining with -exec for batch operations

Honestly? I use both. fd for quick lookups, find for heavy lifting.

Conclusion

The find command has been around forever because it works. Master these examples and you’ll handle 95% of file-finding tasks you’ll encounter in daily Linux administration.

Want to dive deeper? Check the man page—there’s always more to learn.

Questions? Drop them in the comments below.

Bits Lovers

Bits Lovers

Professional writer and blogger. Focus on Cloud Computing.

Comments

comments powered by Disqus