描述: 移动文件与目录,或更名
用法:mv [-fiu] source destination
mv [option] source1 source2 source3 ... directory
常用参数:
-b:若需覆盖文件,则覆盖前先行备份。
-f:强制
-i:互动模式
-u:若目标文件存在,且source比较新,才会更新。
示例:
1.文件重命名
[root@share19 ~]# mv 1.log 2.log
[root@share19 ~]# ll
total 4
-rw-r--r--. 1 root root 0 May 23 15:36 2.log
2.目录的移动
说明:
如果目录dir2不存在,将目录dir1改名为dir2;否则,将dir1移动到dir2中。
[root@share19 ~]# ll
total 4
drwxr-xr-x. 2 root root 6 May 23 15:38 test1
[root@share19 ~]# mv test1 test2
[root@share19 ~]# ll
total 4
drwxr-xr-x. 2 root root 6 May 23 15:38 test2
[root@share19 ~]# mkdir test1
[root@share19 ~]# ll
total 4
drwxr-xr-x. 2 root root 6 May 23 15:39 test1
drwxr-xr-x. 2 root root 6 May 23 15:38 test2
[root@share19 ~]# mv test1 test2
[root@share19 ~]# ll
total 4
drwxr-xr-x. 3 root root 18 May 23 15:39 test2
[root@share19 ~]# cd test2
[root@share19 test2]# ll
total 0
drwxr-xr-x. 2 root root 6 May 23 15:39 test1
3.移动当前文件夹下的所有文件到上一级目录
[root@share19 test2]# mv * ../
4.文件被覆盖前做简单备份,前面加参数-b
[root@share19 ~]# ll
total 12
-rw-r--r--. 1 root root 25 May 23 15:49 1.log
-rw-r--r--. 1 root root 53 May 23 15:49 2.log
[root@share19 ~]# mv -b 1.log 2.log
mv: overwrite ‘2.log’? y
[root@share19 ~]# ll
total 12
-rw-r--r--. 1 root root 25 May 23 15:49 2.log
-rw-r--r--. 1 root root 53 May 23 15:49 2.log~