一、find find <指定目錄> <指定條件> <指定動做> 文件名 find /home -name "*.txt" 查找以.txt結尾的文件 find /home -iname "*.txt" 忽略大小寫 文件類型 f 普通文件 l 符號鏈接 d 目錄 c 字符設備 b 塊設備 s 套接字 p Fifo 目錄深度 find . -maxdepth 3 -type f find . -mindepth 2 -type f 文件時間戳 訪問時間(-atime/天,-amin/分鐘):用戶最近一次訪問時間。 修改時間(-mtime/天,-mmin/分鐘):文件最後一次修改時間。 變化時間(-ctime/天,-cmin/分鐘):文件數據元(例如權限等)最後一次修改時間。 find . -type f -atime -7 文件大小 find . -type f -size 文件大小單元 b —— 塊(512字節) c —— 字節 w —— 字(2字節) k —— 千字節 M —— 兆字節 G —— 吉字節 刪除匹配 find . -type f -name "*.txt" -delete 權限匹配 find . -type f -perm 777 find . -type f -name "*.php" ! -perm 644 當前目錄下搜索出權限爲777的文件 find . -type f -user tom 找出當前目錄用戶tom擁有的全部文件 find . -type f -group sunk 找出當前目錄用戶組sunk擁有的全部文件 長度爲0 find .empty 二、locate 不搜索具體目錄,而是搜索一個數據庫/var/lib/locatedb locate /etc/sh 三、grep global search regular expression(RE) and print out the line,全面搜索正則表達式並把行打印出來 ps -ef | grep java 顯示java進程信息 ps -ef | grep java -c 統計java進程個數 grep -n "aaa" a.txt 搜素文字 或操做 grep -E '123|abc' filename // 找出文件(filename)中包含123或者包含abc的行 egrep '123|abc' filename // 用egrep一樣能夠實現 awk '/123|abc/' filename // awk 的實現方式 與操做 grep pattern1 files | grep pattern2 //顯示既匹配 pattern1 又匹配 pattern2 的行 grep -i pattern files //不區分大小寫地搜索。默認狀況區分大小寫, grep -l pattern files //只列出匹配的文件名, grep -L pattern files //列出不匹配的文件名, grep -w pattern files //只匹配整個單詞,而不是字符串的一部分(如匹配‘magic’,而不是‘magical’), grep -C number pattern files //匹配的上下文分別顯示[number]行