2011-01-30 38 views
0

我正在写一个解压缩文件的程序。虽然这样做untar tar命令给消息焦油块大小的消息

$ tar -xf testing_Download.txt1.tar 
Tar: blocksize = 12 

我试过下面

$ tar 2>&1 1>/dev/null -xf testing_Download.txt1.tar 
Tar: blocksize = 12 

下面是命令输出的tar文件,该文件是不存在的磁盘

tar 2>&1 1>/dev/null -xf testing_Download.txt12.tar 

tar: cannot open testing_Download.txt12.tar

我想知道如何调整我的tar命令,以便我可以确定untar已成功执行。

回答

1

使用tar的返回值。

tar -xf testing_Download.txt1.tar &>/dev/null 
if [ "$?" = "0" ]; 
then 
    echo "success..." 
fi 

或检查,如果该文件是有第一:

if [ -e testing_Download.txt1.tar ]; 
then 
    tar -xf testing_Download.txt1.tar &>/dev/null 
else 
    echo "tar file not there" 
fi 
+0

但这是检查文件不存在。我不确定,但可能会有其他一些tar失败的情况。在这种情况下,返回代码是否也有帮助?因为第二种情况不适用于此。 – user258367 2011-01-30 12:20:31