文件查找
grep:文件内容过滤
grep '查找的内容' 路径
例1:
grep 'root' /etc/passwd
#从/etc/passwd 下过滤root字段
例2:
grep -R 'logout' /root
#在root目录中查找包含logout的文件
查找命令
[root@localhost ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@localhost ~]# which cd
/usr/bin/cd
[root@localhost ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
find文件查找
find 路径 条件 根路径相关的操作符 [-exec 动作]
路径:
1.不写默认是当前路径
2.加路径
条件:
1.名称 -name
find / -name "file"
#查找文件名为file的文件
2.类型 -type
find / -type f
#查找文件类型为普通文件的文件
f:普通文件
d:目录
l:软链接
3.权限 -perm
find / -perm 744
#查找权限为744的文件
4.大小 -size
find / -size +5M -a -10M
#查找大于5M小于10M的文件(-a与 -o或)
5.时间
-atime =access 访问时间
-ctime =charge 修改时间 文件属性改变时间会改变
-mtime =modify 改变时间 内容修改时间会随着改变
find / -atime +1 #访问时间在一天前的文件
find / -mttime +1 #修改时间在一天前的文件
find / -ctime +1 #属性修改时间在一天之前的
文件查找后续操作
命令:
find / -name "*.conf" -exec cp {} /opt \;
查找以。conf结尾的文件,并将他们复制到/opt
#命令结束一find / -name "*.conf" 定要加上\;
find / -name "*.conf" | xarges -i cp {} /opt
查找以。conf结尾的文件,并将他们复制到/opt