Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Find Files with the find Command in Linux

Search for files by name, type, size or time with one powerful command.

VPS and Cloud Servers2 min read5 screenshots

Syntax

find [path] [options] [expression]
  • path is the folder where the search starts. If you leave it out, find starts in the current folder.
  • options change how find works.
  • expression is the search rule.

Find by name

find /home/ubuntu/Documents -name filename.txt
Finding a file by name

The search is case sensitive. Wildcards work if you put them in quotes: -name "*.txt".

Find by name and ignore case

Use -iname:

find /home/ubuntu/Documents -iname newfile.txt
A search that ignores case

Find by type

-type f finds files and -type d finds folders:

find /home/ubuntu/Documents -type f
Finding all files

Find by size

Files bigger than 100 MB:

find /home/ubuntu/Documents -type f -size +100M
Finding files by size

+ means bigger than, - means smaller than. Units are k, M and G.

Find by time

Files changed in the last day:

find . -type f -mtime -1
Finding files changed in the last day

-mtime -1 means less than one day ago. Use -mtime +30 for files older than 30 days.

More ideas

By permission

find /var/www -type f -perm 777

By owner

find /home -user ubuntu

Combine rules. Use -and, -or and -not:

find . -type f \( -name "*.log" -o -name "*.tmp" \)

Do something with the results. Delete old log files (check the list first!):

find /var/log -name "*.log" -mtime +30 -exec ls -l {} \;

Replace ls -l with rm only when you are sure.

Why use find

  • It searches by permissions, owner, size and time.
  • It combines rules with logical operators.
  • It can run a command on every file it finds.

Quick recap

  • find path -name "name" finds by name, -iname ignores case.
  • Use -type, -size and -mtime to narrow the search.
  • Use -exec to act on the results, with care.