.tar文件的结构

PRP

我正在尝试运行一些基准测试,以输入tar文件。

现在,tar文件中有一个runme.sh,需要对其进行修改,并且必须将文件夹再次设置为.tar。

原始基准测试有效,但修改基准无效。我相信这是文件格式的问题。

注意:我的修改没有引起问题。如果我只是解压缩工作的tar并再次对其进行压缩而不进行修改,那么它将无法正常工作。令人惊讶的是,新文件的大小发生了变化。

我试过了

  1. file在工作和不工作的tar文件上执行命令。两者返回相同POSIX tar archive

  2. 试图运行命令tar cvf folder_name.tar folder_name/不起作用。

什么有效:

我在Ubuntu(14.04)上,双击tar,直接编辑了想要的文件并进行了更新。这可行,但不是可行的解决方案,因为我有大量文件,并且我想编写一个脚本来使其自动化。

屏幕如何与G​​UI配合使用的屏幕截图:

在此处输入图片说明

佩德·克林根伯格

原始tar文件是否包含顶级目录名称?从您的屏幕截图来看,它看起来不像。如果您使用顶层目录重新创建tar文件(如尝试中的第2点所示),则结构将不同,并且任何尝试使用tar文件的程序都将无法使用解析它。

如何测试:“如果我只是解压缩工作的tar,然后再次对其进行压缩而不进行修改,那么它将无法正常工作。” 在GUI或Shell中?如果在外壳中-您将使用哪些确切命令?

In a shell, you can get the contents of the tarball with the command tar -tf filename.tar. If all the files it lists starts with the same folder name, your tarball includes a top level directory. If it just lists various files and subdirectories, it doesn't. (Tarballs that don't are an abomination, but if whatever you are using them for requires it, you'll just have to cope.)

I'm guessing that if you do this on your original tar file and your modified, non-working tar file, the results will differ.

The following should work in a shell if you have/need a tarball without a toplevel directory:

$ mkdir workdir
$ cd workdir
$ tar -xf ../tarball.tar
<edit your file however you like>
$ tar -cf ../tarball-new.tar *
$ cd ..
$ rm -r workdir

In case you have/need a tarball with a toplevel directory, the following should suffice:

$ tar -xf ../tarball.tar
$ cd toplevel_directory
<edit your file however you like>
$ cd ..
$ tar -cf tarball-new.tar toplevel_directory
$ rm -r toplevel_directory

编辑:很高兴它为您工作。当然,重点是tar包含它存储的文件的路径,而不仅仅是文件名。因此,如果您需要平面文件列表,则需要在包含这些文件的目录中运行tar,并将所有文件都作为参数提供给tar如果您尝试采用上一步的快捷方式,而仅指定要打包的目录名称,则tar将在归档文件中包含目录名称。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章