一、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]行