mv :改名或者变更文件存放位置
用法:
mv [选项]... 源文件... 目录
mv [选项]... -t 目录 源文件...
选项:
-b :当目标文件存在时,先进行备份,在覆盖
-f :强制覆盖
-i :交互式,覆盖前询问
• mv :移动文件,默认-i
[root@host test]# ls
file1 file2 file3 file4 file5 time
[root@host test]# mv file* time
[root@host test]# ls
time
[root@host test]# cd time/
[root@host time]# ls
file1 file2 file3 file4 file5
[root@host test]# touch file1
[root@host test]# mv file1 atime/
mv:是否覆盖"atime/file1"? y
• mv file file2 :改名
[root@host test]# ls
time
[root@host test]# mv time atime
[root@host test]# ls
atime
• mv -b:目标文件存在时,先备份,在覆盖
[root@host test]# ls
atime
[root@host test]# touch file1
[root@host test]# echo "1234" > file1
[root@host test]# cd atime/
[root@host atime]# echo "5678" > file1
[root@host atime]# cd ..
[root@host test]# mv -b file1 atime/
mv:是否覆盖"atime/file1"? y
[root@host test]# cd atime/
[root@host atime]# ls
file1 file1~ file2 file3 file4 file5
[root@host atime]# cat file1
1234
[root@host atime]# cat file1
file1 file1~ #file1~就是移动之前atime/file1的备份文件
[root@host atime]# cat file1~
5678
• mv -f:强制覆盖
[root@host test]# touch file1
[root@host test]# echo "123456" > file1
[root@host test]# mv -f file1 atime/
[root@host test]# ls
atime
[root@host test]# cd atime/
[root@host atime]# ls
file1 file1~ file2 file3 file4 file5
[root@host atime]# cat file1
123456
[root@host atime]# cat file1~ #这个file1~是mv -b的没有删除
5678
• mv -t 路径 file:移动文件
[root@host test]# ls
atime
[root@host test]# touch file
[root@host test]# mv -t atime/ file
[root@host test]# ls
atime
[root@host test]# cd atime/
[root@host atime]# ls
file