linux下重新命名檔案對永久連結和軟連結的影響__linux

來源:互聯網
上載者:User

linux下重新命名檔案或檔案夾的命令mv既可以重新命名,又可以移動檔案或檔案夾.

例子:將目錄A重新命名為B

mv A B

例子:將/a目錄移動到/b下,並重新命名為c

mv /a /b/c

 

其實在文字模式中要重新命名檔案或目錄的話也是很簡單的,我們只需要使用mv命令就可以了,

比如說我們要將一個名為abc的檔案重新命名為1234就可以這樣來寫:mv abc 1234,但是要注意的是,

如果目前的目錄下也有個1234的檔案的話,我們的這個檔案是會將它覆蓋的。

注意,移動檔案會改變檔案名稱,但是保持同樣的索引節點和時間戳記,移動一個有軟連結指向的檔案會帶來麻煩,採用永久連結沒有問題。


root@wl-MS-7673:/home/wl/案頭/shell/test# touch test1root@wl-MS-7673:/home/wl/案頭/shell/test# lstest1root@wl-MS-7673:/home/wl/案頭/shell/test# ln test1 test2root@wl-MS-7673:/home/wl/案頭/shell/test# ls -il總用量 03161381 -rw-r--r-- 2 root root 0  3月  6 21:09 test13161381 -rw-r--r-- 2 root root 0  3月  6 21:09 test2root@wl-MS-7673:/home/wl/案頭/shell/test# ln -s test1 test3root@wl-MS-7673:/home/wl/案頭/shell/test# ls -il總用量 03161381 -rw-r--r-- 2 root root 0  3月  6 21:09 test13161381 -rw-r--r-- 2 root root 0  3月  6 21:09 test23161398 lrwxrwxrwx 1 root root 5  3月  6 21:10 test3 -> test1root@wl-MS-7673:/home/wl/案頭/shell/test# mv test1 test4root@wl-MS-7673:/home/wl/案頭/shell/test# ls -il總用量 03161381 -rw-r--r-- 2 root root 0  3月  6 21:09 test23161398 lrwxrwxrwx 1 root root 5  3月  6 21:10 test3 -> test13161381 -rw-r--r-- 2 root root 0  3月  6 21:09 test4root@wl-MS-7673:/home/wl/案頭/shell/test# 




test2是指向test1的永久連結,移動test1為test3後test2和test3依然保持同樣的索引節點,而軟連結test3卻指向了此時已經不存在的test1。。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.