find命令总结

find命令总结

find [path] [option] [action]

选项与参数:

  • 与时间有关的参数,共有-atime,-ctime,与-mtime,下面以mtime为例。

-mtime n:n为数字,意义为在n天之前的一天以内被更改过的文件。
-mtime +n:列出n天之前(不含n天本身)被更改过的文件名。
-mtime -n:列出n天之内(含有n天本身)被更改过的文件名。
-newer file:file为一个存在的文件,别处比file还要新的文件。

将/etc/下24小时内有改动(mtime)的文件列出

# find /etc/ -mtime 0
/etc/
/etc/resolv.conf
/etc/group-
/etc/gshadow-
/etc/group
/etc/passwd-
/etc/gshadow
/etc/shadow-
/etc/passwd
/etc/shadow
/etc/cron.daily

将/etc/下5天以前修改过的文件列出来,只显示前五个

# find /etc/ -mtime +5 | head -5
/etc/fstab
/etc/crypttab
/etc/mtab
/etc/grub.d
/etc/grub.d/00_header

将/etc/下5天内修改过的文件列出来

# find /etc/ -mtime -5 
/etc/
/etc/resolv.conf
/etc/group-
/etc/gshadow-
/etc/group
/etc/passwd-
/etc/gshadow
/etc/shadow-
/etc/passwd
/etc/shadow
/etc/cron.daily
/etc/tuned/active_profile
/etc/tuned/profile_mode

将/etc/比/etc/passwd新的文件列出

# find /etc/ -newer  /etc/passwd
/etc/
/etc/resolv.conf
/etc/group-
/etc/gshadow-
/etc/group
/etc/gshadow
/etc/shadow
  • 与使用者或用户组有关系的

-user name 查找用户账号为name的文件。
-group name 查找用户组为name的文件。
-uid n: n为数字,这个数字是使用者的账号id,亦即uid,这个uid是记录在/etc/passwd里面
-gid n: n为数字,这个数字是使用者的用户组的id,亦即gid,这个gid是记录在/etc/group里面
-nouser:查找文件拥有者不在/etc/passwd中的文件
-nogroup:查找文件拥有者不在/etc/group中的文件

查找/etc/下用户拥有者为root的文件

# find /etc/ -user root  | head -5
/etc/
/etc/fstab
/etc/crypttab
/etc/mtab
/etc/resolv.conf

查找系统中不属于任何人的文件:

# find / -nouser
  • 与文件权限及名称有关的参数

-name filename //查找文件名为filename的名称
-size ±SIZE //查找比SIZE还要大(+)或小(-)的文件
-type TYPE 查找文件的类型为TYPE的文件。 一般为:正规文件(f),设备文件(b,c),目录(d),链接文件(l),socket(s)以及fifo(p)等
-perm mode //查找文件权限刚好等于mode的文件
-perm -mode //查找文件权限(必须全部囊括)
-perm /mode //查找文件(包含任意mode的)

查找大于100M的文件。

# find / -size +100M
/proc/kcore
find: ‘/proc/11850/task/11850/fd/6’: No such file or directory
find: ‘/proc/11850/task/11850/fdinfo/6’: No such file or directory
find: ‘/proc/11850/fd/5’: No such file or directory
find: ‘/proc/11850/fdinfo/5’: No such file or directory
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/usr/lib/locale/locale-archive

查找名称为passwd的文件

# find / -name passwd
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd

查找套接字文件

# find / -type s
/dev/log
/run/NetworkManager/private-dhcp
/run/vmware/guestServicePipe
/run/dbus/system_bus_socket
/run/lvm/lvmpolld.socket
/run/lvm/lvmetad.socket
/run/udev/control
/run/systemd/shutdownd
/run/systemd/private
/run/systemd/journal/socket

查找fifo文件

# find / -type p
/run/dmeventd-client
/run/dmeventd-server
/run/systemd/inhibit/1.ref
/run/systemd/sessions/19.ref
/run/systemd/sessions/1.ref
/run/systemd/initctl/fifo

查找文件权限为4755的文件:

# find / -perm 4755
/usr/bin/fusermount
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/mount
/usr/bin/chage
/usr/bin/su
/usr/bin/umount
/usr/bin/crontab
/usr/bin/pkexec
/usr/bin/passwd
/usr/sbin/pam_timestamp_check
/usr/sbin/unix_chkpwd
/usr/sbin/usernetctl
/usr/lib/polkit-1/polkit-agent-helper-1

查找文件任意权限包括4777的文件:

# find /etc -perm /4777  | head -5
/etc
/etc/fstab
/etc/crypttab
/etc/mtab
/etc/resolv.conf
  • 额外执行的操作

-exec commad : command为其他命令,-exec后面可再接额外的命令来处理查找到的结果。

# find / -perm 4755 -exec ls -lh {} \;
-rwsr-xr-x. 1 root root 32K Oct 31  2018 /usr/bin/fusermount
-rwsr-xr-x. 1 root root 77K Oct 31  2018 /usr/bin/gpasswd
-rwsr-xr-x. 1 root root 41K Oct 31  2018 /usr/bin/newgrp
-rwsr-xr-x. 1 root root 44K Oct 31  2018 /usr/bin/mount
-rwsr-xr-x. 1 root root 63K Oct 31  2018 /usr/bin/chage
-rwsr-xr-x. 1 root root 32K Oct 31  2018 /usr/bin/su
-rwsr-xr-x. 1 root root 32K Oct 31  2018 /usr/bin/umount
-rwsr-xr-x. 1 root root 57K Apr 11  2018 /usr/bin/crontab
-rwsr-xr-x. 1 root root 24K Oct 31  2018 /usr/bin/pkexec
-rwsr-xr-x. 1 root root 28K Jun 10  2014 /usr/bin/passwd
-rwsr-xr-x. 1 root root 11K Apr 11  2018 /usr/sbin/pam_timestamp_check
-rwsr-xr-x. 1 root root 36K Apr 11  2018 /usr/sbin/unix_chkpwd
-rwsr-xr-x. 1 root root 12K Oct 31  2018 /usr/sbin/usernetctl
-rwsr-xr-x. 1 root root 16K Oct 31  2018 /usr/lib/polkit-1/polkit-agent-helper-1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值