0

I have 1000s of directories inside a main directory and I would like to be able to find a certain type of file from inside the 1000s of directories, list the files by size and then delete the largest files with out deleting the directories they are in.

I suppose the delete command might be a follow on from the find command and not executed all in one.

I am using Ubuntu.

1
  • how do you want to decide what files to delete, after you have seen the list?
    – tlund
    Apr 11, 2016 at 13:08

1 Answer 1

1

To find and list files without deleting them, open the terminal and type:

find . -type f -size +1M -name \*.ext

To find, list and delete files, use the command:

find . -type f -size +1M -name \*.ext -delete

where:

  • -size +1M finds files larger than 1 Megabyte (unit of 1048576 bytes)

  • \*.ext -delete deletes all files that have the extension .ext

  • -delete delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option, which processes each directory's contents before the directory itself..

1
  • Works great @karel Apr 11, 2016 at 13:26

You must log in to answer this question.

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