running 5 Finding and Processing Files
2010-07-19 09:57
351 查看
本篇介绍 在linux上怎样快速查找到自己需要的文件和目录:
方法有#locate 和#find
#locate
使用权限: 所有人均可使用。
特点:基于数据库,检索效率高 但仅仅按照路径匹配 只要路径中出现查找的关键字 locate即认为匹配到 相对于find来说 locate受限于数据库的更新 可能不精确。
语法格式:
locate [-q] [-d ] [—database=]
locate [-r ] [—regexp=]
locate [-qv] [-o ] [—output=]
locate [-e ] [-f ] <[-l ] [-c] [-U ] [-u]>
locate [-Vh] [--version] [—help]
主要参数:
-u -U 建立数据库,-u 会由根目录开始,-U 则可以指定开始的位置。
-l 如果是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到的档案。这会使速度减慢,因为 locate必须至实际的档案系统中取得档案的权限资料。
-f 将特定的档案系统排除在外,例如我们没有到理要把 proc 档案系统中的档案放在数据库中。
-q 安静模式,不会显示任何错误讯息。
-n 至多显示 个输出。
-r 使用正规运算式做寻找的条件。
-o 指定数据库存的名称。
-d 指定数据库的路径
-h 显示辅助讯息
-v 显示更多的讯息
-V 显示程序的版本讯息
开始使用#locate
#locate file4 : 寻找所有叫 file4 的档案
#locate -n 100 filename : 寻找所有叫 filename 的档案,但最多只显示 100 个
#locate -u : 建立数据库
ps:#locate 刚刚装完系统需要不能立即使用 需要用-u命令或者#updatedb 手动创建数据库 过程比较漫长,如果想让数据库每天更新 可以在/etc/updatedb.conf里PRUNEFS PRUNEPATHS加入daily update=yes 即 每天更新
#locate –i ThisFile 查找ThisFile文件 忽略大小写
#locate –e dir1 搜索时 核对查找到的文件是否存在
#locate –r “\<issue\>” 会搜到如下结果 -r选项可以支持标准正则表达式
/etc/issue
/etc/issue.net
/usr/share/man/man5/issue.5.gz
#locate --regex “\<issue\>|\<passwd\>” -–regexz 可以支持扩展正则表达式
/etc/issue
/etc/issue.net
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/usr/bin/passwd
#find 搜索命令
find命令非常强大 支持 文件名 时间戳 所有者 文件长度 文件类型 等等高级匹配
而且搜索到的结果准确 使用遍历目录的方式检索 可以在指定目录实时检索 结果准确 但没有locate快
使用权限:所有人
使用规则:
#find [options] [path] [conditions] [-action]
选项 路径 操作
文件名匹配方式支持正则表达式
例子:
#find /etc -name “passwd” -name选项 精确匹配文件名
#find /etc -name “*passwd*” 制定模糊查询的时候才会模糊查询
#find 显示当前目录所有文件 包括子目录 子子目录
#find /etc 显示指定目录文件
#find /etc –name “passwd”-ls 查找到匹配文件之后显示详情
#find /etc –name “passwd”-exec chmod 700 {} \; 对匹配到的每个文件做chmod 700操作
#find /etc –name “passwd”-ok chmod 700 {} \; 交互式对匹配到的每个文件做chmod 700操作 操作前询问
{}为占位符 代表匹配到的每个文件 整个语句以空格\;结尾
#find /etc –name “*passwd*” |xargs chmod 744
#find /etc –user redhat 找到属主为redhat 的文件 也可以-group –nouser -nogroup
#find /etc –user root –a –name "*passwd*" –o –name “*issue*” 先匹配x –a x 再匹配 -o后面的
可以指定 –a 表示与–o 表示或–not 或者!表示非 如果不指定 系统默认都为与 即&& 如果需要 可以在某两项两边加括号 \( \)提高优先级
-not –a –o 的优先级由高到低
!(a&&b)---> !a||!b
!(a||b) --->!a&&!b
匹配权限:
#find –perm mode 如 –perm 644 精确匹配644的文件
#find –perm /mode 如 –perm /444 只要有一类用户权限包含了444即可匹配 比444权限大的文件
#find –perm –mode
匹配大小:单位 M(MB) k(kb) c (byte)b(block)
#find ./ –size –2M匹配小于2M的
#find ./ –size +2M匹配大于2M的
#find ./ –size –1024k 不可写作-1M 否则将匹配不到 它认为0<file<1M的 都算作1M了 所以只能找到0k的
匹配时间戳:
默认为天
#find –n 为n天之内的 即 当前时间减去n 到现在的 +n 为n天之前的 即当前时间-n的那天之前的
-newer 比文件最近一次访问时间更短的
-atime 访问时间 天
-mtime 修改时间 如文件内容
-ctime 元数据修改时间 如文件名
-amin 同上 但单位为分钟
-mmin
-cmin
方法有#locate 和#find
#locate
使用权限: 所有人均可使用。
特点:基于数据库,检索效率高 但仅仅按照路径匹配 只要路径中出现查找的关键字 locate即认为匹配到 相对于find来说 locate受限于数据库的更新 可能不精确。
语法格式:
locate [-q] [-d ] [—database=]
locate [-r ] [—regexp=]
locate [-qv] [-o ] [—output=]
locate [-e ] [-f ] <[-l ] [-c] [-U ] [-u]>
locate [-Vh] [--version] [—help]
主要参数:
-u -U 建立数据库,-u 会由根目录开始,-U 则可以指定开始的位置。
-l 如果是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到的档案。这会使速度减慢,因为 locate必须至实际的档案系统中取得档案的权限资料。
-f 将特定的档案系统排除在外,例如我们没有到理要把 proc 档案系统中的档案放在数据库中。
-q 安静模式,不会显示任何错误讯息。
-n 至多显示 个输出。
-r 使用正规运算式做寻找的条件。
-o 指定数据库存的名称。
-d 指定数据库的路径
-h 显示辅助讯息
-v 显示更多的讯息
-V 显示程序的版本讯息
开始使用#locate
#locate file4 : 寻找所有叫 file4 的档案
#locate -n 100 filename : 寻找所有叫 filename 的档案,但最多只显示 100 个
#locate -u : 建立数据库
ps:#locate 刚刚装完系统需要不能立即使用 需要用-u命令或者#updatedb 手动创建数据库 过程比较漫长,如果想让数据库每天更新 可以在/etc/updatedb.conf里PRUNEFS PRUNEPATHS加入daily update=yes 即 每天更新
#locate –i ThisFile 查找ThisFile文件 忽略大小写
#locate –e dir1 搜索时 核对查找到的文件是否存在
#locate –r “\<issue\>” 会搜到如下结果 -r选项可以支持标准正则表达式
/etc/issue
/etc/issue.net
/usr/share/man/man5/issue.5.gz
#locate --regex “\<issue\>|\<passwd\>” -–regexz 可以支持扩展正则表达式
/etc/issue
/etc/issue.net
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/usr/bin/passwd
#find 搜索命令
find命令非常强大 支持 文件名 时间戳 所有者 文件长度 文件类型 等等高级匹配
而且搜索到的结果准确 使用遍历目录的方式检索 可以在指定目录实时检索 结果准确 但没有locate快
使用权限:所有人
使用规则:
#find [options] [path] [conditions] [-action]
选项 路径 操作
文件名匹配方式支持正则表达式
例子:
#find /etc -name “passwd” -name选项 精确匹配文件名
#find /etc -name “*passwd*” 制定模糊查询的时候才会模糊查询
#find 显示当前目录所有文件 包括子目录 子子目录
#find /etc 显示指定目录文件
#find /etc –name “passwd”-ls 查找到匹配文件之后显示详情
#find /etc –name “passwd”-exec chmod 700 {} \; 对匹配到的每个文件做chmod 700操作
#find /etc –name “passwd”-ok chmod 700 {} \; 交互式对匹配到的每个文件做chmod 700操作 操作前询问
{}为占位符 代表匹配到的每个文件 整个语句以空格\;结尾
#find /etc –name “*passwd*” |xargs chmod 744
#find /etc –user redhat 找到属主为redhat 的文件 也可以-group –nouser -nogroup
#find /etc –user root –a –name "*passwd*" –o –name “*issue*” 先匹配x –a x 再匹配 -o后面的
可以指定 –a 表示与–o 表示或–not 或者!表示非 如果不指定 系统默认都为与 即&& 如果需要 可以在某两项两边加括号 \( \)提高优先级
-not –a –o 的优先级由高到低
!(a&&b)---> !a||!b
!(a||b) --->!a&&!b
匹配权限:
#find –perm mode 如 –perm 644 精确匹配644的文件
#find –perm /mode 如 –perm /444 只要有一类用户权限包含了444即可匹配 比444权限大的文件
#find –perm –mode
匹配大小:单位 M(MB) k(kb) c (byte)b(block)
#find ./ –size –2M匹配小于2M的
#find ./ –size +2M匹配大于2M的
#find ./ –size –1024k 不可写作-1M 否则将匹配不到 它认为0<file<1M的 都算作1M了 所以只能找到0k的
匹配时间戳:
默认为天
#find –n 为n天之内的 即 当前时间减去n 到现在的 +n 为n天之前的 即当前时间-n的那天之前的
-newer 比文件最近一次访问时间更短的
-atime 访问时间 天
-mtime 修改时间 如文件内容
-ctime 元数据修改时间 如文件名
-amin 同上 但单位为分钟
-mmin
-cmin
相关文章推荐
- RH033 Unit13 Finding and Processing Files
- RH033 Unit 13 Finding and Processing Files
- RH033读书笔记(12)-Lab 13 Finding and Processing Files
- Finding and Processing Files
- RH033 Unit13 Finding and Processing Files
- Executing and Running Applications and Files from Delphi Code
- nose1.3.7文档翻译--4.Finding and running tests
- Data Compression :: Running RLE Algorithm on BMP and PGM Image Files Using C#
- Inno Setup:Running files during installation and uninstallation
- Finding files on a *nix/Linux and sorting by size
- Scrapy学习笔记九--Downloading and processing files and images
- 第三章Databases and Database Files(2)
- swirl 2: Workspace and Files
- Google跨机房数据同步方案 Large-scale Incremental Processing Using Distributed Transactions and Notifications
- Processing Global Mouse and Keyboard Hooks in C#
- JHTP小结_第十五章_文件、流和对象序列化(Files, Streams, and Object Serialization)
- Doing more with files with Java and PeopleCode
- cat - concatenate files and print on the standard output
- [转载]C header files matching your running
- 《Microsoft Sql server 2008 Internals》读书笔记--第三章Databases and Database Files(1)