首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要压缩文件夹中的所有文件和子目录,包括以点开始的文件和子目录。

问我需要压缩文件夹中的所有文件和子目录,包括以点开始的文件和子目录。
EN

Unix & Linux用户
提问于 2021-09-16 16:47:40
回答 1查看 1.6K关注 0票数 1

我需要压缩文件夹中的所有文件和子目录,包括以. (点)开头的文件和子目录。

我在一个名为synthesis的文件夹中,我需要压缩它下面的所有文件和子目录(但不是synthesis文件夹本身)。synthesis文件夹包含一个名为.sopc_builder的子目录,其中包含一个文件。

我尝试了以下命令

代码语言:javascript
复制
zip -r synthesis.zip *

我将生成的synthesis.zip复制到另一个文件夹,并在一个文件中列出了zip内容:

代码语言:javascript
复制
unzip -l synthesis.zip > filelist.txt

filelist.txt在列表中没有.sopc_builder及其文件。

我在一些帖子中看到了一些关于Linux命令shopt的内容,但并没有真正理解它。

我使用的Linux版本是我公司的RedHatEnterpriseLinuxServer7.9。

谢谢你,格雷迪

EN

回答 1

Unix & Linux用户

发布于 2021-09-16 18:23:59

一种方法是将zip与find结合起来:

代码语言:javascript
复制
$ cd the/dir/you/want/to/zip
$ find . -print | zip test -@
adding: file.txt (stored 0%)
adding: .hidden/ (stored 0%)
adding: .hidden/file2.txt (stored 0%)

根据手册

代码语言:javascript
复制
-@ file lists. If a file list is specified as -@ [Not on MacOS],
zip takes the list of input files from standard input instead
of from the command line. For example,
    zip -@ foo 
will store the files listed one per line on stdin in foo.zip.

Under Unix, this option can be used to powerful effect
in conjunction with the find (1) command.
For example, to archive all the C source files in the current directory
and its subdirectories:
    find . -name "*.[ch]" -print | zip source -@ 
(note that the pattern must be quoted to keep the shell from expanding it). 
票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/669317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档