find file by name in linux

In this post, we will see how to find file by name in linux.

You can use "find" command to find file by name.

Find file in the current directory

Here is a simple command to find file "letters.txt" in current directory.

find . -name letters.txt

$ find . -name letters.txt

./txtFiles/letters.txt

If you want to find a file by name that contains both upper case and lower case then run:

find . -iname letters.txt

$ find . -iname letters.txt

./LETTERS.txt
./txtFiles/letters.txt

Find file in the specific directory

1. Find file “letters.txt” in /home directory.

find /home -name letters.txt

2. Find file “letters.txt” in multiple directories /home and /opt.

find /home /opt -name letters.txt

3. Find file “letters.txt” in directory /home and remove it

find /home -type f -name letters.txt -exec rm -f {}

4. Find all files in /opt directory with txt extension

find /opt -name “*.txt”

5. Find all hidden files in /home directory and remove it

find /home -name “.*”

6. Find all empty files in directory /home

find /home -type f -empty

That’s all about how to find file by name in linux

Was this post helpful?

Leave a Reply

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