10 Find Commands to improve your file search in Linux [Basics]

Updated on September 3, 2017

In continuation to our tutorials on Linux basics, today I’ll show you 10 Find commands that will improve file search in Linux. Ok! Here we go,

1. How to find or locate a file in current directory?

find . -name filename.txt

Note: dot(.) after find denotes current directory

2. How to find or locate a file under ‘/’?

find / -name filename.txt

Note: slash (/) after find searches file under ‘/’ partition. For instance, to a search a file under /home directory, below is the command,

find /home -name filename.txt

3. How to search a directory using find?

find . -type d -name directory_name

4. How to find a file by ignoring case?

For example, the below command list lower case and upper case files.

$ find . -iname project.txt
./project.txt
./PROJECT.TXT
./Project.txt

 5. How to find a file and remove it using Find?

find . -name project.txt -exec rm -f {} \;

6. How to find a file and change its permission?

Here’s the actual permission set for a file,

$ ls -l secret.txt
-r-------- 1 peter author 0 Oct 12 14:20 secret.txt

We’ll try to find a file and change its permission to ‘755’

find . -name secret.txt -exec chmod 755 {} \;

Checkout the file permission now

$ ls -l secret.txt
-rwxr-xr-x 1 peter author0 Oct 12 14:20 secret.txt

7. How to find all txt files and change its permission?

find / -name *.txt -exec chmod 755 {} \;

8. How to find all empty files?

find /tmp -type f -empty

9. How to find all empty directories?

find /tmp -type d -empty

10. How to find all files based on group?

find /home -group developer

Was this article helpful?

Related Articles

Leave a Comment