gzip压缩了一组目录并创建一个COM焦油pressed文件 [英] gzipping up a set of directories and creating a tar compressed file

查看:92
本文介绍了gzip压缩了一组目录并创建一个COM焦油pressed文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的bash福是不是应该是什么。

My bash fu is not what it should be.

我想创建一个小批处理脚本,将目录列表复制到一个新的zip文件。

I want to create a little batch script which will copy a list of directories into a new zip file.

有(至少)两种方式我能想到的证明文件的列表中:

There are (at least) two ways I can think of proving the list of files:


  1. 从文件(比如config.txt)里读出。该文件将包含的目录列表,以压缩或

  1. read from a file (say config.txt). The file will contain the list of directories to zip up OR

硬code列表直接进入bash脚本

hard code the list directly into the bash script

第一种选择似乎更简单(虽然不太高雅)。

The first option seems more straightforward (though less elegant).

我现在面临的两个问题是,我不知道如何做到以下几点:

The two problems I am facing are that I am not sure how to do the following:


  • 提供的目录列表的shell脚本

  • 迭代的目录列表

有人能在几行提示,我该怎么做呢?

Could someone suggest in a few lines, how I can do this?

顺便说一句,我在Ubuntu上运行10.0.4

BTW, I am running on Ubuntu 10.0.4

推荐答案

您可以创建在命令行gzip压缩的tar如下:

You can create a gzipped tar on the commandline as follows:

tar czvf mytar.tar.gz dir1 dir2 .. dirN

如果你想做的事,在bash脚本,并通过目录作为参数传递给脚本,这些参数会在 $ @ 结束。所以,那么你有:

If you wanted to do that in a bash script and pass the directories as arguments to the script, those arguments would end up in $@. So then you have:

tar czvf mytar.tar.gz "$@"

如果是在脚本(可以说 myscript.sh ),你会说这就是为:

If that is in a script (lets say myscript.sh), you would call that as:

./myscript.sh dir1 dir2 .. dirN

如果您想从列表(你选择1)来读取你能做到这一点,像这样(如果有空格的目录名,这并不正常工作):

If you want to read from a list (your option 1) you could do that like so (this does not work if there is whitespace in directory names):

tar czvf mytar.tar.gz $(<config.txt)

这篇关于gzip压缩了一组目录并创建一个COM焦油pressed文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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