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 Caturra variety coffee 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.txtThis find command will search for afile.txt in MyDirectory directory and display the results such as:
./MyDirectory/path/to/afile.txtIf you like to search in the current directory just use a ‘ . ‘ instead of the directory name:
find . -name bfile.txt2. 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 *.txtIf there are any .txt files you should get an output similar to:
./MyDirectory/some/path/afile.txt
./MyDirectory/some/path/bfile.txt3. 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 -emptyIf there are any empty files or directories you will get a list:
./MyDirectory/oneFile
./MyDirectory/twoFile4. Find command examples to search for files with specific permissions
Another useful find command.
$ find ./MyDirectory -perm 644The above find command example will search for files with permissions set to 644 under the /MyDirectory directory and will display a list.
Search for directories
You can also specify what you want to search. For example if you want to search for directories only:
find . -type d -name directoryNameCheck 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!

