在linux 系统字符界面查找文件,find是非常有用的,下面介绍一些常用的find 使用方法:
find ./表示在当前路径下查找,
find /etc 表示在etc文件下查找
find -type f 表示查找文件
find -type d 表示查找目录
find -name 1.txt 表示查找文件名称是1.txt 的文件
find -size 500M 表示查找大小为500兆的文件
find -perm 644 表示查找文件或目录权限是644/rw-r--r--
stat 1.txt 表示查看当前文件修改的时间,属性修改的时间
查找/var目录下属主是root并且属组是mail的所有文件
[root@localhost ~]# find /var -type f -user root -group mail
/var/spool/mail/root
[root@localhost ~]#
查找/usr/目录下不属于root,bin的文件
[root@localhost ~]# find /usr -type f -not -user root -a -not -user bin
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
[root@localhost ~]#
atime,amin,ctime,cmin,mtime,mmin
atime,amin:文件被查看时间
ctime,cmin:文件内容被修改的时间
mtime,mmin:文件属性被修改的时间
查找/etc目录下最近一周内容修改过且不属于root用户的文件
[root@localhost ~]# find /etc -type f -mtime -7 -not -user root
[root@localhost ~]#
find -ctime +1 表示1天以上
find -ctime -1 表示1天以内
find -ctime 1 刚好一天
find -nouser 没有属主
find -nogroup 每一属组
查找当前系统上没有属主或属组且最近一天内访问的过的文件并将属主和属组都改为root
find / -type f -nouser -a nogroup -atime -1|xargs chown root.root
查找/etc目录下大于1M的文件,并将文件名写入到/tmp/test文件中
find /etc -size +1M -type f >>/tmp/test
查找/etc目录下所有用户没有写权限的文件并列出详细信息
find /etc -type -f -not -perm /222
先找出所有有写权限的文件再取反就找到结果。
多个文件个并为一个
find /tmp -name "*.sh"|xargs cat 2>&1 1>>cc.txt