补充

locate 

locate 命令可以在搜寻数据库时快速找到档案,数据库由updatedb程序来更新,updatedb是由cron daemon周期性建立的,locate命令 在搜寻数据库时比由整个由硬盘资料来搜寻资料来得快,

但locate所找到的档案若是最近才建立或 刚更名的,可能会找不到,在内定值 中,updatedb每天会跑一次,可以由修改crontab来更新设定值。(etc/crontab)

 

搜索alm的bin目录下所有以i/I开头的文件

locate ~/alm/bin/I* -i   #-i表示不区分大小写


whereis

要查找的二进制程序、源文件和man手册页的指令名。

说明:whereis -m svn查出说明文档路径,whereis -s svn找source源文件。

 

 

find

根据名称进行搜索

find /home -name "*.txt"
find . -name "*.txt" -o -name "*.pdf" 
find /home ! -name "*.txt"
find . -regex ".*\(\.txt\|\.pdf\)$"


根据文件类型进行搜索

find . -type 类型参数

类型参数列表:

  • 普通文件
  • 符号连接
  • d 目录
  • 字符设备
  • 块设备
  • 套接字
  • Fifo

find . -maxdepth 3 -type f

根据文件时间戳进行搜索

find . -type f 时间戳

UNIX/Linux文件系统每个文件都有三种时间戳:

  • 访问时间(-atime/天,-amin/分钟):用户最近一次访问时间。
  • 修改时间(-mtime/天,-mmin/分钟):文件最后一次修改时间。
  • 变化时间(-ctime/天,-cmin/分钟):文件数据元(例如权限等)最后一次修改时间。

搜索最近七天内被访问过的所有文件

find . -type f -atime -7

搜索恰好在七天前被访问过的所有文件

find . -type f -atime 7

搜索超过七天内被访问过的所有文件

find . -type f -atime +7

搜索访问时间超过10分钟的所有文件

find . -type f -amin +10

找出比file.log修改时间更长的所有文件

find . -type f -newer file.log



根据文件大小进行搜索

find . -type f -size 文件大小单元

 

文件大小单元:

  • b —— 块(512字节)
  • c —— 字节
  • w —— 字(2字节)
  • k —— 千字节
  • M —— 兆字节
  • G —— 吉字节

 

搜索大于10KB的文件

find . -type f -size +10k

搜索小于10KB的文件

find . -type f -size -10k

搜索等于10KB的文件

find . -type f -size 10k



根据文件权限/所有权进行匹配

当前目录下搜索出权限为777的文件

find . -type f -perm 777

找出当前目录下权限不是644的php文件

find . -type f -name "*.php" ! -perm 644

找出当前目录用户tom拥有的所有文件

find . -type f -user tom

找出当前目录用户组sunk拥有的所有文件

find . -type f -group sunk

 

 

借助-exec选项与其他命令结合使用 (\; 做结尾)

 

查找当前目录下所有.txt文件并把他们拼接起来写入到all.txt文件中

 

find . -type f -name "*.txt" -exec cat {} \;> all.txt

 

将30天前的.log文件移动到old目录中

 

find . -type f -mtime +30 -name "*.log" -exec cp {} old \;

 

找出当前目录下所有.txt文件并以“File:文件名”的形式打印出来

 

find . -type f -name "*.txt" -exec printf "File: %s\n" {} \;

 

搜索但跳出指定的目录

find . -path "./sk" -prune -o -name "*.txt" -print

 

列出所有长度为的文件

find . -empty

 

 

posted on 2018-08-24 11:07  zhco  阅读(154)  评论(0编辑  收藏  举报

导航