Usage of Find Command with Examples
Hi All,
Find is a very important command for system administrator to do their daily works. Most of the Linux distribution’s comes prepacked with the “find” command tool to search for files. Now lets see how to use find command with examples.
1. Find Files Using Name in Current Directory
Find all the files whose name is test.txt in a current working directory.
# find . -name test.txt ./test.txt
2. Find Files Under Home Directory
Find all the files under /home directory with name test.txt.
# find /home -name test.txt /home/test.txt
3. Find Files Using Name and Ignoring Case
Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory.
# find /home -iname test.txt ./test.txt ./test..txt
4. Find Directories Using Name
Find all directories whose name is test in / directory.
# find / -type d -name test /test
5. Find HTML Files Using Name
Find all php files whose name is test.html in a current working directory.
# find . -type f -name test.html ./test.html
6. Find all PHP Files in Directory
Find all html files in a directory.
# find . -type f -name "*.html" ./test.html ./login.html ./index.html
7. Find Files With 644 Permissions
Find all the files whose permissions are 644.
# find . -type f -perm 0644
8. Find Files Without 644 Permissions
Find all the files without permission 644.
# find / -type f ! -perm 644
9. Find all Empty Files
To find all empty files under certain path.
# find /tmp -type f -empty
10. Find all Empty Directories
To file all empty directories under certain path.
# find /tmp -type d -empty
11.Find Specific Files and Delete
Find all .mp4 files with more than 50MB and delete them using one single command.
# find / -type f -name *.mp4 -size +50M -exec rm {} \;
Thanks for reading this tutorial, Hope you have enjoyed it 🙂