[英]Shell: How to move multiple files to a directory and zip that directory with different name?
Fore example, I have some files in my project, structure could be like this 例如,我的项目中有一些文件,结构可能像这样
Project/
-- file1.txt
-- file2.txt
-- build/
-- sub-folder/
I want to zip some files from my project and I can do that using ZIP command (build folder and some other files are excluded from zip) 我想从我的项目中压缩一些文件,我可以使用ZIP命令来完成(构建文件夹和其他一些文件不包含在zip中)
zip -r build/project-04.05.2016 ./ -x *\build\*
After this new file is created: 创建此新文件后:
build/project-04.05.2016.zip
In Mac Finder when I double click on this file it becomes unzipped like this: 在Mac Finder中,当我双击该文件时,它将像以下这样解压缩:
build/project-04.05.2016/
----------- file1.txt
----------- file2.txt
----------- subfolder/
I would like to somehow zip this archive, so when it's unzipped, instead of "project-04.05.2016" I get a folder "project" with the same content. 我想以某种方式压缩此存档,因此当解压缩该存档时,我会得到一个具有相同内容的文件夹“ project”,而不是“ project-04.05.2016”。 I was trying to rename the file to "project-04.05.2016" after it's zipped as "project", but when it's unzipped the results are the same.
在将其压缩为“项目”之后,我试图将文件重命名为“ project-04.05.2016”,但是当解压缩时,结果是相同的。 Maybe there's a way to first move the files to some temporary "project" folder and than to zip them to "project-04.05.2016.zip"?
也许有一种方法可以先将文件移动到某个临时的“项目”文件夹,然后再将其压缩为“ project-04.05.2016.zip”? Thanks in advance.
提前致谢。
Here is my current solution, it's a small script and I'm not too satisfied with it, but it works. 这是我当前的解决方案,它是一个小的脚本,我对此不太满意,但是可以使用。 I will accept if someone answers with more elegant solution.
如果有人用更优雅的解决方案回答,我将接受。 So, here it is:
因此,这里是:
#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.