0

I am trying to delete all zip files from a folder /mnt/drive1/temp and its subfolders recursivley.

I am aware that an incorrect command here could have disastrous consequences so wanted to check I had the right format, so far I have...

find /mnt/drive/temp -type f -name '*.zip' -delete

Will this command achieve what I want?

  • use -iname to delete all ZIP files – alecxs Aug 30 at 13:43
2

If you omit the -delete option, find will print out a list of all files that match the test conditions you have specified. This is great way to check that you have caught the right files, especially before you delete them. Once you're sure that the files are the right ones, append the -delete option and run the command.


Syntactically, your command appears correct, but there may be a typo. You have find followed by the path ('/mnt/drive/temp'). You have also mentioned '/mnt/drive1/temp' in the question, which is a different path. This is the possible typo I am referring.

Followed by the path, you have a series of tests. -type f will find regular files, and -name '*.zip' will find files that end with the .zip extension. The single quotes prevent the shell from expanding the '*' character, which is the correct approach.

As stated above, first do a 'dry run' without the -delete option. Then, review the output and confirm that the files are correct. Once you are satisfied, proceed to delete the files.

| improve this answer | |

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.