[root@localhost ~]# mv 【選項】 源文件 目標文件
選項:[root@localhost ~]# mv cangls /tmp
#移動之后,源文件會被刪除,類似剪切
[root@localhost ~]# mkdir movie
[root@localhost ~]# mv movie/ /tmp
#也可以移動目錄。和 rm、cp 不同的是,mv 移動目錄不需要加入 "-r" 選項
[root@localhost ~]# touch cangls
#重新建立文件
[root@localhost ~]# mv cangls /tmp
mv:縣否覆蓋"tmp/cangls"?y
#由于 /tmp 目錄下已經存在 cangls 文件,所以會提示是否覆蓋,需要手工輸入 y 覆蓋移動
[root@localhost ~]# touch cangls
#重新建立文件
[root@localhost ~]# mv -f cangls /tmp
#就算 /tmp/ 目錄下已經存在同名的文件,由于"-f"選項的作用,所以會強制覆蓋
[root@localhost ~]# ls /tmp
/tmp/bols /tmp/cangls
#在/tmp/目錄下已經存在bols、cangls文件了
[root@localhost ~]# mv -vn bols cangls lmls /tmp/、
"lmls"->"/tmp/lmls"
#再向 /tmp/ 目錄中移動同名文件,如果使用了 "-n" 選項,則可以看到只移動了 lmls,而同名的 bols 和 cangls 并沒有移動("-v" 選項用于顯示移動過程)
[root@localhost ~]# mv bols lmls
#把 bols 改名為 lmls
[root@localhost ~]# touch test1.txt test2.txt test3.txt
#建立三個測試文件
[root@localhost ~]# mv -v *.txt /tmp
"test1.txt" -> "/tmp/test1.txt"
"test2.txt" -> "/tmp/test2.txt"
"test3.txt" -> "/tmp/test3.txt"
#加入"-v"選項,可以看到有哪些文件進行了移動
新聞熱點
疑難解答