歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下mv命令移動目錄的二種情況

Linux下mv命令移動目錄的二種情況

日期:2017/2/28 14:02:30   编辑:Linux教程

mv 移動目錄分為2種情況:

第一種:目標目錄為空,使用mv命令可以直接移動,使用絕對路徑執行或加參數-f 不會提示是否移動。
[root@localhost ~]# mkdir 1
[root@localhost ~]# mkdir /tmp/1
[root@localhost ~]# mv 1/ /tmp/
mv: overwrite `/tmp/1'? n
[root@localhost# /bin/mv 1/ /tmp/

第二種:目標目錄非空,使用絕對路徑執行也會提示目錄非空不能移動,需要加一個參數-b 加參數後可以移動,同時會備份目標目錄一份。備份目錄後面 ~ 表示;

[root@localhost ~]# mkdir 2
[root@localhost ~]# mkdir /tmp/2
[root@localhost ~]# touch /tmp/2/2.txt
[root@localhost ~]# /bin/mv 2/ /tmp/
/bin/mv: cannot move `2/' to `/tmp/2': Directory not empty
[root@localhost ~]# ls /tmp/
1 2 yum.log
[root@localhost# /bin/mv -b 2/ /tmp/
[root@localhost ~]# ls /tmp/
1 2 2~ yum.log

2~ 這個目錄為移動以前/tmp/目錄下的,移動之後加了~表示備份。

Copyright © Linux教程網 All Rights Reserved