1. 程式人生 > 實用技巧 >轉載:Linux下查詢檔案

轉載:Linux下查詢檔案

轉載:https://www.cnblogs.com/heishuichenzhou/p/10609144.html

一:檢視檔案

1、檢視某資料夾下檔案的個數:
ls -l|grep "^-"|wc -l

2、檢視某資料夾下檔案目錄的個數:
ls -l|grep "^d"|wc -l

3、檢視某資料夾下檔案的個數,包括子檔案裡的檔案:
ls -lR|grep "^-"|wc -l

4、檢視某資料夾下檔案目錄的個數,包括子檔案裡的檔案目錄:
ls -lR|grep "^d"|wc -l

命令補充:
ls -l :檢視目錄型別(檔案、目錄、連結等)
wc -l :統計行數

5、搜尋以xx開頭的檔案

ls -1 | grep "^xx\."

注:grep後面使用正則表示式去匹配

7、按修改時間排序顯示目錄

ls -r:升序

ls -t:降序(最新的在最前面)

二:查詢檔案

1、查詢xx開頭的檔案並複製到某個資料夾下

find ./ -name "xx*.jar" -exec cp {} ./gateway \;

注:分號必須加上

2、從當前目錄開始查詢所有副檔名為.log的文字檔案,並找出包含”error”的行

find . -name “*.log” | xargs grep “error”

3、查詢當前目錄下副檔名以.log結尾的檔案並刪除

find ./ -name "*.log" | xargs rm -f