tar -r向归档中添加同名文件问题


先解释下我遇到的问题:
之前我的archive.tar包括file1,file2,file3,如下所示:

   
  ajaxhe@bbs:~/program/bash/tar$ tar -tvf archive.tar
  
-rw-r--r-- ajaxhe/ajaxhe 19 2012-12-10 19:18 file1
-rw-r--r-- ajaxhe/ajaxhe 0 2012-11-08 11:26 file2
-rw-r--r-- ajaxhe/ajaxhe 0 2012-11-08 11:26 file3

现在我有个同名文件file1,并不小心将这个文件用追加的方式添加到了archive.tar中,

   
  ajaxhe@bbs:~/program/bash/tar$ tar -rvf archive.tar file1
  
file1
ajaxhe@bbs:~/program/bash/tar$ tar -tvf archive.tar
-rw-r--r-- ajaxhe/ajaxhe 19 2012-12-10 19:18 file1
-rw-r--r-- ajaxhe/ajaxhe 0 2012-11-08 11:26 file2
-rw-r--r-- ajaxhe/ajaxhe 0 2012-11-08 11:26 file3
-rw-r--r-- ajaxhe/ajaxhe 27 2012-12-11 18:04 file1

若我现在从archive.tar提取文件

   
  ajaxhe@bbs:~/program/bash/tar$ tar -xvf archive.tar -C exact
  
file1
file2
file3
file1
ajaxhe@bbs:~/program/bash/tar$ cd exact/
ajaxhe@bbs:~/program/bash/tar/exact$ ls
file1 file2 file3

但这样提取出来的file1是我最新修改的,有没有可能找回我旧版本的file1?
谢谢!

Linux shell

kuroxue 10 years, 6 months ago

刚才没事,翻了一下tar的文档,很多有用的options,以前从来没用过啊

下面是上面问题相关的两个选项:

Keep Old Files

‘--keep-old-files’
‘-k’
Do not replace existing files from archive. The ‘--keep-old-files’ (‘-k’) option prevents tar from replacing existing files with files with the same name from the archive. The ‘--keep-old-files’ option is meaningless with ‘--list’ (‘-t’). Prevents tar from replacing files in the file system during extraction.

Keep Newer Files

‘--keep-newer-files’
Do not replace existing files that are newer than their archive copies. This option is meaningless with ‘--list’ (‘-t’).

more。。。。。

http://www.gnu.org/software/tar/manua...

夏日丨葱娘 answered 10 years, 6 months ago

Your Answer