Reputation: 61
I would like to zip a directory and I am able to do so with
zip -r zip_file_name directory
however, I would like exclude a single file in the directory from the zip file. How would I go about doing this?
Upvotes: 4
Views: 162
Reputation: 75
Enter the directory which you want to zip. Then:
find . -not -name "file_to_exclude" | zip zip_file_name -@
The command above will create zip_file_name.zip in directory itself.
To create zip at a particular path, Enter the directory which you want to zip. Then:
find . -not -name "file_to_exclude" | zip ~/ParticularPath/zip_file_name -@
From linux man page for zip:
-@ file lists. If a file list is specified as -@ [Not on MacOS], zip takes the list of input files from standard input instead of from the command line. For example,
zip -@ foo
will store the files listed one per line on stdin in foo.zip.
Under Unix, this option can be used to powerful effect in conjunction with the find command. For example, to archive all the C source files in the current directory and its subdirectories:
find . -name "*.[ch]" -print | zip source -@
Upvotes: 1