格式:mv [OPTION]… SOURCE… DIRECTORY
将目录/tmp/1下的某文件移动到目录/tmp/1/2下
[root@localhost tmp]# ll /tmp/1/2/ total 0 drwxr-xr-x 3 root root 14 Nov 28 2017 3 [root@localhost tmp]# mv /tmp/1/test.txt /tmp/1/2/ [root@localhost tmp]# ll /tmp/1/2/ total 0 drwxr-xr-x 3 root root 14 Nov 28 2017 3 -rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt [root@localhost tmp]#
将目录/tmp/1下的某文件移动到目录/tmp/1/2下并重命名
[root@localhost tmp]# mv /tmp/1/test.txt /tmp/1/2/test1.txt [root@localhost tmp]# ll /tmp/1/2/ total 0 drwxr-xr-x 3 root root 14 Nov 28 2017 3 -rw-r--r-- 1 root root 0 Feb 14 20:33 test1.txt -rw-r--r-- 1 root root 0 Feb 12 21:00 test.txt [root@localhost tmp]#
将tmp下的目录1移动到目录/tmp/qwe下
[root@localhost tmp]# ll /tmp/qwe/ total 0 [root@localhost tmp]# [root@localhost tmp]# mv /tmp/1/ /tmp/qwe/ [root@localhost tmp]# tree /tmp/qwe/ /tmp/qwe/ └── 1 └── 2 ├── 3 │ └── 4 │ └── 5 ├── test1.txt └── test.txt 5 directories, 2 files [root@localhost tmp]#
将tmp下的目录qwe移动到目录/tmp/z下并重命名
[root@localhost tmp]# ll /tmp/z/ total 0 drwxr-xr-x 3 root root 14 Nov 28 2017 x [root@localhost tmp]# mv /tmp/qwe/ /tmp/z/poi [root@localhost tmp]# tree /tmp/ /tmp/ ├── rty ├── systemd-private-67f03791c3f34110b44cc9fe6c96389d-vmtoolsd.service-Nfell2 │ └── tmp ├── yum_save_tx.2017-11-26.20-55.3OHjxh.yumtx └── z ├── poi │ └── 1 │ └── 2 │ ├── 3 │ │ └── 4 │ │ └── 5 │ ├── test1.txt │ └── test.txt └── x └── c └── v └── b 14 directories, 3 files [root@localhost tmp]#
Ubuntu系统请配合sudo使用(sudo mv)