有时候我们忘记文件存放在哪里了,我们只知道文件的名字或者名字的部分字节,可以使用find命令来快速查找:
# find / -name *node10*
/var/lib/libvirt/images/rh7_node10.img
这里我要找的是一个名字里面包含有node10字样的文件,很快就能找出它的位置了。
*代表通配符,-name代表按名字查找, /表示在根目录下查找。
如果记得完整的文件名字,也可以使用locate快速查找
[root@localhost ~]# locate main.cf
/etc/postfix/main.cf
/usr/libexec/postfix/main.cf
/usr/share/doc/postfix-2.10.1/main.cf.default
find也可以按类型查找
[root@localhost ~]# find /tmp/cluster/ -type d
[root@localhost ~]# find /tmp/cluster/ -type f
同时可以修改权限
find /tmp/cluster/ type d -exec chomod 755 { } \;
按照大小查找
[root@localhost ~]# find /boot/ -size +5M 查找大于5M的文件
/boot/initrd-plymouth.img
/boot/initramfs-0-rescue-e783146fd26f448d951f5c739b136d2f.img
/boot/initramfs-3.10.0-327.el7.x86_64.img
/boot/initramfs-3.10.0-327.el7.x86_64kdump.img
[root@localhost ~]# find /boot/ -mtime -5 查找5天内改动的文件