用 tar 归档隐藏目录
目录 mydir
上的 tar
将归档隐藏文件和隐藏子目录,但使用 mydir
中的 tar >* 通配符不会。这是已知的不一致或错误吗?
编辑:附加信息。使用 *
通配符从 mydir 中的 tar
不会“看到”也不会归档隐藏文件和隐藏子目录直接目录。但是,在 mydir
的非隐藏子目录中,隐藏文件和隐藏子目录将被归档。换句话说,隐藏的对象将被存档在目录树的更深处。
tar
on a directory mydir
will archive hidden files and hidden subdirectories, but tar from within mydir
with a *
wildcard will not. Is this a known inconsistency or bug?
Edit: Additional information. tar
from within mydir
with a *
wildcard will not "see" nor archive hidden files and hidden subdirectories in the immediate directory. However, in the non-hidden subdirectories of mydir
hidden files and hidden subdirectories will be archived. In other words, deeper in the directory tree the hidden objects will be archived.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用通配符将不起作用。你必须指定 . (当前目录)如果您指的是包括隐藏文件的完整目录。你可以做
With wildcard it will not work. You have to specify . (current directory) if you mean full directory including hidden files. You can do
答案是
*
通配符由 shell 处理,它只是不会扩展到以点开头的内容。另一个通配符?
也不会扩展到以点开头的内容。感谢 Keith 指出是 shell 进行了扩展,因此它与tar
无关。如果您使用
shopt -s dotglob
,那么扩展将包括.filename
之类的内容。感谢安迪。使用shopt -u dotglob 将其关闭。
切换
dotglob
选项不会更改ls
本身。相反,它只是改变扩展行为,如ls *
所示。编辑:我的建议在下面的评论中。
The answer is that the
*
wildcard is handled by the shell and it just does not expand to things that start with a dot. The other wildcard?
also does not expand to things that start with a dot. Thanks to Keith for pointing out it is the shell that does the expansion and so it has nothing to do withtar
.If you use
shopt -s dotglob
then expansion will include things like.filename
. Thanks to Andy.Use
shopt -u dotglob
to turn it off.Switching the
dotglob
option does not changels
itself. Rather it just changes expansion behaviour as exhibited in something likels *
.Edit: My recommendations are in a comment below.
您可以使用:
但是,这仅适用于名称 > 的隐藏文件。 2(防止出现“.”和“..”)
You can use:
But, this works only for hidden files with names > 2 (to prevent '.' and '..')
您可以使用以下方法压缩当前目录中的所有文件/文件夹(包括 .hidden):
最后一个参数是要压缩的文件夹。如果您传递
ls -A -1
,则您将传递当前目录中除.
和..
之外的所有文件夹。对于子目录,.hidden 文件默认已包含在压缩中。
You can compress all the files / folders in your current directory (including .hidden) by using:
The last argument are the folders you want to compress. If you pass it
ls -A -1
, you are passing it all folders in your current directory but.
and..
.When it comes to subdirectories, .hidden files are already included in the compression by default.
shell 扩展了通配符,因此 tar 甚至看不到它。如果您想这样做,则必须显式添加它们。 (<代码>.*)。然而,最常见的是压缩单个目录,这样当您解压缩时,所有内容都会到达同一个位置。
The shell expands the wildcards so tar doesn't even see it. You have to add them explicitly if you want to do that. (
.*
). However, it's most common to tar a single directory so that when you untar it all goes to the same place.这将使
this will make the
这将压缩所有隐藏文件和目录
This will tar all hidden files and directories