我在这条路径上有一个网络应用程序
var/app/current
我使用此命令压缩所有内容,包括 htaccess 等隐藏文件
zip -r yourfile.zip * .*
它会生成一个压缩文件,其中包含 Web 应用程序文件和文件夹,以及一个名为 current 的文件夹,其中包含 Web 应用程序文件和文件夹的另一个副本。
如何压缩包括隐藏文件在内的 Web 应用程序文件和文件夹,而不将名为“current”的目录作为重复文件包含进去。
答案1
您可能无法使用.*
,因为该 shell glob 也将匹配.
和..
(当前和父目录),从而导致您描述的行为。
但无论如何这不是必需的,您可以单独使用该zip -r
选项。让我引用手册页man zip
:
-r
--recurse-paths
Travel the directory structure recursively; for example:
zip -r foo.zip foo
or more concisely
zip -r foo foo
In this case, all the files and directories in foo are saved in
a zip archive named foo.zip, including files with names starting
with ".", since the recursion does not use the shell's file-name
substitution mechanism. If you wish to include only a specific
subset of the files in directory foo and its subdirectories, use
the -i option to specify the pattern of files to be included.
You should not use -r with the name ".*", since that matches
".." which will attempt to zip up the parent directory (proba‐
bly not what was intended).
Multiple source directories are allowed as in
zip -r foo foo1 foo2
which first zips up foo1 and then foo2, going down each direc‐
tory.
[...]
因此您只需指定要压缩的文件夹,例如:
zip -r yourfile.zip /var/app/current
或者如果你的当前目录已经是/var/app/current
,只需:
zip -r yourfile.zip .