文件覆盖前做简单备份
命令: **mv -b myFile1 myFile2 ** [root@VM_0_9_centos test]# ll
total 0
-rw-r--r-- 1 root root 0 Oct 27 10:14 myFile1
-rw-r--r-- 1 root root 0 Oct 27 10:05 myFile2
[root@VM_0_9_centos test]# mv -b myFile1 myFile2
mv: overwrite ?.yFile2?. y
[root@VM_0_9_centos test]# ll
total 0
-rw-r--r-- 1 root root 0 Oct 27 10:14 myFile2
-rw-r--r-- 1 root root 0 Oct 27 10:05 myFile2~
-b 不接受参数,mv会去读取环境变量VERSION_CONTROL来作为备份策略。
--backup该选项指定如果目标文件存在时的动作,共有四种备份策略:
1.CONTROL=none或off : 不备份。
2.CONTROL=numbered或t:数字编号的备份
3.CONTROL=existing或nil:如果存在以数字编号的备份,则继续编号备份m+1...n:
执行mv操作前已存在以数字编号的文件log2.txt.~1~,那么再次执行将产生log2.txt~2~,以次类推。如果之前没有以数字编号的文件,则使用下面讲到的简单备份。
4.CONTROL=simple或never:使用简单备份:在被覆盖前进行了简单备份,简单备份只能有一份,再次被覆盖时,简单备份也会被覆盖。 [root@VM_0_9_centos test]# mv -b --backup=numbered myFile2
mv: missing destination file operand after ?.yFile2?
Try 'mv --help' for more information.
[root@VM_0_9_centos test]# mv -b --backup=numbered myFile1 myFile2
mv: overwrite ?.yFile2?. y
[root@VM_0_9_centos test]# ll
total 0
-rw-r--r-- 1 root root 0 Oct 27 10:27 myFile2
-rw-r--r-- 1 root root 0 Oct 27 10:16 myFile2.~1~
[root@VM_0_9_centos test]#