centos 用于排除目录和文件的Zip命令

sg2wtvxw  于 8个月前  发布在  其他
关注(0)|答案(4)|浏览(124)

我试图使用这个ssh命令在centos 5压缩了一个目录充满了文件夹和文件,但排除了下面的例子。没有用

zip -r file.zip * -x dir1 -x dir2 -x file1 -x file2

或这一个

zip -r file.zip * -x "dir1" -x "dir2" -x "file1" -x "file2"

它仍然只是压缩了整个目录和它的一切。我不想要dir 1 dir 2 file 1 file 2。
我需要知道正确的-x语法,以便排除函数工作。

gjmwrych

gjmwrych1#

对于我的特定系统,为了排除一个目录,我不得不在我排除的目录周围加上引号,它就像一个魅力:

zip -r myarchive.zip target -x "target/exclude1/*" "target/exclude2/*"

备注:
--这排除了要排除的目录和其中的所有文件。
--必须使用要包含和排除的目录的完整路径!
--只要排除项位于行尾,就不需要@符号

8ljdwjyq

8ljdwjyq2#

-x选项有点奇怪;你列出文件,以-x开始,以@符号结束:

zip file.zip -r * -x dir1 dir2 file1 file2 @

我也很怀疑你是否想在Unix系统上的文件名中使用\. /是常用的路径分隔符。
范例:

mkdir tmp5
cd tmp5
touch a b c d e f g
zip foo.zip -r * -x e f g @
  adding: a (stored 0%)
  adding: b (stored 0%)
  adding: c (stored 0%)
  adding: d (stored 0%)

对于子目录,你可以很容易地使用一个*来忽略它们的 contents,但是似乎*会导致目录本身被包含(空):

mkdir x y z
touch {a,b,c} {x,y,z}/{a,b,c}
zip foo.zip -r * -x c y y/* z z/* @
  adding: a (stored 0%)
  adding: b (stored 0%)
  adding: x/ (stored 0%)
  adding: x/b (stored 0%)
  adding: x/a (stored 0%)
  adding: x/c (stored 0%)
  adding: y/ (stored 0%)
  adding: z/ (stored 0%)

你可能最好省略*,并明确列出那些你想包括的东西。

zip core-latest-$version.zip -r cp images include mobile stats \
    -x cp/includes/configure.php @

(the \在末尾只是继续到下一行;你可以把它放在一行上,不带尾随的\

7gcisfzg

7gcisfzg3#

如果您使用腻子,请按照以下步骤操作:
1.输入您的目录:$ cd directory_name并按回车键
1.写命令:

$ zip -r file_name.zip . -x \*excludingfolderName\*

zip之后使用.作为当前目录,*是一个目录。

0aydgbwb

0aydgbwb4#

TLDR

使用-x "**/folder/*"

LR;

可以使用与gitignore或vscode排除文件vscode files exclude syntax相同的语法

相关问题