0% found this document useful (0 votes)
3 views

Find docs

The document provides various examples of using the 'find' command in a Unix/Linux environment to locate files and directories based on different criteria such as name, type, permissions, ownership, and modification time. It includes commands for finding files with specific names, searching for empty files, and identifying files with certain permissions like SUID and SGID. Additionally, it covers how to search for files based on their size and access times.

Uploaded by

suman.mitra2025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Find docs

The document provides various examples of using the 'find' command in a Unix/Linux environment to locate files and directories based on different criteria such as name, type, permissions, ownership, and modification time. It includes commands for finding files with specific names, searching for empty files, and identifying files with certain permissions like SUID and SGID. Additionally, it covers how to search for files based on their size and access times.

Uploaded by

suman.mitra2025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1

EXAMPLES
EXAMPLE-1:
To find all the files whose name is xyz.txt in a current working directory.:
# find . -name names.txt

output:
# ls
names.txt test.txt xyz.txt
# find . -name names.txt
./names.txt

EXAMPLE-2:
To find all the files under /tmp directory with name xyz.txt.
# find /tmp -name names.txt

output:
# ls /tmp/
names.txt test.txt xyz.txt

# find /tmp/ -name names.txt


/tmp/names.txt

EXAMPLE-3:
To find all the files whose name is names.txt and contains both capital
and small letters in /tmp directory.:
# find /tmp -iname names.txt

output:
# ls /tmp/
names.txt Names.txt test.txt xyz.txt

# find /tmp/ -iname names.txt


/tmp/Names.txt
/tmp/names.txt

EXAMPLE-4:
To find all directories whose name is test in / directory.
# find / -type d -name test
output:
/usr/src/linux-headers-3.19.0-25/lib/raid6/test

EXAMPLE-5:
2

To find all php files whose name is test.py in / directory.


# find / -type f -name test.py
output:
/usr/lib/python2.7/dist-packages/chardet/test.py
EXAMPLE-6:
To find all py files in / directory.
# find / -type f -name "*.py"

EXAMPLE-7:
To find all the files whose permissions are 777.
# find . -type f -perm 0777 -print

output:
# ls -l /tmp/
total 4
-rwxrwxrwx 1 root root 0 Dec 29 15:06 names.txt
-rw-r--r-- 1 root root 0 Dec 29 15:13 Names.txt
-rwxrwxrwx 1 ubuntu ubuntu 13 Dec 28 01:12 test.txt
-rw-r--r-- 1 root root 0 Dec 29 15:05 xyz.txt

# find /tmp -type f -perm 0777 -print


/tmp/names.txt

EXAMPLE-8:
To find all files that belongs to user ubuntu under /tmp directory.
# find /tmp -user ubuntu
output:
# ls -l /tmp
total 4
-rw-r--r-- 1 root root 0 Dec 29 15:13 Names.txt
-r--r--r-- 1 ubuntu ubuntu 13 Dec 28 01:12 test.txt
-rw-r--r-- 1 root root 0 Dec 29 15:05 xyz.txt

# find /tmp -user ubuntu


/tmp/test.txt

EXAMPLE-9:
To find all files that belongs to group ubuntu under /tmp directory.
# find /tmp -group ubuntu
output:
# ls -l /tmp
3

total 4
-rw-r--r-- 1 root root 0 Dec 29 15:13 Names.txt
-r--r--r-- 1 ubuntu ubuntu 13 Dec 28 01:12 test.txt
-rw-r--r-- 1 root root 0 Dec 29 15:05 xyz.txt

# find /tmp -group ubuntu


/tmp/test.txt

EXAMPLE-10:
* To find a single file called names.txt and remove it.
# find . -type f -name "names.txt" -exec rm -f {} \;

output:
# ls /tmp
names.txt Names.txt test.txt xyz.txt

# find /tmp -type f -name "names.txt" -exec rm -f {} \;

# ls /tmp
Names.txt test.txt xyz.txt

4. Search for empty files and directories.


$ find ./GFG -empty
6. Search text within multiple files.
$ find ./ -type f -name "*.txt" -exec grep 'Geek' {} \;

Search for files that were modified in the last 7 days below the
current directory
$ find ./ -mtime -7

Find newer files


The '-newer' parameter helps in searching the files which are newer than
the mentioned file. Consider the below command:

1. find . -newer msg.txt

8. Find Files Without 777 Permissions


Find all the files without permission 777.

# find / -type f ! -perm 777


4

. Find SGID Files with 644 Permissions


Find all the SGID bit files whose permissions are set to 644.

# find / -perm 2644

Find all the Sticky Bit set files whose permission is 551.

# find / -perm 1551

11. Find SUID Files


Find all SUID set files.

# find / -perm /u=s

12. Find SGID Files


Find all SGID set files.

# find / -perm /g=s

[ You might also like: How to Find Files With SUID and SGID Permissions in
Linux ]
13. Find Read-Only Files
Find all Read-Only files.

# find / -perm /u=r

14. Find Executable Files


Find all Executable files.

# find / -perm /a=x

27. Find Last 50 Days Accessed Files


To find all the files which are accessed 50 days back.

# find / -atime 50
5

. Find Last 50-100 Days Modified Files


To find all the files which are modified more than 50 days back and less
than 100 days.

# find / -mtime +50 –mtime -100

To find all the files which are changed in the last 1 hour.

# find / -cmin -60

30. Find Modified Files in Last 1 Hour


To find all the files which are modified in the last 1 hour.

# find / -mmin -60

31. Find Accessed Files in Last 1 Hour


To find all the files which are accessed in the last 1 hour.

# find / -amin -60

32. Find 50MB Files


To find all 50MB files, use.

# find / -size 50M

33. Find Size between 50MB – 100MB


To find all the files which are greater than 50MB and less than 100MB.

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

You might also like