系統(tǒng)之家 - 系統(tǒng)光盤(pán)下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Linux mv命令

Linux下mv命令實(shí)例講解(2)

時(shí)間:2014-12-09 13:35:12 作者:qipeng 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問(wèn): https://m.xitongzhijia.net/xtjc/20141208/32114.html 手機(jī)查看 評(píng)論

  實(shí)例五:將文件file1改名為file2,即使file2存在,也是直接覆蓋掉。

  命令:

  mv -f log3.txt log2.txt

  輸出:

  [root@localhost test4]# ll

  總計(jì) 8

  -rw-r--r-- 1 root root 8 10-28 06:15 log2.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log3.txt

 。踨oot@localhost test4]# cat log2.txt

  odfdfs

 。踨oot@localhost test4]# cat log3

  cat: log3: 沒(méi)有那個(gè)文件或目錄

 。踨oot@localhost test4]# ll

  總計(jì) 8

  -rw-r--r-- 1 root root 8 10-28 06:15 log2.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log3.txt

 。踨oot@localhost test4]# cat log2.txt

  odfdfs

  [root@localhost test4]# cat log3.txt

  dfosdfsdfdss

 。踨oot@localhost test4]# mv -f log3.txt log2.txt

 。踨oot@localhost test4]# cat log2.txt

  dfosdfsdfdss

 。踨oot@localhost test4]# ll

  總計(jì) 4

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

 。踨oot@localhost test4]#

  說(shuō)明:

  log3.txt的內(nèi)容直接覆蓋了log2.txt內(nèi)容,-f 這是個(gè)危險(xiǎn)的選項(xiàng),使用的時(shí)候一定要保持頭腦清晰,一般情況下最好不用加上它。

  實(shí)例六:目錄的移動(dòng)

  命令:

  mv dir1 dir2

  輸出:

 。踨oot@localhost test4]# ll

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

 。踨oot@localhost test4]# ll

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

  [root@localhost test4]# cd 。。

 。踨oot@localhost test]# ll

  drwxr-xr-x 6 root root 4096 10-27 01:58 scf

  drwxrwxrwx 3 root root 4096 10-28 06:24 test3

  drwxr-xr-x 2 root root 4096 10-28 06:48 test4

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

  [root@localhost test]# cd test3

 。踨oot@localhost test3]# ll

  drwxr-xr-x 2 root root 4096 10-28 06:21 logs

  -rw-r--r-- 1 root root 29 10-28 06:05 test1.txt

 。踨oot@localhost test3]# cd 。。

 。踨oot@localhost test]# mv test4 test3

 。踨oot@localhost test]# ll

  drwxr-xr-x 6 root root 4096 10-27 01:58 scf

  drwxrwxrwx 4 root root 4096 10-28 06:54 test3

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

  [root@localhost test]# cd test3/

 。踨oot@localhost test3]# ll

  drwxr-xr-x 2 root root 4096 10-28 06:21 logs

  -rw-r--r-- 1 root root 29 10-28 06:05 test1.txt

  drwxr-xr-x 2 root root 4096 10-28 06:48 test4

 。踨oot@localhost test3]#

  說(shuō)明:

  如果目錄dir2不存在,將目錄dir1改名為dir2;否則,將dir1移動(dòng)到dir2中。

  實(shí)例7:移動(dòng)當(dāng)前文件夾下的所有文件到上一級(jí)目錄

  命令:

  mv * 。。/

  輸出:

 。踨oot@localhost test4]# ll

  -rw-r--r-- 1 root root 25 10-28 07:02 log1.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

 。踨oot@localhost test4]# mv * 。。/

 。踨oot@localhost test4]# ll

  [root@localhost test4]# cd 。。

 。踨oot@localhost test3]# ll

  -rw-r--r-- 1 root root 25 10-28 07:02 log1.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

  drwxr-xr-x 2 root root 4096 10-28 06:21 logs

  -rw-r--r-- 1 root root 29 10-28 06:05 test1.txt

  drwxr-xr-x 2 root root 4096 10-28 07:02 test4

  實(shí)例八:把當(dāng)前目錄的一個(gè)子目錄里的文件移動(dòng)到另一個(gè)子目錄里

  命令:

  mv test3/*.txt test5

  輸出:

  [root@localhost test]# ll

  drwxr-xr-x 6 root root 4096 10-27 01:58 scf

  drwxrwxrwx 4 root root 4096 10-28 07:02 test3

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

 。踨oot@localhost test]# cd test3

 。踨oot@localhost test3]# ll

  -rw-r--r-- 1 root root 25 10-28 07:02 log1.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

  drwxr-xr-x 2 root root 4096 10-28 06:21 logs

  -rw-r--r-- 1 root root 29 10-28 06:05 test1.txt

  drwxr-xr-x 2 root root 4096 10-28 07:02 test4

  [root@localhost test3]# cd 。。

 。踨oot@localhost test]# mv test3/*.txt test5

 。踨oot@localhost test]# cd test5

 。踨oot@localhost test5]# ll

  -rw-r--r-- 1 root root 25 10-28 07:02 log1.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

  -rw-r--r-- 1 root root 29 10-28 06:05 test1.txt

  drwxr-xr-x 2 root root 4096 10-25 17:56 test5-1

 。踨oot@localhost test5]# cd 。。

 。踨oot@localhost test]# cd test3/

 。踨oot@localhost test3]# ll

  drwxr-xr-x 2 root root 4096 10-28 06:21 logs

  drwxr-xr-x 2 root root 4096 10-28 07:02 test4

 。踨oot@localhost test3]#

  實(shí)例九:文件被覆蓋前做簡(jiǎn)單備份,前面加參數(shù)-b

  命令:

  mv log1.txt -b log2.txt

  輸出:

  [root@localhost test5]# ll

  -rw-r--r-- 1 root root 25 10-28 07:02 log1.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt

  -rw-r--r-- 1 root root 29 10-28 06:05 test1.txt

  drwxr-xr-x 2 root root 4096 10-25 17:56 test5-1

 。踨oot@localhost test5]# mv log1.txt -b log2.txt

  mv:是否覆蓋“log2.txt”? y

 。踨oot@localhost test5]# ll

  -rw-r--r-- 1 root root 25 10-28 07:02 log2.txt

  -rw-r--r-- 1 root root 13 10-28 06:16 log2.txt~

  -rw-r--r-- 1 root root 29 10-28 06:05 test1.txt

  drwxr-xr-x 2 root root 4096 10-25 17:56 test5-1

 。踨oot@localhost test5]#

  說(shuō)明:

  -b 不接受參數(shù),mv會(huì)去讀取環(huán)境變量VERSION_CONTROL來(lái)作為備份策略。

  --backup該選項(xiàng)指定如果目標(biāo)文件存在時(shí)的動(dòng)作,共有四種備份策略:

  1.CONTROL=none或off : 不備份。

  2.CONTROL=numbered或t:數(shù)字編號(hào)的備份

  3.CONTROL=existing或nil:如果存在以數(shù)字編號(hào)的備份,則繼續(xù)編號(hào)備份m+1.。.n:

  執(zhí)行mv操作前已存在以數(shù)字編號(hào)的文件log2.txt.~1~,那么再次執(zhí)行將產(chǎn)生log2.txt~2~,以次類推。如果之前沒(méi)有以數(shù)字編號(hào)的文件,則使用下面講到的簡(jiǎn)單備份。

  4.CONTROL=simple或never:使用簡(jiǎn)單備份:在被覆蓋前進(jìn)行了簡(jiǎn)單備份,簡(jiǎn)單備份只能有一份,再次被覆蓋時(shí),簡(jiǎn)單備份也會(huì)被覆蓋。

  上面就是Linux下mv命令的用法介紹了,通過(guò)上面的9個(gè)例子相信你對(duì)mv命令有了一定的了解,如果你要進(jìn)行文件移動(dòng)和重命名的話,可以使用mv命令。

標(biāo)簽 命令

發(fā)表評(píng)論

0

沒(méi)有更多評(píng)論了

評(píng)論就這些咯,讓大家也知道你的獨(dú)特見(jiàn)解

立即評(píng)論

以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)

其他版本軟件

熱門(mén)教程

人氣教程排行

Linux系統(tǒng)推薦

掃碼關(guān)注
掃碼關(guān)注

掃碼關(guān)注 官方交流群 軟件收錄