Notes

Select files with multiple different file extensions

Edit on GitHub

Commands
2 minutes

tl;dr

1# *.{a,b,c,d}
2ls -alh *.{md,json,html,xml} # list all files ending in given extensions
3find . -type f *.{html,xml,php} # find all files ending in given extensions
4find . -type f *.{html,xml,php} -exec rm -rf {} \; # find and delete all files ending in given extensions

Find/List files

1find . -type f *.{html,xml,php}

will find all (*) files (-type f) in the current directory (.) ending in .html, .xml or .php. You can add as many comma seperated values as you want, no spaces in between.

One case scenario when this has been useful is when i had to delete hacked files from a WordPress wp-content/uploads directory. It contained files with executable PHP code, spam pages ending in .html, XML scripts and the like left behind by the hacker. (Usually, the WordPress uploads directory only contains images or uploaded files - PDFs and such, but not scripts. Some plugins may use the Uploads directory, but that’s not our concern right now, moving on..).

1ls -alh *.{md,json,html,xml}
1-rw-r--r--  1 aamnah  staff   247B Feb 23 09:18 README.md
2-rw-r--r--  1 aamnah  staff   1.2K Feb 24 15:19 about.md
3-rw-r--r--  1 aamnah  staff   1.3K Feb 23 09:21 feed.xml
4-rw-------  1 aamnah  staff   908B Mar 13 20:55 index.html
5-rw-r--r--@ 1 aamnah  staff   6.5K Mar 22 08:41 progress.md
6-rw-r--r--  1 aamnah  staff   202B Mar 13 14:14 quotes.md
7-rw-r--r--  1 aamnah  staff   547B Mar 13 15:05 resources.md
8-rw-r--r--  1 aamnah  staff   308B Mar  2 10:46 search.json

find works recursively while ls will only list files in the current directory (and not it’s sub-dirs)

Delete files

1find . -type f *.{html,xml,php} -exec rm -rf {} \;