假设结构:
/foo/bar/
--file1
--file2
--file3
--folder1
--file4
--folder2
--file5
我想运行 unix zip实用程序,压缩
bar
文件夹及其所有文件和子文件夹,来自 foo
文件夹,但没有 bar
zip 中的文件夹,仅使用命令行。如果我尝试使用
-j
参数,它不会按照我的意愿在 zip 中创建 bar 文件夹,但不会创建 folder1
和 folder2
.做 -rj
不起作用。(我知道我可以进入 bar 并执行
zip -r bar.zip .
我想知道是否有可能完成 $/foo/bar/zip -r bar.zip .
但从 $/foo 执行的操作)。
最佳答案
你要做的cd /foo/bar
然后 zip -r bar.zip .
,但是,您可以使用括号将它们分组以在子shell中运行:
# instead of: cd /foo/bar; zip -r bar.zip; cd -
( cd /foo/bar; zip -r bar.zip . )
封闭的(paren-grouped)命令在子 shell 中运行,其中的 cd 不会影响 shell 程序 session 。
见 sh manual .
Compound Commands
A compound command is one of the following:
(list) list is executed in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below).
Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes.
The return status is the exit status of list.
关于unix - 不包含压缩目录本身的 Zip 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3630167/