linux下檔案或檔案夾的建立、複製、剪下、重新命名、清空和刪除等命令總結

來源:互聯網
上載者:User

linux下檔案或檔案夾的建立、複製、剪下、重新命名、清空和刪除等命令總結

linux下檔案或檔案夾的建立、複製、剪下、重新命名、清空和刪除等命令總結。

一、目錄建立

在/home/wwwroot目錄下建立一個phpernote123的檔案夾

mkdir /home/wwwroot/phpernote123

linux建立檔案(touch)命令詳解

二、目錄複寫

1.把/home/wwwroot/phpernote裡面的檔案和檔案夾等複製到home/wwwroot/phpernote123目錄下

cp -rf /home/wwwroot/phpernote/* /home/wwwroot/phpernote123

2.把/home/wwwroot/phpernote目錄複寫到/home/wwwroot/phpernote123目錄下,即把phpernote複製變成phpernote123的子目錄,變成/home/wwwroot/phpernote123/phpernote的路徑

cp -rf /home/wwwroot/phpernote /home/wwwroot/phpernote123

三、目錄剪下

1.使用mv命令剪下檔案。

如需要將/home/wwwroot/phpernote123/music/目錄下的1.mp3檔案剪下到/home/wwwroot/phpernote123/abc目錄下,執行下面的命令即可:

mv /home/wwwroot/phpernote123/music/1.mp3 /home/wwwroot/phpernote123/abc

2.使用mv命令剪下檔案夾。

把/home/wwwroot/phpernote123/soft檔案夾剪下到/home/wwwroot/phpernote123/abc目錄下

mv /home/wwwroot/phpernote123/soft /home/wwwroot/phpernote123/abc

3.使用mv命令剪下檔案夾和檔案

把/home/wwwroot/phpernote123/photo/下的檔案夾和檔案剪下到/home/wwwroot/phpernote123/abc目錄下

mv /home/wwwroot/phpernote123/photo/* /home/wwwroot/phpernote123/abc

四、目錄重新命名

在linux下,移動檔案跟重新命名都是同一個命令,mv(就是move的意思)

命令: mv 源檔案名稱 目標檔案名

1.把/home/wwwroot/phpernote123/index.htm重新命名為/home/wwwroot/phpernote123/index.html

mv /home/wwwroot/phpernote123/index.htm /home/wwwroot/phpernote123/index.html

2.把/home/wwwroot/phpernote123目錄重新命名為/home/wwwroot/phpernote456

mv /home/wwwroot/phpernote123 /home/wwwroot/phpernote456

五、目錄刪除

linux刪除目錄很簡單,很多人還是習慣用rmdir,不過一旦目錄非空,就陷入深深的苦惱之中,現在使用rm -rf命令即可。

直接rm就可以了,不過要加兩個參數-rf

即:rm -rf   目錄名字

-r 就是向下遞迴,不管有多少級目錄,一併刪除

-f 就是直接強行刪除,不作任何提示的意思

1.刪除檔案使用執行個體:

rm -f /home/wwwroot/phpernote456/index.html

將會強制移除/home/wwwroot/phpernote456/index.html這個檔案

2.清空檔案夾執行個體:

rm -rf /home/wwwroot/phpernote456/abc/*

將會強制移除/home/wwwroot/phpernote456/abc目錄下所有檔案、檔案夾,保留/home/wwwroot/phpernote456/abc目錄

3.刪除檔案夾執行個體:

rm -rf /home/wwwroot/phpernote456

將會強制移除/home/wwwroot/phpernote456目錄以及其下所有檔案、檔案夾

需要提醒的是:使用這個rm -rf的時候一定要格外小心,linux沒有資源回收筒的

當然,rm還有更多的其他參數和用法,man rm就可以查看了

如果是在/home/wwwroot/目錄下進行操作,則可以省去每個命令的/home/wwwroot/部分。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.