2011-01-30 49 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