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.
Related videos on Youtube
Author by
stack
Updated on September 18, 2022Comments
-
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 therepath/foldername
. So I want to make a file zip ofpath/foldername
directory exceptimg
folder which is into it.How can I do that?
-
Mostafa Ahangarha over 7 yearsAlways 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/
andn
for searching forward, you will be taking to the right place.
-