简体   繁体   English

如何使用shell脚本创建一个zip文件?

[英]How to create a zip file using shell script?

I want to create a zip files based on the directory.我想根据目录创建一个 zip 文件。 But I need to make zip file from Result directory.但我需要从 Result 目录制作 zip 文件。

#!/bin/bash
zip -r /home/admin/download.zip /home/admin/1/2/3/Results

From your question, I understand that you want to zip the files in the "Results" directory without considering the directory "Results" itself when trying to zip.从您的问题中,我了解到您想压缩“结果”目录中的文件,而在尝试压缩时不考虑目录“结果”本身。

If so, then use the below commands如果是这样,则使用以下命令

#!/bin/bash
cd /home/admin/1/2/3/Results
zip -r /home/admin/download.zip ./*

After this, the zip file would be created in the required location.之后,将在所需位置创建 zip 文件。 Zip file is with only the files from the result directory, without the "Result" directory itself. Zip 文件只包含结果目录中的文件,没有“结果”目录本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM