3

Here is my current command:

zip -r compressed_filename.zip path/foldername

But there is lots of images into a folder named img in there path/foldername. So I want to make a file zip of path/foldername directory except img folder which is into it.

How can I do that?

muru
  • 197,895
  • 55
  • 485
  • 740
stack
  • 581
  • Always it is good idea to have a look on manpage of the command you want to use. Run man zip and search for exclude by pressing / and n for searching forward, you will be taking to the right place. – Mostafa Ahangarha Feb 28 '17 at 12:31

1 Answers1

5

The zip command has an --exclude (or -x) flag to exclude some files:

zip -r --exclude 'img/' compressed_filename.zip path/foldername

Adjust the paths if necessary.


You can also use the find command to list all the files to be included and pass them to the zip command.

find path/foldername -name 'img' -prune -o -exec zip compressed_filename.zip {} +

This will search the path/foldername for all files (and folders). If it finds img, it stops processing it (-prune). All other (-o) found items will be (together, because of + at the end) passed to the zip invocation.

Melebius
  • 11,431
  • 9
  • 52
  • 78