5

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 ?

3
  • 1
    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. Commented Feb 3, 2014 at 16:37
  • Will zip -d archivename.zip '*/pattern/*' do what you want? Commented Feb 3, 2014 at 16:55
  • To answer the new question: yes, adding >> ${logFile} after the zip command will append all the "deleting:" messages to that file. Commented Feb 5, 2014 at 11:41

1 Answer 1

6

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).

1
  • 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 Commented Feb 4, 2014 at 8:06

You must log in to answer this question.

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