命令使用特定目录作为根目录来压缩目录 [英] Command to zip a directory using a specific directory as the root

查看:120
本文介绍了命令使用特定目录作为根目录来压缩目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写一个PHP脚本,将一系列生成的文件(使用 wget )下载到一个目录中,然后使用 zip 命令。



下载工作完美,压缩主要工作。我运行命令:

  zip -r /var/www/oraviewer/rgn_download/download/fcst_20100318_0319.zip / var / www / oraviewer / rgn_download / download / fcst_20100318_0319 

这会生成一个包含所有下载文件的zip文件,包含完整的 / var / www / oraviewer / rgn_download / download / 目录,然后到达 fcst_20100318_0319 / 目录。 / p>

我可能只是从zip命令中缺少一个标志,或者一些小东西,但是如何让它使用 fcst_20100318_0319 / 作为根目录?

解决方案

我不认为zip有一个标志。我认为唯一的方法是:

  cd / var / www / oraviewer / rgn_download / download /& \ 
zip -r fcst_20100318_0319.zip fcst_20100318_0319

(反斜杠只是为了清楚起见,您可以删除它并将所有内容放在一行上。)



由于PHP在subshel​​l中执行命令,因此不会更改当前目录。


I'm writing a PHP script that downloads a series of generated files (using wget) into a directory, and then zips then up, using the zip command.

The downloads work perfectly, and the zipping mostly works. I run the command:

zip -r /var/www/oraviewer/rgn_download/download/fcst_20100318_0319.zip /var/www/oraviewer/rgn_download/download/fcst_20100318_0319

which yields a zip file with all the downloaded files, but it contains the full /var/www/oraviewer/rgn_download/download/ directories, before reaching the fcst_20100318_0319/ directory.

I'm probably just missing a flag, or something small, from the zip command, but how do I get it to use fcst_20100318_0319/ as the root directory?

解决方案

I don't think zip has a flag to do that. I think the only way is something like:

cd /var/www/oraviewer/rgn_download/download/ && \
   zip -r fcst_20100318_0319.zip fcst_20100318_0319

(The backslash is just for clarity, you can remove it and put everything on one line.)

Since PHP is executing the command in a subshell, it won't change your current directory.

这篇关于命令使用特定目录作为根目录来压缩目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆