小命令大做用---Linux 下快速查找

1. 如何快速查找大文件

好比根文件系統,最大的前10個文件?python

bashtree -finxs -L 5 / |sort -k2n -t '[' |tail

-f 列出全路徑,直觀,方便後面使用
-x 當前文件系統。好比/ 下面掛載個/wls卷(另一個ext4文件系統),就不會去查找
-L 列出路徑深度,越深越慢,5 層挺好的linux

實例:shell

shell[root@localhost mreald]# tree -finxs -L 5 / |sort -k2n -t '[' |tail 
[142363262]  //public/jdk1.7.0_67.tgz
[161505713]  //public/sosreport-CNSZ031314-702153-da593f.tar.bz2
[162204545]  //public/wlas.tar.gz
[167106418]  //root/slogs/2015-04-28_20:20:42pts-203public.log
[175738200]  //public/PA18CMSDMZ7603.out.20150511
[647942144]  //root/chkusr@10.11.100.141
[694297784]  //root/slogs/2015-05-15_11:03:00pts-255public.log
[700575507]  //root/slogs/2015-05-15_10:26:39pts-271public.log
[1101279689]  //root/slogs/2015-04-24_14:02:48pts-177public.log
[1956988917]  //chkusr/CNSZ040588.osbackup.tgz

若是空間滿了,又不能刪除,這樣處理數據庫

shellgzip /public/PA18CMSDMZ7603.out.20150511

就會生成 //public/PA18CMSDMZ7603.out.20150511.gz 並會自動刪除原文件apache

2. 查找一個路徑下面哪些目錄佔的空間大:

shelldu -hx --max-depth=1 /

--max-depth 設置列出層次
-x 只在當前文件系統bash

這樣能夠遞歸查詢哪些目錄最大app

3. 查找一個文件或者目錄或者路徑:

shelllocate filename/path/dirname/keyword

原理:cron 天天會跑一次 /etc/cron.daily/mlocate.cron ,把全部的文件路徑寫到一個小小數據庫裏面,查找的時候用索引,很是快速。code

好比 昨天老大的大做,修改 getPdf_IDG.py
但我想看看內容,找找在哪兒,下面就用0.4s 找到全部:blog

shell[mreald@localhost ~]$ locate getPdf_IDG.py
/b4p/apache/appsystems/epcisprint/common/apps/python/getPdf_IDG.py
/b4p/apache/appsystems/epcisprint/common/apps/python/jaspergetPdf_IDG.py
/wls/apache/appsystems/ap_epcis-print-stg2/common/apps/python/getPdf_IDG.py
/wls/apache/appsystems/ap_epcis-print-stg2/common/apps/python/jaspergetPdf_IDG.py

4.查找少不了find ,按大小,時間,類型等等。

生產的wls 卷99%了,怎麼辦?遞歸

shellfind /wls/applogs/rtlog/  -type f -size +100M  |grep \.out$ |xargs -I{} cp /dev/null  {}

先清理下,再慢慢處理別的大個文件

5. 查找被誤刪除,還在被應用使用的文件:

shelltree -fin /proc/|grep \(deleted\) |grep log
or
lsof +aL1 |grep delete |sort -k 7 -n

至於怎麼清理見:手把手教你清理 應用末釋放的大文件

6.查找文件內的關鍵字

shellgrep -c/-o/-n/-i/-l/-w/-v/-h

不用說了,不少選項,詳見: Linux命令 經常使用實例彙總(一)

原文:小命令大做用---linux 下快速查找

相關文章
相關標籤/搜索