1

Currently I am doing the following command to delete a file inside a zip file on my server:

zip -d file.zip .exe

But I have so many zip file that needs to delete all files with an .exe file extension.

All the zip files is stored under "downloads" folder.

Is it possible to delete files from multiple zip file?

1 Answer 1

1

Use find and xargs:

find -iname '*.zip' -print0|xargs -0 -i zip -d '{}' .exe

or to specify the directory explicitly:

find /downloads -iname '*.zip' -print0|xargs -0 -i zip -d '{}' .exe

EDIT: To exclude a specific directory, /downloads/admin:

find /downloads -path /downloads/admin -prune -o -iname '*.zip' -print0|xargs -0 -i zip -d '{}' .exe
7
  • 1
    Even simpler, you could use -exec instead of find | xargs
    – slhck
    Dec 8, 2013 at 13:35
  • Hi, Sorry I forgot that inside the downloads folder, there are several folders that is created based on who uploaded that .zip file. So an example is /downloads/user1, /downloads/user2, /downloads/user3, etc. Is the first or second code you gave above still valid?
    – jaYPabs
    Dec 8, 2013 at 13:38
  • @user176890 yes, it searches in all subdirectories recursively, to unlimited depth. Dec 8, 2013 at 13:40
  • Thank you. I tried and it works. I have one more question which I forgot to ask. Is it possible to exclude a folder? Example I want to exclude the folder called "admin" inside downloads folder. Because I can assure that admin folder don't have .exe file that is infected with a virus because it's my account.
    – jaYPabs
    Dec 8, 2013 at 13:44
  • @user176890 I edited my answer to add that. Dec 8, 2013 at 13:47

You must log in to answer this question.

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