How do I delete folders using regex from Linux terminal

c 2 picture c 2 · Aug 12, 2012 · Viewed 20.5k times · Source

Say I have folders:

img1/
img2/

How do I delete those folders using regex from Linux terminal, that matches everything starts with img?

Answer

Diego Torres Milano picture Diego Torres Milano · Aug 12, 2012

Use find to filter directories

$ find . -type d -name "img*" -exec rm -rf {} \;

As it was mentioned in a comments this is using shell globs not regexs. If you want regex

$ find . -type d -regex "\./img.*" -exec rm -rf {} \;