linux下的刪除目錄和檔案的方法

2022-08-23 06:57:07 字數 866 閱讀 7653

看到了一遍文章,便突發奇想的想起linux中刪除目錄下的所有檔案的方法;整理了幾個,如有不足,還望讀者不吝賜教!

刪除當前目錄下的檔案

1.rm -f *

#最經典的方法,刪除當前目錄下的所有型別的檔案

2.find . -type f -delete或find . -type f -exec rm -f {} \;

#用find命令查詢普通檔案並刪除or用find命令的處理動作將其刪除

3.find . -type f | xargs rm -f

#用於引數列表過長;要刪除的檔案太多

4.rm-f `find . -type f`

#刪除全部普通檔案

5.for delete in `ls -l`;do rm -f * ;done

#用for迴圈語句刪除當前目錄下的所有型別的檔案

刪除指定目錄下的檔案

1.rm -f 指定目錄*

#最經典的方法,刪除指定目錄下的所有型別的檔案

2.find 指定目錄 -type f -delete或find 指定目錄 -type f -exec rm -f {} \;

#用find命令查詢指定目錄下的所有普通檔案並刪除or用find命令的處理動作將其刪除

3.find 指定目錄 -type f | xargs rm -f

#用於引數列表過長;要刪除的檔案太多

4.rm-f `find 指定目錄 -type f`

#刪除指定目錄下的全部普通檔案

5.for delete in `ls –l 指定目錄路徑`;do rm -f * ;done

#用for迴圈語句刪除指定目錄下的所有型別的檔案

Linux下目錄和檔案的許可權

在linux系統內檔案有三種身份 owner group others 而且每種身份有三種許可權 r read w write x execute 我們可以使用chmod chown chgrp去修改這 些許可權,也可以用ls l檢視他們的許可權與屬性,那麼這些許可權對於一般檔案和目錄檔案有什麼不同...

linux下遍歷目錄和檔案

目錄操作相關函式 1 opendir 開啟目錄 dir opendir const char name 引數 要開啟的目錄名 返回值 指向目錄的指標 這裡的dir型別可以int dirfd dir dirp 函式轉變為描述符 fd 2 讀目錄 readdir struct dirent readdi...

linux遞迴強行刪除目錄和檔案

在linux中刪除乙個目錄很簡單,使用rm rf命令即可解決。直接rm就可以了,不過要加兩個引數 rf 即 rm rf 目錄名字 r 就是向下遞迴,不管有多少級目錄,一併刪除 f 就是直接強行刪除,不作任何提示的意思刪除資料夾例項 rm rf home name mydir 將會刪除 home na...