【发布时间】:2013-04-16 19:20:35
【问题描述】:
我正在编写一个 bash 脚本,它应该从指定目录创建一个 .tar.gz 存档,包括文件结构。这是一个家庭作业,我需要它在学校使用的 Solaris 系统上工作。这意味着我不能像这样使用 tar
tar xvzf archive.tar.gz ./
因为这个系统使用了一些没有 -z 选项的旧版本的 tar。我是这样用的
tar xvf - ./ | gzip > archive.tar.gz
除了一个奇怪的事实外,它工作正常,当我检查存档的内容时,它包含自己(换句话说,它包含“archive.tar.gz”)。我怎样才能防止这种情况发生?
【问题讨论】:
-
tar在 Solaris 上有一个参数X Exclude. Use the exclude-filename argument as a file containing a list of named files (or direc-tories) to be excluded from the tarfile when using the key letters c, x, or t.。在 /tmp 中创建一个文件,其中包含结果文件的名称。或者在 /tmp 中创建压缩的 tar 文件,如果创建成功则移动它。
标签: bash gzip solaris archive tar