Linux 归档(ubuntu tar)隐藏目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4572973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
archiving (ubuntu tar) hidden directories
提问by H2ONaCl
tar on a directory mydir
will archive hidden files and hidden subdirectories, but tar from withinmydir
with a *
wildcard will not. Is this a longstanding and known inconsistency or bug?
在目录上的焦油mydir
会从归档隐藏文件和隐藏子目录,但焦油中mydir
有*
通配符不会。这是一个长期存在且已知的不一致或错误吗?
Edit (additional information): tar from within mydir
with a wildcard will not "see" nor archive hidden files and hidden subdirectories in the immediatedirectory. However, in the non-hidden subdirectories of mydir
hidden files and hidden subdirectories will be archived.
编辑(附加信息):mydir
带有通配符的tar不会“看到”或存档直接目录中的隐藏文件和隐藏子目录。但是,在非隐藏子目录中的mydir
隐藏文件和隐藏子目录将被归档。
采纳答案by H2ONaCl
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 with tar
.
答案是*
通配符由 shell 处理,它只是不会扩展为以点开头的内容。另一个通配符?
也不会扩展到以点开头的内容。感谢 Keith 指出是 shell 进行扩展,因此它与tar
.
If you use shopt -s dotglob
then expansion will include things like .filename
. Thanks to Andy.
如果您使用,shopt -s dotglob
则扩展将包括诸如.filename
. 感谢安迪。
Use shopt -u dotglob
to turn it off.
使用shopt -u dotglob
将其关闭。
Switching the dotglob
option does not change ls
itself. Rather it just changes expansion behaviour as exhibited in something like ls *
.
切换dotglob
选项本身不会改变ls
。相反,它只是改变了像ls *
.
Edit: My recommendations are in a comment below.
编辑:我的建议在下面的评论中。
回答by Madhur Ahuja
With wildcard it will not work. You have to specify . (current directory) if you mean full directory including hidden files. You can do
使用通配符将不起作用。您必须指定 . (当前目录)如果您的意思是包含隐藏文件的完整目录。你可以做
tar -cvpzf test.tgz .
回答by Keith
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.
shell 扩展了通配符,因此 tar 甚至看不到它。如果你想这样做,你必须明确地添加它们。( .*
). 但是,最常见的是对单个目录进行 tar 处理,以便在解压时将其全部放到同一个位置。
回答by andy
shopt -s dotglob
this will make the
这将使
回答by Markoj
You can use:
您可以使用:
tar -cvpzf test.tgz * .??*
But, this works only for hidden files with names > 2 (to prevent '.' and '..')
但是,这仅适用于名称 > 2 的隐藏文件(以防止 '.' 和 '..')
回答by zurfyx
You can compress all the files / folders in your current directory (including .hidden) by using:
您可以使用以下方法压缩当前目录(包括 .hidden)中的所有文件/文件夹:
tar -zcvf compressed.tgz `ls -A -1`
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.
最后一个参数是您要压缩的文件夹。如果您通过它ls -A -1
,您将把当前目录中的所有文件夹传递给它,但是.
和..
. 对于子目录,默认情况下 .hidden 文件已包含在压缩中。