Skip to content

Instantly share code, notes, and snippets.

@AbhishekPednekar84
Last active May 2, 2020 14:13
Show Gist options
  • Save AbhishekPednekar84/80b55421b03578aa3ee06ced79d51e3a to your computer and use it in GitHub Desktop.
Save AbhishekPednekar84/80b55421b03578aa3ee06ced79d51e3a to your computer and use it in GitHub Desktop.

Usage of the find command in Linux

Accessing the help manual

man find


Basic search

Find all files and sub-directories in the current directory

find .

Find all files in the current directory

find . -type f

Find all sub-directories in the current directory

find . -type d

Find all files starting with the word "test" (case sensitive)

find . -type f -name "test*"

Find all files starting with the words "test" or "Test" (case insensitive)

find . -type f -iname "test*"


Search using metadata

Files modified less than 5 minutes ago

find . -type f -mmin -5

Files modified more than 5 minutes ago

find . -type f -mmin +5

Files modified more than 1 minute and less than 5 minutes ago

find . -type f -mmin +1 -mmin -5

Files modified less than 10 days ago

find . -type f -mtime -10

Files modified more than 10 days ago

find . -type f -mtime +10

Note: Like mmin and mmtime, one may also use amin and atime to find files / directories accessed x minutes and days ago respectively. Similarly, cmin and ctime will look for files / directories changed (owner, permissions etc...) x minutes and days ago respectively.

Files with size greater than 1MB

find . -type f -size +1M

Files with size less than 1MB

find . -type f -size -1M

Files with size greater than 1kB

find . -type f -size +1k

Files with size greater than 1GB

find . -type f -size +1G


Find empty files and directories

find . -empty


Find files / directories by permission

find . -perm 777


Excluding sub-directories using maxdepth

Find html files in current directory (exclude sub-directories)

find . -maxdepth 1 -type f -name "*.html"

Find html files in current directory and only those sub-directories that are exactly one level below

find . -maxdepth 2 -type f -name "*.html"


Execute commands against results of find using exec

Change the owner and group of all files

find . -type f -exec chown owner_name:group_name {} +

Remove html files in only the current directory (exclude sub-directories)

find . -maxdepth 1 -type f -name "*.html" -exec rm {} +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment