1 / 15

红帽企业 Linux 用户基础 RHA030

红帽企业 Linux 用户基础 RHA030. 13 单元. 查找和处理文件. 目标. 通过本单元的学习,你将能够: 使用 locate 使用 find 使用 Gnome 得查找工具. locate. 向预建数据库询问系统上文件的路径 数据库必须是管理员更新的 完整的路径将被查找,而不止是文件名 对于被搜索目录,用户要拥有可读和可执行的权限. Locate 例子. Locate passwd, 查找名字或路径中包含 passwd 的文件 有用的选项 -i 进行大小写不敏感的查找 -n X 只列出 X 打头的

zody
Télécharger la présentation

红帽企业 Linux 用户基础 RHA030

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 红帽企业Linux用户基础RHA030

  2. 13单元 查找和处理文件

  3. 目标 • 通过本单元的学习,你将能够: • 使用locate • 使用find • 使用Gnome得查找工具

  4. locate 向预建数据库询问系统上文件的路径 数据库必须是管理员更新的 完整的路径将被查找,而不止是文件名 对于被搜索目录,用户要拥有可读和可执行的权限

  5. Locate例子 Locate passwd,查找名字或路径中包含passwd的文件 有用的选项 -i 进行大小写不敏感的查找 -n X 只列出X打头的 -e DIR1,DIR2…不搜索目录DIR1,DIR2等等

  6. find Find [dir1 dir2 …][criteria…] 实时搜索目录树 比locate慢但更精确 如果不给定开始目录,就用CWD 如果不给定criteria,所有文件都匹配 在找到的文件上可以执行命令 对于被搜索目录,用户要拥有可读和可执行的权限

  7. 基础的find例子 • find –name snow.png 在当前目录下查找名为snow.png的文件 • find –iname snow.png 在当前目录下查找文件名字为snow.png,SNOW.PNG,等等,大小写不敏感 • find / -name *.txt 在整个系统中查找以.txt结尾的文件 • find /etc –name *pass* 在/etc目录下查找名字包含pass的文件 • find /home –user joe –group joe 在/home目录下查找所有者是joe并且组也是joe的文件

  8. find与逻辑操作 • 默认匹配是与 • 可以用-o或者是-not表示”或”或者是”否定” • 括号可以用来检测逻辑操作的顺序,但必须用斜线转义 • find –user joe –not –group joe • find –user joe –o –user jane • find –not \( -user joe –o –user jane \)

  9. find与权限 • 能用名字或id匹配所属关系 • find / -user joe –o –uid 500 • 能匹配八进制或符号权限 • find –perm 755 会匹配755的模式 • find –perm +222会匹配只要任何用户能写的模式 • find –perm -222会匹配所有用户都可以写的模式 • find –perm -002会匹配其他人可以写的模式

  10. find 与数字标准 • 许多查找标准采用数字值 • find –size 10M 大小等于10M的文件 • find –size +10M 大小超过10M的文件 • Find –size -10M 大小少于10M的文件 • 其他修饰符也有效,如:k代表KB,G代表GB等等

  11. find与访问时间 • find可以通过节点时间戳匹配 • -atime 文件是最后被读的 • -mtime 文件数据最后被修改的 • -ctime 文件数据或元数据最后被修改的 • 给定值是天 • find /tmp –ctime +10 /tmp下10天以前被修改的文件 • 可以使用分钟的值 • -amin • -mmin • -cmin • find /etc –amin -60

  12. 用find执行命令 • 在找到的文件上可以执行命令 • 必须用 –exec 或者-ok打头执行命令 • -ok在对每个文件进行动作前提示 • 命令必须以空格+斜线(“ \”)结尾 • 可以使用{}作为文件名字占位符 • find –size +100M –ok mv {} /tmp/largefiles/ \

  13. find 执行例子 • find –name “*.conf” –exec cp {} {}.orig \; 备份当前目录下的配置文件,加.orig扩展名 • find /tmp –ctime +3 –user joe –ok rm {} \;提示删除Joe的3天以前的临时文件 • find ~ -perm -002 –exec chmod o-w {} \;定位你的根录下其他用户可写的文件 • find /home –type d –ls 做一个/hom/目录下所有目录ls –l风格的显示列表 • find /data –type f –perm 644 –name *.sh –ok chmod 755 {} \;在/data/目录下查找以.sh结尾的权限模式为644的文件,并且把他们增加为可以执行的。

  14. Gnome搜索工具 • Places->Search Tool • 通过如下匹配的图形搜索工具 • 名字 • 内容 • 用户/组 • 大小 • 修改时间

  15. 结束 • 问题和答案 • 摘要 • 用locate很快的查找不是很新的文件 • 用find搜索基于很明确的标准的文件,并且可选择在匹配的文件上执行命令 • 使用Gnome搜索工具,直观的但很强大的GUI搜索工具

More Related