linux 文件搜索
- 命令:find
(1)按文件名
find [搜索范围路径] -name 【文件名称】(根据文件名查找)
find命令示例:find [搜索范围路径] -name
[root@master opt]# find /opt/ -name 11.txt
/opt/11.txt
[root@master opt]#
匹配任意字符 *
[root@master opt]# find /opt/ -name "*.txt"
/opt/112.txt
/opt/11.txt
/opt/212.txt
匹配指定字符 ?
[root@master opt]# find /opt/ -name "?1.txt"
/opt/11.txt
(2)按拥有者
find [搜索范围路径] -user(文件的所有者)
[root@master opt]# ll
总用量 0
-rw-r--r--. 1 root root 0 9月 16 14:47 112.txt
-rw-r--r--. 1 tom root 0 9月 16 14:47 11.txt
-rw-r--r--. 1 root root 0 9月 16 14:47 212.txt
[root@master opt]# find /opt/ -user tom
/opt/11.txt
(3)按文件大小
find [搜索范围路径] -size [(+n 大于 -n小于 n等于)]
b for 512-byte blocks (this is the default if no suffix is used)
c for bytes
w for two-byte words
k for Kilobytes (units of 1024 bytes)
M for Megabytes (units of 1048576 bytes)
G for Gigabytes (units of 1073741824 bytes)
注意,对于文件的大小是以b为单位。数据块大小是512bit
形如:如需查找100M的文件,那么就要知道100M为多少block?
100M = ? block
1M = 1024K
100M = 102400K
1K = 2 block
100M = 2*102400 block
[root@master opt]# find -size -204800
如果不想自己转换,可以使用其他单位,如c、K、M等。
[root@master opt]# find -size -100M
以时间查找
“`
天: ctime、atime、mtime
分钟:cmin、amin、mmin
c表示:change 改变文件属性的意思(比如所有者、所属组、权限变更)。
a表示:access 表示被访问过的意思(比如被查看过等)。
m表示:modify 更改内容的意思。
在时间前面添加:-表示之内,+表示之外
当前目录180天以内修改的文件
find . -mtime -180
find应用的连接符:
-a (and的意思,逻辑与)
-o(or的意思,逻辑或)
[root@master opt]# find . -mtime -180 -a -name "*.txt"
- 根据文件类型进行查找
-type
其中:f表示二进制文件,l表示软连接文件 d表示目录
[root@master opt]# find . -type f
which 文件搜索命令
[root@master opt]# which rm
alias rm='rm -i'
/bin/rm
“`