How to find all files of a specific type recursively in Unix-based operating systems (Linux and Mac)
Nick Scialli • September 28, 2021 • 🚀 1 minute read
find command line utility is a powerful tool for searching your filesystem in Linux and MacOS. A common use case is trying to find all files with a certain extension.
In the following example, we use the
find command to find all
txt files within the current directory, recursively.
find . -type f -name "*.txt"
Let’s break down how this works:
- The first argument we provide the
., which tells
findto start from the current directory. if we wanted to start in a subdirectory called
my_directory, our command would be
find my_directory -type f -name "*.txt".
- Next up, we have the
typeflag. As you might intuit, the
fis for files. You can also use
- Finally, we have the
nameflag. Since we’re looking for all
.txtfiles, we use a
*wildcard to indicate that we don’t really care what the file name is so long as it ends in
Note that we don’t specify anything for searching recursively—this will be done automatically!
If you'd like to support this blog by buying me a coffee I'd really appreciate it!
Nick Scialli is a software engineer at the U.S. Digital Service.