Finding files with different extensions

In a previous blog post I wrote about using the find command to search a file system. I recently had need to locate a number of ebook files with different extensions in my personal library, and wanted a quick way to enumerate them all with a single script. On BSD and OSX systems, the find command processes regular expressions differently than on Linux systems, so using it wouldn’t work for me as I wanted my script to work on both OSX and Linux. Fortunately Alvin Alexander’s blog post “Using the Linux ‘find’ command with multiple filename patterns” pointed me in the right direction. The -name filter can be chained to create the serarch pattern I needed:

find . -type f \( -name "*pdf" -o -name "*epub" -o -name "*mobi" \) > index.txt