FIND Command

Akash C MAkash C M
2 min read

The find command in LINUX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner and permissions. By using the ‘-exec’ other UNIX commands can be executed on files or folders found.

Find by NAME

To search for files and directories by their name

find -name <file/dir_name>
find -iname <file/dir_name>

Find by TYPE

To only search for files

find type -f <file_name>

To only search for directories

find -type d -name <dir_name>

To search the whole Linux system

find / -name  <file/dir_name>

Find by PERMISSIONS

To find all the files and directories with permission 644

find perm 644

Finding by TIME

To find all the files and directories that were created/modified in the last 5 days

find -mtime -5

To find all the files and directories that were created/modified more than 5 days ago

find -mtime +5

Find all the files that were created in the last 60 minutes

find -type f -mmin -60

Find EMPTY or NON-EMPTY files/directories

To find all the empty files

find -type f -empty

To find all the nonempty files

find -type f  -non -empty

Find by DEPTH

To search for files and directories only in the current directory

find -mixdepth 1 -name <file/dir>

To search for files and directories in the subdirectory

find -mindepth 2 -maxdepth 2 -name <file/dir_name>

Find by SIZE of the file

Find all the files with size more than 1 MB

find -type f -size +1M

Find & DELETE the empty files

Find and delete all the empty files

find -type f -empty -print -delete
0
Subscribe to my newsletter

Read articles from Akash C M directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Akash C M
Akash C M

Empowering community via open source and education