Searching Files From Terminal

Find files in current directory

$ find . 

It will show all the files and directories present in the current directory.

Find files which are just files and not directories

$ find . -type f

It will print all the files of type file.

Find files by name

$ find . -name "fileName"

It will print all the files with name "fileName"

Find files by extension

$ find . -name "*.txt"

It will find all the files of extension "txt"

Find files by name [case insensitive]

$ find . -iname "fileName"

It will find all the files with name "fileName" case insensitively.

Find files by size [greater than 1 mb]

$ find . -size +1M

It will look for files greater than 1 mb

Find files by size [smaller than 1 mb]

$ find . -size -1M

It will look for files smaller than 1 mb

Find files by modification time

$ find . -mtime -1

It will look for files which were modified within the last day

Find files by access time

$ find . -atime -1

It will look for files which were accessed within the last day

Find files by created time

$ find . -ctime -1

It will look for files which were created within the last day

Find using logical operators

$ find . -name "*.php" -or -name "*.js" -and -mtime -1

It will search for all the php files or js files which were modified within a day.

Find by excluding directory

$ find . -name "*.php" -print -or -name "excludeDirName" -prune

It will search for all the php files but exclude dir "excludeDirName"

comments powered by Disqus