tar我犯了一个错误,在使用如下命令时忘记分配文件名参数:
[john@foobar foo]$ ll\ntotal 0\n-rw-rw-r-- 1 john john 0 7\xe6\x9c\x88 4 19:20 2018 file1\n-rw-rw-r-- 1 john john 0 7\xe6\x9c\x88 4 19:20 2018 file2\n-rw-rw-r-- 1 john john 0 7\xe6\x9c\x88 4 19:20 2018 file3\n[john@foobar foo]$ tar -cvzf file1 file2 file3\nfile2\nfile3\n[john@foobar foo]$ ll\ntotal 4\n-rw-rw-r-- 1 john john 130 7\xe6\x9c\x88 4 19:21 2018 file1\n-rw-rw-r-- 1 john john 0 7\xe6\x9c\x88 4 19:20 2018 file2\n-rw-rw-r-- 1 john john 0 7\xe6\x9c\x88 4 19:20 2018 file3\nRun Code Online (Sandbox Code Playgroud)\n\n当忘记指定存档文件名时,tar将覆盖并创建存档file1。
我检查了man tar,但似乎没有选项,例如cp当同名文件已存在时显示提示。
创建一个万无一失的脚本是一种可能的方法吗?
\nPos*_*shi 21
从man tar:
-k, --keep-old-files\n don\xe2\x80\x99t replace existing files when extracting, treat them as errors\n\n--skip-old-files\n don\xe2\x80\x99t replace existing files when extracting, silently skip over them\nRun Code Online (Sandbox Code Playgroud)\n