I have a folder that is full of files and subdirectories. A lot of that is trash, but some of it I want to keep.

Therefore, I want to delete all files of a few certain types (which are the files I don't want or need) and then delete all empty directories and subdirectories.

These commands do not work at all - they do nothing:

find . -name "*.jpg" -type f -delete
find . -type d -empty -delete

I'd really appreciate any help at all!


Try with -mindepth option to delete all the files ended with .jpg which was present inside subfolders,

find . -mindepth 1 -name "*.jpg" -type f -delete

To delete empty directories,

find . -empty -type d -delete
  • Any idea how to find and delete files WITHOUT any file extensions? There are quite a few in that directory... – etsnyman May 15 '14 at 7:55
  • using file names, you can delete files by specifying it's name. – Avinash Raj May 15 '14 at 7:56
  • There are a whole lot of files without extensions which are trash. I don't want to look through about 500 subdirectories to delete each one - I just want to delete them all... – etsnyman May 15 '14 at 8:02
  • I tried find . -mindepth 1 ! -iname "*.*" -type f -delete but it did nothing... – etsnyman May 15 '14 at 8:04
  • do you want to delete all the files which isn't has a . in their filenames? – Avinash Raj May 15 '14 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.