I wanted to put together some find command examples because I tend to forget this useful Linux command often. It is very important for Linux/MacOS administrators or DevOps to master the find command.
While having my favorite coffee varietal Caturra the other day I decided to put together this brief find command examples:
Syntax is simple: find [where to start search from] [what to find] [-any options] [what to find at last]
1. Search a file with specific name.
$ find ./MyDirectory -name afile.txt
This find command will search for afile.txt in MyDirectory directory and display the results such as:
2. Find command examples to search for file patterns
For example if you want to find all files with a .txt extension inside the MyDirectory
find ./MyDirectory -name *.txt
If there are any .txt files you should get an output similar to:
3. Search for empty files and directories.
This is a cool one. Let’s say you want to find those empty directories or file by just running a simple find command:
find ./MyDirectory -empty
If there are any empty files or directories you will get a list:
4. Find command examples to search for files with specific permissions
Another useful find command.
$ find ./MyDirectory -perm 644
The above find command example will search for files with permissions set to 644 under the /MyDirectory directory and will display a list.
Check the man pages for more useful options of the find command in Linux or MacOS. Contact me if you have any questions. Also grab one of my T-Shirt or coffee mugs designs on my shop. I design them myselft. Thanks!