linux基础(15)--locate、find命令的使用--RHEL6.5

来源:互联网 发布:endnote mac 编辑:程序博客网 时间:2024/05/18 20:07

  本文涉及命令: locate find

1. locate

  定位指定文件的位置。

  使用locate前建议先更新一下数据库,updatedb, 虽然此数据库会自动进行更新,但是在每晚的2:00进行,因此更新之后下次更新之前新增的文件使用locate时无法定位到的。

  updatedb

  locate passwd

2. find

  查找文件,可通过对此命令的查找条件进行各种组合查询出符合自己需要的文件位置。

  (1)根据用户和组查找

  find /home -user user1

  find /home -group group1

  (2)根据文件类型查找

  f 文件, d 目录, l 连接, p 管道,c 字符文件,b 块文件 ,s socket文件

  find /home -type f

  find /home -type d

  (3)根据名字查找

  find /home -name "file1"

  (4)根据大小查找

  大于2M

  find /home -size +2M

  小于2M

  find /home -size -2M

  以M为单位显示文件信息

  ll -h /home

  (4)根据时间查找

  ctime:change time, 如文件属性

  mtime:modify time, 文件内容被修改

  atime:access time, 文件被读过

  ll 默认列出的是文件的mtime。

  列出文件的atime:

  ls -lu   /home

  列出文件的ctime:

  ls -lc /home

  列出文件的mtime:

  ls -l /home

  (5)根据文件权限查找

  权限等于755的文件

  find /home -perm 755

  权限至少为755的文件:

  find /home -perm -755

  (6)查找目录的深度

  find /home -maxdepth 1

  find /home -maxdepth 2

  (7)多条件查找

  a    -and

  o    -or

  !     -not

  在/home下权限至少为002的文件:

  find /home -type f -a -perm -002

  (8)-exec

  接后续命令

  删除/root下的普通文件:

  find /home -type f -exec rm -f {} \;

 

 

0 0
原创粉丝点击