ZIP 不会将隐藏文件归档到 HOME 下
这是我尝试归档的文件夹的目录结构:
DIR STRUCTURE
HOME
HOME/.abc
HOME/FIRST
HOME/FIRST/.def
我正在使用 simlpe $PATCH/zip -r -l -x "bac*" abc.zip HOME/*
一件有趣的事情我观察到它直接跳过 HOME 下的隐藏文件夹,并将 FIRST 下的文件夹压缩。我在这里缺少什么?我选择的选项有副作用吗?请帮忙提前致谢。
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 under FIRST. What am I missing here? Is it any side effect of the options I am chosing ? Please help thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 .* 并排除 ../* 欺骗 si
Trick si using .* and excluding ../*
*
不由 zip 实用程序解释,而是由 shell 扩展。在执行 zip 实用程序之前,*
会替换为所有非隐藏文件或目录的空格分隔列表。您可以通过将
$PATCH/zip
替换为echo
来证明这一点,这将显示在 shell 修改之后实际传递给程序的参数。如果将环境变量
GLOBIGNORE
设置为.:..
,bash 不仅会禁用.
和..< 的匹配/code>,它还有一个很好的效果,就是自动启用“dotglob”,它可以匹配其他隐藏文件,而不需要
.*
,所以你可以只使用*
对于一切。例如,这应该可以解决您的问题:
请注意,您不能以简单的方式或在一个命令中执行此操作:
bash 似乎直到下一个命令才注意到这一点。
*
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
withecho
, 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:
Note that you cannot do this the short way, or in one command:
It seems that bash doesn't notice this until the next command.