Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Question 1 : In many .zip archive files I would like to delete directories anwsering to a name pattern. In a "normal" directory I used :

find . -type d -name "pattern" -mtime +30| xargs rm -r

Is it possible to find/delete these directories without having to unzip the .zip files?

If I do have to unzip I have to zip them again after deleting those files, which I would like to avoid.

I saw a few topics which advised to mount .zip files to use shell commands. Could it work for me too ? (I'm quite new to the Unix World).

Question 2 : i did like Mark said and put everything in a loop. It works fine but without asking for anything i get in the terminal for each deleted file/folder a line : "deleting: blabla.txt". How is it possible to get these lines in a log file ? Just adding >> ${logFile} after the command line would be enough ?

share|improve this question
A zip archive is a compressed file. You can update them with a command like jar which follows a syntax similar to tar. You might also use a loopback filesystem, or a GUI archive manager. – Elliott Frisch Feb 3 '14 at 16:37
Will zip -d archivename.zip '*/pattern/*' do what you want? – Mark Plotnick Feb 3 '14 at 16:55
To answer the new question: yes, adding >> ${logFile} after the zip command will append all the "deleting:" messages to that file. – Mark Plotnick Feb 5 '14 at 11:41

As @MarkPlotnick pointed out, you can use glob patterns. From man zip:

zip -d foo foo/tom/junk foo/harry/\* \*.o

will remove the entry foo/tom/junk, all of the files that start with foo/harry/, and all of the files that end with .o (in any path).

share|improve this answer
Hello, thanks for your answers, – Jean-Samuel Feb 4 '14 at 7:43
Hello, thanks a lot Mark, your solution works fine for a single test file. Now I'll try to do this in a loop. If i don't manage to do this on my own, I may come back to you. Have a nice day, Jean-Samuel – Jean-Samuel Feb 4 '14 at 8:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.