I have a zip archive (created automatically in a script with -j -r flags) and I would like to remove a single file from it. I tried as documented.
zip -d "picture_43_9.jpg" gallery.zipbut I get this error:
zip warning: picture_43_9.jpg not found or empty
zip error: Nothing to do! (picture_43_9.jpg) Anyway, there is such a file inside the archive and it is not empty:
unzip -l .../gallery.zip | grep -i 43_9.jpg
1477092 2013-05-22 14:23 picture_43_9.jpg Any ideas on what I'm doing wrong?
1 Answer
You have the arguments swapped. Try this:
zip -d gallery.zip "picture_43_9.jpg" From the zip(1) man page:
3
-d
--delete
Remove (delete) entries from a zip archive. For example:
zip -d foo foo/tom/junk foo/harry/\* \*.owill remove the entry
foo/tom/junk, all of the files that start withfoo/harry/, and all of the files that end with.o(in any path). Note that shell pathname expansion has been inhibited with backslashes, so that zip can see the asterisks, enabling zip to match on the contents of the zip archive instead of the contents of the current directory. (The backslashes are not used on MSDOS-based platforms.) Can also use quotes to escape the asterisks as in
zip -d foo foo/tom/junk "foo/harry/*" "*.o"Not escaping the asterisks on a system where the shell expands wildcards could result in the asterisks being converted to a list of files in the current directory and that list used to delete entries from the archive.
Under MSDOS, -d is case sensitive when it matches names in the zip archive. This requires that file names be entered in upper case if they were zipped by PKZIP on an MSDOS system. (We considered making this case insensitive on systems where paths were case insensitive, but it is possible the archive came from a system where case does matter and the archive could include both
Barandbaras separate files in the archive.) But see the new option -ic to ignore case in the archive.