How to use find command in Linux
The Linux Find Command is one of the most valuable and convenient command in Linux systems. It can search the whole filesystem to find files and directory as indicated by the search criteria you determine. The find command is accessible on most Linux systems by default so you don’t need to install any packages. The find command is a key one to learn, on the off chance that you need to get super productive with the command line on Linux.
See Also:
Finding Files by Name
If you want to find the file whose name is technical.txt in a current working directory, run following command:
# find ./ -name technical.txt
./technical.txt
If you want to find all the file who name is starting with technical, run following command:
# find ./ -name technical*
./technical.txt ./technical1.txt ./technical2.txt ./technical3.txt
Find all the files whose name is support.txt and contains both capital and small letters in /tmp directory.
# find /home -iname support.txt
./support.txt ./Support.txt
If you want to find all files and want to ignore file with a specific pattern, you can invert the search with “-not” or “!”. If you use “!”, you must escape the character so that bash does not try to interpret it before find can act:
# find -not -name technical.txt
Or
# find \! -name technical.txt
./support.txt ./technical1.txt ./technical2.txt ./technical3.txt
Find all the files under /tmp directory with name technical.txt.
# find /tmp -name tecmint.txt
/tmp/technical.txt
If you want to find all the file under /tmp directory who name is starting with technical, run following command:
# find /tmp -name technical*
./technical.txt ./technical1.txt ./technical2.txt ./technical3.txt
Search files into multiple directories.
# find /opt /usr /var /etc -name support.txt -type f
Find files with different extensions or patterns.
# find . -type f \( -name "*sh" -o -name "*xml" -o -name "*html" \)
Finding by Type
You can specify the type of files you want to find with the “-type” parameter. Use following command:
# find / -type f technical.txt
/root/tmp/technical.txt
Some of the most regular descriptors that you can use to indicate the kind of document are here:
We can search all the files that end with “.php”.
# find /home -type f -name "*.php"
/home/index.php /home/test.php /home/technical/techoism.php ....
To find all hidden files, use below command.
# find /home -type f -name ".*"
Enjoy it!