1. locate
Updated
升级文件信息数据库
Locate
在数据库中查找
locate foo
● locate -r '\.foo$'
支持基本正则表达式
● Useful options
-i
:
忽略文件名大小写
-n
:显示指定前几行信息
如:
-n
显示前十行匹配到的结果
--regex
支持扩展正则表达式
Locate --regex
“
\<issue\> | <passwd\>
”
2
.
Find
的作用
● find [directory...] [criteria...]
● Searches directory trees in real-time
Slower but more accurate than locate
CWD is used if no starting directory given
All files are matched if no criteria given
● Can execute commands on found files
● May only search directories where the user
has read and execute permission
3
.
find
命令的格式:
find [options] [path] [conditions] [-action]
用
find
查找时,路径省略的话
是当前目录
Find /etc �Cname “*passwd*” �Cls
-ls
是
find
下的一个动作
Find /etc �Cname “*passwd*”
�Cexec chmod 700 {} \;
用
find
查找到之后执行
chmod
命令
改为权限
700 {}
代表全部文件
-exec
不交互式
-ok
交互式
Find /etc �Cname “*passwd*” | xargs command
Xargs
可执行命令
-name
后加文件名 区分大小写
-iname
同上,但不区分大小写
-lname
查找链接名
当使用通配符时,查找条件必须用引号引起
-user
查找属于用户的文件
-group
查找文件属组
-nogroup
匹配没有属组的文件
-nouser
匹配没有属主的文件
查找那些没有用户和组的文件,作为管理员经常使用。
查找时如果文件没有指明查找关系时,默认相与关系
相当于
�Ca
表示
and
-o
相或的关系
Find /etc �Cuser root �Ca �Cname “*passwd*” �Co �Cuser bin
查找
passwd
文件并且(
-a
)属于
root
的用户
或者(
-o
)属于
bin
的用户
优先级关系
�Cnot > -a >-o
-perm
权限匹配
-perm mode
精确匹配
-perm /mode
查找范围内只要有一位满足条件
即将显示
0
表示此用户段不检查
-perm �Cmode
三个用户必须同时匹配,以为即可
-uid
:文件属主
uid
号
-gid
:文件属组的
gid
号
-type
f :
普通文件
d
:目录文件
l
:链接文件
b
:块设备
c
:字符设备
p
:管道文件
s
:scoket文件,套接字
-size
b
:512
c
:byte
k:kb
M: mb
G:gb
Find ./ -size [+|-] 2M
查找大于或小于2兆文件
Time
注意:当单位统一时 ,查找时要注意转换
-atime [+|-]n +
表示从以前开始 到5天之前曾经访问 -5表示5天以内访问的
find and Access Times
●
find
can match by inode timestamps
m
-atime
when file was last read
m
-mtime
when file data last changed
m
-ctime
when file data or metadata last changed
●
Value given is in days
m
find -ctime -10
■
Files modified less than 10 days ago
-exec ls �Cl {} \;
必须以红色部分结尾 (不交互式)
-ok \;
(交互式)
Places->Search for Files...
●
Graphical tool for searching by
m
name
m
content
m
owner/group
m
size
m
modification time
当找文件比较多时,建议使用
xcargs ls �Cl
它是查找单个之后传送
效率高
对当前目录效率高
查找子目录的用
-exec
较好