I want to zip a folder recursively, but exclude certain directories (temp/.hidden
in the example below). I want the zip file to have a top level folder which would be temp
in the example below, hence my working directory is temp
.
mkdir -p temp/subdir
touch temp/subdir/keepthisfile.txt
touch temp/excludethisfile.txt
mkdir temp/.hidden
touch temp/.hidden/exclude.txt
cd temp/
Code I have to achieve what I want is either
zip -r temp.zip ../temp/ -x ../temp/excludethisfile.txt ../temp/.hidden/* ../temp/.hidden/
Or more concisely (syntax gleaned from elsewhere online)
zip -r temp.zip ../temp/ -x ../temp/excludethisfile.txt ../temp/*.hidden*
I can see why this would work, but I can't see why the code below doesn't do the same thing (i.e. why do I need ../temp/*.hidden*
rather than just ../temp/.hidden*
?)
zip -r temp.zip ../temp/ -x ../temp/excludethisfile.txt ../temp/.hidden*