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.

  • how do you want to decide what files to delete, after you have seen the list? – tlund Apr 11 '16 at 13:08
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..

  • Works great @karel – user2786484 Apr 11 '16 at 13:26

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.