ZIP doesn't archive hidden file under the HOME
Here is the directory structure of the folder I am trying to archive:
DIR STRUCTURE
HOME
HOME/.abc
HOME/FIRST
HOME/FIRST/.def
I am using simlpe $PATCH/zip -r -l -x "bac*" abc.zip HOME/*
One interesting thing I obseverved was it is skipping hidden folder directly under HOME and it zips the one开发者_Python百科 under FIRST. What am I missing here? Is it any side effect of the options I am chosing ? Please help thanks in advance.
zip archiveName -r .* -x "../*"
Trick si using .* and excluding ../*
*
is not interpreted by the zip utility, but rather expanded by the shell. Before the zip utility is executed, *
is replaced by a space separated list of all the non-hidden files or directories.
You can prove this by replacing $PATCH/zip
with echo
, which will show the arguments that are actually passed to the program, after shell mangling.
If you set the environment variable GLOBIGNORE
to .:..
, not only will bash disable the matching of .
and ..
, it has the nice effect of also automatically enabling 'dotglob', which matches the other hidden files without the need for .*
, so you can just use *
for everything.
For example, this should solve your problem:
GLOBIGNORE=.:..; $PATCH/zip -r -l -x "bac*" abc.zip HOME/*; unset GLOBIGNORE
Note that you cannot do this the short way, or in one command:
GLOBIGNORE=.:.. $PATCH/zip -r -l -x "bac*" abc.zip HOME/*
It seems that bash doesn't notice this until the next command.
精彩评论