search

Home  >  Q&A  >  body text

linux - tar 命令 报错 tar: Cowardly refusing to create an empty archive

系统:ubuntu

版本:13.02 和 12.04

执行命令:
tar -czf first_20130508.tar.gz -C /home/fyc/Documents/myTmp

tar -czf first_20130508.tar.gz -C /home/fyc/Documents/myTmp/*

报错:

tar: Cowardly refusing to create an empty archive  
Try `tar --help' or `tar --usage' for more information.

说明:
/home/fyc/Documents/myTmp目录下是有文件的,不明白怎么会报这个错。是因为打包的指定路径不用-C参数吗?

以上问题已解决,请看一下补充的问题

补充:
知道-C是解压缩时候的命令了。
还有一个问题

tar -cz**P**f first_20130508.tar.gz /home/fyc/Documents/myTmp/*

执行这个命令,会把绝对路径打到包里去,如果我想打相对路径,有什么参数吗? 也就是当使用

tar -tzf first_20130508.tar.gz

查看时,希望直接是/home/fyc/Documents/myTmp/目录下的文件名,而不带路径。

伊谢尔伦伊谢尔伦2779 days ago6427

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 11:26:42

    -C in tar specifies the decompression path.

    When packaging, directly add the path or file to be packaged after the package file name. According to the example you mentioned, the packaging command should be:
    tar -czf first_20130508.tar /home/fyc/Documents/myTmp

    That is to say, removing the -C should be enough.

    ==================

    You can also specify the -C option when compressing, which is used to specify a relative path. In the example you mentioned, the tar command should be changed to: tar -czf first_20130508.tar.gz -C /home/fyc/Documents/ myTmp

    reply
    0
  • PHPz

    PHPz2017-04-17 11:26:42

    Packaging without path should be: cd /home/fyc/Documents/myTmp; tar zcf /This points to the path where tar.gz is stored/first_20130508.tar.gz *

    reply
    0
  • 黄舟

    黄舟2017-04-17 11:26:42

    tar -zcvf external_libva.tgz -C external/libva .

    You forgot the dot after it. -C is only responsible for switching directories, but it does not tell tar which files to add to the archive

    reply
    0
  • 迷茫

    迷茫2017-04-17 11:26:42

    How to solve the first problem

    reply
    0
  • Cancelreply