Find docs
Find docs
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
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
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
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
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
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
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
# ls /tmp
Names.txt test.txt xyz.txt
Search for files that were modified in the last 7 days below the
current directory
$ find ./ -mtime -7
Find all the Sticky Bit set files whose permission is 551.
[ 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 / -atime 50
5
To find all the files which are changed in the last 1 hour.