Find
locate 搜索命令 使用:
#yum install -y mlocate 安装
updatedb 生成db数据库,服务器不建议在工作时间生成,使用计划任务在凌晨启动
#find /etc/ -name ‘sshd*‘ 模糊搜索,搜索/etc目录下name为sshd的文件或目录 #find /etc/ -type d -name "sshd*" 模糊搜索,只搜索/etc目录下name为sshd的目录 #find /etc/ -type f -name "sshd*" 模糊搜索,只搜索/etc目录下name为sshd的文件
-type l 为连接文件
-type b 为block块设备
#stat 2.txt 查看 2.txt的time状态信息
参数:
atime = access time 访问时间
mtime = modify time 创建(修改)时间
ctime = change time 改动时间
更改了文件内容,ctime一定会发生改变
查看文件内容,access会发生改变
实例:
#find /etc/ -type f -mtime -1 #一天以内/etc目录下修改过的文件 #find /etc/ -type f -mtime +1 #一天前的/etc目录下修改过的文件 #find /etc/ -type f -mtime +1 -name "*.conf" #一天前的/etc目录下名为.conf 且修改过的文件 #find /etc/ -type f -o -mtime +1 -o -name "*.conf" #一天前的/etc目录下名为.conf 且修改过的文件 如上两个“-o”均是或的意思 #find /etc/ -type f -mmin -200 #200分钟以内/etc目录下修改过的文件
#find /etc/ -type f -mmin -200 -exec ls -l {} \; #200分钟以内/etc目录下修改过的文件, -exec 是指:执行 ls -l 命令, {} 表示对列出的结果再次交给ls一条条的执行
#find /etc/ -type f -mmin -200 -exec mv {} {}.bak \; #然后对符合条件的文件全部改名为.bak 在日常工作中会用到find去查找Size大于多少多少的文件或者目录时
#find /etc/ -type f -size -10M -exec ls -lh {} \; #列出来在/etc目录下 类型为文件且大于10M的 并ls -lh显示其详细信息
本文出自 “老七Linux运维管理” 博客,请务必保留此出处http://asd9577.blog.51cto.com/4291946/1934199
原文:http://asd9577.blog.51cto.com/4291946/1934199