![](/img/trans.png)
[英]How do I move a large number of zip files in a directory to a specified number of multiple subdirectories in bash?
[英]Shell: How to move multiple files to a directory and zip that directory with different name?
例如,我的项目中有一些文件,结构可能像这样
Project/
-- file1.txt
-- file2.txt
-- build/
-- sub-folder/
我想从我的项目中压缩一些文件,我可以使用ZIP命令来完成(构建文件夹和其他一些文件不包含在zip中)
zip -r build/project-04.05.2016 ./ -x *\build\*
创建此新文件后:
build/project-04.05.2016.zip
在Mac Finder中,当我双击该文件时,它将像以下这样解压缩:
build/project-04.05.2016/
----------- file1.txt
----------- file2.txt
----------- subfolder/
我想以某种方式压缩此存档,因此当解压缩该存档时,我会得到一个具有相同内容的文件夹“ project”,而不是“ project-04.05.2016”。 在将其压缩为“项目”之后,我试图将文件重命名为“ project-04.05.2016”,但是当解压缩时,结果是相同的。 也许有一种方法可以先将文件移动到某个临时的“项目”文件夹,然后再将其压缩为“ project-04.05.2016.zip”? 提前致谢。
这是我当前的解决方案,它是一个小的脚本,我对此不太满意,但是可以使用。 如果有人用更优雅的解决方案回答,我将接受。 因此,这里是:
#clear the contents of the previous build first
rm -r build/*
#copy required files to a temporary folder
rsync -av --exclude=build ./ build/project
#change current directory to build
cd build/
#zip files from build/project folder
zip -r "project-04.05.2016" project
#remove temporary folder
rm -r project/
#final zip file is at location:
#build/project-04.05.2016.zip
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.