How to: Use “find” command in Linux (Debian, Ubuntu, Kali Linux, CentOS, RHEL/RedHat etc.)

Last Updated on

Table of Contents

  • 1 Find command basics
  • 2 Find files and folders by their size
  • 3 Find files by their Owner/Group
  • 4 Find files and folders by date and time
  • 5 Find files by their privileges

1 Find command basics

1.1 Find file from current folder

(“Permission denied” error will appear if the current user doesn’t have permission to access that folder)

Find file named “1.txt” within current working folder

find filename
find 1.txt
find 1.txt
find 1.txt

1.2 Find the file from a folder

Find “1.txt” file under “/tmp” folder

find /path/to/folder -name filename
find /tmp -name 1.txt
find file from a parent folder
find file from a parent folder

1.3 Find file (Ignoring the case/Case insensitive)

Find “1.txt” within “/tmp” folder, ignoring case.

find /path/to/folder -iname filename
find /tmp -iname 1.txt
Find file (Ignoring the case/Case insencitive)
Find file (Ignoring the case/Case insencitive)

1.4 Find folder/directory only

find /path/to/folder -type d -name foldername
find /tmp -type d -name abc
Find folder/directory
Find folder/directory only
Find folder/directory, ignoring the case
Find folder/directory only, ignoring the case

1.5 Find file only

find /path/to/folder -type f -name 1
find /tmp -type f -name 1.txt
Find file only
Find file only

1.6 Find specific file

Find .txt files from “/tmp” folder

find -type f -name "*.extension"
find -type f -name "*.txt"
Find specific file
Find specific file

2 Find files and folders by their size

2.1 Find all 100MB files

find / -size 100M

2.2 Find files which is between 10MB and 100MB

find / -size +50M -size -100M

2.3 Find and delete files which is greater than 500MB in size

find / -size +500M -exec rm -rf {} \;

2.4 Find specific files and delete them

Find all mp3 files which are greater than 5MB, delete them

find / -type f -name *.mp3 -size +5M -exec rm {} \;

3 Find files by their Owner/Group

3.1 Find files by their owner

Find all of the “1.txt” file which belongs to Bob

find / -user Bob -name 1.txt

3.2 Find all files belongs to the user

Find all files belongs to Bob under “/test” folder

find /test -user Bob

3.3 Find files based on their group

Find all files under “/test” which belongs to the group “testgroup”

find /test -group testgroup

3.4 Find all “.txt” files under “/test” which belongs to Bob

find /test -user Bob -iname "*.txt"

4 Find files and folders by date and time

4.1 Find files

4.1 Find files which their data was last modified n*24 hours ago. (3 days in this example)

find / -mtime 3

4.2 Find files being accessed in 3 days

find / -atime 3

4.3 Find files that being modified between last 3-10 days

find / -mtime +3 -time -10

4.4 Find files which their status was last changed 5 minutes ago

find / -cmin -5

4.5 Find files which their data was last modified 5 minutes ago

find / -mmin -5

4.6 Find files which are being access within 5 minutes

find / -amin -5

5 Find files by their privileges

5.1 Find files with “777” permission

find -type f -perm 0777 -print

5.2 Find files without “777” permission

find / -type f ! -perm 777

5.3 Find files with “644” permission (SGID)

find / -perm 2644

5.4 Find files with “551” Sticky Bit permission

find / -perm 1551

5.5 Find SUID files

find / -perm /u=s

5.6 Find read only permission files

find / -perm u=r

5.7 Find executable files

find / -perm /a=x

5.8 Find all files with “777” permission and chmod to 644

find /test -type f -perm 0777 -print -exec chmod 644 {} \;

5.9 Find all folders with “777” permission and chmod to 755

find / -type d -perm 777 -print -exec chmod 755 {} \;

5.10 Find and delete single file (1.txt in this case)

find -type f -name "1.txt" -exec rm -f {} \;

5.11 Find and delete multiple files with same extension (txt files in this case)

find -type f -name "*.txt" -exec rm -f {} \;

5.12 Find all empty files

find / -type f -empty

5.13 Find all empty folders

find / -type d -empty

5.14 Find all hidden files under “/tmp” folder

find /tmp -type f -name ".*"

Leave a Reply

Your email address will not be published. Required fields are marked *