1

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!

1 Answer 1

2

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
8
  • Any idea how to find and delete files WITHOUT any file extensions? There are quite a few in that directory...
    – etsnyman
    May 15, 2014 at 7:55
  • using file names, you can delete files by specifying it's name. May 15, 2014 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, 2014 at 8:02
  • I tried find . -mindepth 1 ! -iname "*.*" -type f -delete but it did nothing...
    – etsnyman
    May 15, 2014 at 8:04
  • do you want to delete all the files which isn't has a . in their filenames? May 15, 2014 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .