How can I make a zip file of a directory except specific folder of it?

5,117

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.

Share:
5,117

Related videos on Youtube

stack
Author by

stack

Updated on September 18, 2022

Comments

  • stack
    stack almost 2 years

    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?

    • Mostafa Ahangarha
      Mostafa Ahangarha over 7 years
      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.