Part of Linux Commands Cheat Sheet

Search for files in a directory hierarchy.

Assume you have the following files:


Find all files in directory

find ~/temp

# find files in current directory

Find by file type

# -type f for files
find -type f

# -type d for directory
find -type d

Find by file name

# 2 matches: ./a.txt and ./z/a.txt
find -name a.txt

# -iname for case insensitive match
find -iname a.txt

# find all files which have .txt at the end
find -name "*.txt"

Find by file size

find -size -100k
find -size +50M

Find by file content

# find empty file and directories
find -empty

Want to find files containing specific text? try grep command:

# -r for recursive, -l for display filenames
grep -rl blabla .

Grep Command in Linux

Find by user and group

find -user root
find -group www-data

Find by time

# find files created 5 minutes ago
find -cmin 5

# find files created in last 5 minutes
find -cmin -5

# find files created more than 5 minutes
# find -cmin +5

# time in days
find -ctime 1
find -ctime -10
find -ctime +10

# number of days are rounded with remainder dropped, so the following command works
# find files created in last 24 hours
find -ctime 0

# modified time
find -mmin 5
find -mmin -60
find -mmin +60
find -mtime 1
find -mtime -3
find -mtime +30

# accessed time
find -amin 5
find -amin -60
find -amin +60
find -atime 1
find -atime -3
find -atime +30

# time range
find -atime +1 -atime -30

Find by permission

# find files with permission 644
find -perm 644

# find executable files
find -perm /u+x

find -executable

find -type f -executable

Exclude files

find ! -name a.txt
find ! -executable

Find and execute command to the file

# grep content in files
find -type f -exec grep 'a' {} \;

# find and delete (with confirmation)
find -name a.txt -exec rm -i {} \;


find command in Linux with examples - GeeksforGeeks

35 Practical Examples of Linux Find Command

find(1) - Linux man page