Linux操作系统的文件查找工具locate和find命令常用参数介绍

          Linux操作系统的文件查找工具locate和find命令常用参数介绍

                                             作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

一.非实时查找(数据库查找)locate工具 

locate命令的工作原理剖析:
  用locate命令在搜索文件列表的时候,它并不是去硬盘中实时搜索文件,而是事先把磁盘上的所有文件预建文件索引数据库(即"/var/lib/mlocate.db"),查询时依赖于事先构建的索引(索引的构建是在系统较为空闲时自动进行,即周期性任务),这就是为什么它搜索文件非常快的原因。
  但这并不是说安装操作系统或者刚刚安装完locate软件,就会立即有"/var/lib/mlocate.db"数据库的,而是需要等待一段时间后它才会自动生成,而这个等待时间是不确定的,因此我们可以使用update命令来手动生成该索引数据库文件。
  索引构建过程需要遍历整个根文件系统,极消耗资源,因此locate命令适合搜索比较稳定的文件,比如系统的启动脚本或系统配置文件之类的,因为他们不仅经常变化,基本上都可以搜索到,但是对于一些变化频率比较高的文件搜索起来locate就有点力不从心,需要咱们不断地手动更新数据库才能获取到最新的文件索引信息。

locate命令的工作特点:
  (1)查找速度快
  (2)模糊查找
  (3)非实时查找
  (4)搜索的文件是全路径,不仅仅是文件名
  (5)可能之搜索用户具备读取和执行权限的目录

locate语法格式:
  Usage: locate [OPTION]... [PATTERN]...
  常用选项:
    -i:
      不区分大小写。
    -n N:
      只例举前N个匹配项目。
    -r:
      使用正则biao a  

1>.安装locate数据库(最小化操作系统是没有安装locate命令的哟~)

[root@node101.yinzhengjie.org.cn ~]# yum -y install mlocate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package mlocate.x86_64 0:0.26-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================
 Package                       Arch                         Version                             Repository                  Size
=================================================================================================================================
Installing:
 mlocate                       x86_64                       0.26-8.el7                          base                       113 k

Transaction Summary
=================================================================================================================================
Install  1 Package

Total download size: 113 k
Installed size: 379 k
Downloading packages:
mlocate-0.26-8.el7.x86_64.rpm                                                                             | 113 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mlocate-0.26-8.el7.x86_64                                                                                     1/1 
  Verifying  : mlocate-0.26-8.el7.x86_64                                                                                     1/1 

Installed:
  mlocate.x86_64 0:0.26-8.el7                                                                                                    

Complete!
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# yum -y install mlocate 

2>.更新locate的数据库文件

[root@node101.yinzhengjie.org.cn ~]# locate hosts              #我们在安装locate命令时并不会立即生成数据索引文件。
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# updatedb                 #因此我们可以手动locate命令的数据库文件,如果文件已经存在则更新该数据库内容。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /var/lib/mlocate/mlocate.db    #数据库文件竟然自动创建出来啦
-rw-r----- 1 root slocate 2483967 Dec 12 09:15 /var/lib/mlocate/mlocate.db
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# touch f1.log              #我们此处创建一个文件
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll                    #该文件已经创建出来来
total 0
-rw-r--r-- 1 root root 0 Dec 12 09:21 f1.log
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate f1.log               #我们发现locate命令竟然找不到f1.log文件,这是由于locate的数据库文件还没有来得及更新
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# updatedb                 #于是于是我们手动更新数据库信息,将之前修改的内容都同步到locate数据库中
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate f1.log              #
/root/f1.log
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]#

3>.省略选项搜索关键词案例

[root@node101.yinzhengjie.org.cn ~]# locate hosts
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/selinux/targeted/active/modules/100/denyhosts
/etc/selinux/targeted/active/modules/100/denyhosts/cil
/etc/selinux/targeted/active/modules/100/denyhosts/hll
/etc/selinux/targeted/active/modules/100/denyhosts/lang_ext
/usr/lib64/security/pam_rhosts.so
/usr/share/ghostscript
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
/usr/share/doc/pam-1.1.8/html/sag-pam_rhosts.html
/usr/share/doc/pam-1.1.8/txts/README.pam_rhosts
/usr/share/ghostscript/conf.d
/usr/share/man/man5/hosts.allow.5.gz
/usr/share/man/man5/hosts.deny.5.gz
/usr/share/man/man5/hosts_access.5.gz
/usr/share/man/man5/hosts_options.5.gz
/usr/share/man/man8/pam_rhosts.8.gz
/usr/share/vim/vim74/ftplugin/denyhosts.vim
/usr/share/vim/vim74/ftplugin/hostsaccess.vim
/usr/share/vim/vim74/syntax/denyhosts.vim
/usr/share/vim/vim74/syntax/hostsaccess.vim
/usr/share/zsh/site-functions/_sd_hosts_or_user_at_host
/var/cache/yum/x86_64/7/timedhosts
/var/cache/yum/x86_64/7/timedhosts.txt
/var/www/html/phpMyAdmin/examples/config.manyhosts.inc.php
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate hosts            #查找文件名包含hosts的文件名或者路径。

4>."-i"选项案例

[root@node101.yinzhengjie.org.cn ~]# locate HOSTS          #我们搜索大写的关键词是搜不到有关HOSTS文件名称或路径的。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate -i HOSTS        #我们使用"-i"选项可以忽略文件大小写,瞬间就可以匹配到包含hosts的文件名称或路径啦。
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/selinux/targeted/active/modules/100/denyhosts
/etc/selinux/targeted/active/modules/100/denyhosts/cil
/etc/selinux/targeted/active/modules/100/denyhosts/hll
/etc/selinux/targeted/active/modules/100/denyhosts/lang_ext
/usr/lib64/security/pam_rhosts.so
/usr/share/ghostscript
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
/usr/share/doc/pam-1.1.8/html/sag-pam_rhosts.html
/usr/share/doc/pam-1.1.8/txts/README.pam_rhosts
/usr/share/ghostscript/conf.d
/usr/share/man/man5/hosts.allow.5.gz
/usr/share/man/man5/hosts.deny.5.gz
/usr/share/man/man5/hosts_access.5.gz
/usr/share/man/man5/hosts_options.5.gz
/usr/share/man/man8/pam_rhosts.8.gz
/usr/share/vim/vim74/ftplugin/denyhosts.vim
/usr/share/vim/vim74/ftplugin/hostsaccess.vim
/usr/share/vim/vim74/syntax/denyhosts.vim
/usr/share/vim/vim74/syntax/hostsaccess.vim
/usr/share/zsh/site-functions/_sd_hosts_or_user_at_host
/var/cache/yum/x86_64/7/timedhosts
/var/cache/yum/x86_64/7/timedhosts.txt
/var/www/html/phpMyAdmin/examples/config.manyhosts.inc.php
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate -i HOSTS          #我们使用"-i"选项可以忽略文件大小写,瞬间就可以匹配到包含hosts的文件名称或路径啦。

5>."-n"选项案例 

[root@node101.yinzhengjie.org.cn ~]# locate hosts
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/selinux/targeted/active/modules/100/denyhosts
/etc/selinux/targeted/active/modules/100/denyhosts/cil
/etc/selinux/targeted/active/modules/100/denyhosts/hll
/etc/selinux/targeted/active/modules/100/denyhosts/lang_ext
/usr/lib64/security/pam_rhosts.so
/usr/share/ghostscript
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
/usr/share/doc/pam-1.1.8/html/sag-pam_rhosts.html
/usr/share/doc/pam-1.1.8/txts/README.pam_rhosts
/usr/share/ghostscript/conf.d
/usr/share/man/man5/hosts.allow.5.gz
/usr/share/man/man5/hosts.deny.5.gz
/usr/share/man/man5/hosts_access.5.gz
/usr/share/man/man5/hosts_options.5.gz
/usr/share/man/man8/pam_rhosts.8.gz
/usr/share/vim/vim74/ftplugin/denyhosts.vim
/usr/share/vim/vim74/ftplugin/hostsaccess.vim
/usr/share/vim/vim74/syntax/denyhosts.vim
/usr/share/vim/vim74/syntax/hostsaccess.vim
/usr/share/zsh/site-functions/_sd_hosts_or_user_at_host
/var/cache/yum/x86_64/7/timedhosts
/var/cache/yum/x86_64/7/timedhosts.txt
/var/www/html/phpMyAdmin/examples/config.manyhosts.inc.php
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate -n 5 hosts          #之列出前5个匹配到的文件名称或路径名称
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/selinux/targeted/active/modules/100/denyhosts
/etc/selinux/targeted/active/modules/100/denyhosts/cil
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate -n 5 hosts          #之列出前5个匹配到的文件名称或路径名称

6>."-r"选项案例

[root@node101.yinzhengjie.org.cn ~]# locate -r "\.conf$"
/etc/GeoIP.conf
/etc/asound.conf
/etc/chrony.conf
/etc/dracut.conf
/etc/e2fsck.conf
/etc/host.conf
/etc/kdump.conf
/etc/krb5.conf
/etc/ld.so.conf
/etc/libaudit.conf
/etc/libuser.conf
/etc/locale.conf
/etc/logrotate.conf
/etc/man_db.conf
/etc/mke2fs.conf
/etc/nsswitch.conf
/etc/resolv.conf
/etc/rsyncd.conf
/etc/rsyslog.conf
/etc/sestatus.conf
/etc/sudo-ldap.conf
/etc/sudo.conf
/etc/sysctl.conf
/etc/updatedb.conf
/etc/vconsole.conf
/etc/yum.conf
/etc/NetworkManager/NetworkManager.conf
/etc/X11/xorg.conf.d/00-keyboard.conf
/etc/audisp/audispd.conf
/etc/audisp/plugins.d/af_unix.conf
/etc/audisp/plugins.d/syslog.conf
/etc/audit/auditd.conf
/etc/dbus-1/session.conf
/etc/dbus-1/system.conf
/etc/dbus-1/system.d/FirewallD.conf
/etc/dbus-1/system.d/com.redhat.tuned.conf
/etc/dbus-1/system.d/nm-dispatcher.conf
/etc/dbus-1/system.d/nm-ifcfg-rh.conf
/etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf
/etc/dbus-1/system.d/org.freedesktop.PolicyKit1.conf
/etc/dbus-1/system.d/org.freedesktop.hostname1.conf
/etc/dbus-1/system.d/org.freedesktop.import1.conf
/etc/dbus-1/system.d/org.freedesktop.locale1.conf
/etc/dbus-1/system.d/org.freedesktop.login1.conf
/etc/dbus-1/system.d/org.freedesktop.machine1.conf
/etc/dbus-1/system.d/org.freedesktop.systemd1.conf
/etc/dbus-1/system.d/org.freedesktop.timedate1.conf
/etc/dbus-1/system.d/teamd.conf
/etc/dbus-1/system.d/wpa_supplicant.conf
/etc/depmod.d/dist.conf
/etc/firewalld/firewalld.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf.modules.d/10-php.conf
/etc/ld.so.conf.d/kernel-3.10.0-957.el7.x86_64.conf
/etc/ld.so.conf.d/mariadb-x86_64.conf
/etc/lvm/lvm.conf
/etc/lvm/lvmlocal.conf
/etc/modprobe.d/dccp-blacklist.conf
/etc/modprobe.d/firewalld-sysctls.conf
/etc/modprobe.d/tuned.conf
/etc/openldap/ldap.conf
/etc/pki/ca-trust/ca-legacy.conf
/etc/plymouth/plymouthd.conf
/etc/prelink.conf.d/fipscheck.conf
/etc/prelink.conf.d/grub2.conf
/etc/prelink.conf.d/nss-softokn-prelink.conf
/etc/rsyslog.d/listen.conf
/etc/sasl2/smtpd.conf
/etc/security/access.conf
/etc/security/chroot.conf
/etc/security/group.conf
/etc/security/limits.conf
/etc/security/namespace.conf
/etc/security/pam_env.conf
/etc/security/pwquality.conf
/etc/security/sepermit.conf
/etc/security/time.conf
/etc/security/limits.d/20-nproc.conf
/etc/selinux/semanage.conf
/etc/selinux/targeted/setrans.conf
/etc/sysctl.d/99-sysctl.conf
/etc/systemd/bootchart.conf
/etc/systemd/coredump.conf
/etc/systemd/journald.conf
/etc/systemd/logind.conf
/etc/systemd/system.conf
/etc/systemd/user.conf
/etc/tuned/tuned-main.conf
/etc/udev/udev.conf
/etc/wpa_supplicant/wpa_supplicant.conf
/etc/yum/version-groups.conf
/etc/yum/pluginconf.d/fastestmirror.conf
/etc/yum/pluginconf.d/langpacks.conf
/etc/yum/protected.d/systemd.conf
/home/yinzhengjie/.pyenv/.pip/pip.conf
/home/yinzhengjie/.pyenv/cache/Python-3.6.9/Doc/docutils.conf
/home/yinzhengjie/.pyenv/cache/Python-3.6.9/Doc/tools/pydoctheme/theme.conf
/usr/lib/NetworkManager/conf.d/10-slaves-order.conf
/usr/lib/dracut/dracut.conf.d/01-dist.conf
/usr/lib/dracut/dracut.conf.d/01-microcode.conf
/usr/lib/dracut/dracut.conf.d/02-rescue.conf
/usr/lib/dracut/dracut.conf.d/50-nss-softokn.conf
/usr/lib/dracut/dracut.conf.d/76-phys-port-name.conf
/usr/lib/dracut/modules.d/40network/dhclient.conf
/usr/lib/dracut/modules.d/98syslog/rsyslog.conf
/usr/lib/dracut/modules.d/98systemd/dracut-tmpfiles.conf
/usr/lib/modprobe.d/dist-alsa.conf
/usr/lib/modprobe.d/dist-blacklist.conf
/usr/lib/sysctl.d/00-system.conf
/usr/lib/sysctl.d/10-default-yama-scope.conf
/usr/lib/sysctl.d/50-default.conf
/usr/lib/tmpfiles.d/cryptsetup.conf
/usr/lib/tmpfiles.d/etc.conf
/usr/lib/tmpfiles.d/httpd.conf
/usr/lib/tmpfiles.d/initscripts.conf
/usr/lib/tmpfiles.d/legacy.conf
/usr/lib/tmpfiles.d/libselinux.conf
/usr/lib/tmpfiles.d/lvm2.conf
/usr/lib/tmpfiles.d/mariadb.conf
/usr/lib/tmpfiles.d/pam.conf
/usr/lib/tmpfiles.d/python.conf
/usr/lib/tmpfiles.d/rpm.conf
/usr/lib/tmpfiles.d/sap.conf
/usr/lib/tmpfiles.d/selinux-policy.conf
/usr/lib/tmpfiles.d/sudo.conf
/usr/lib/tmpfiles.d/systemd-nologin.conf
/usr/lib/tmpfiles.d/systemd.conf
/usr/lib/tmpfiles.d/tmp.conf
/usr/lib/tmpfiles.d/tuned.conf
/usr/lib/tmpfiles.d/var.conf
/usr/lib/tmpfiles.d/x11.conf
/usr/lib/tuned/balanced/tuned.conf
/usr/lib/tuned/desktop/tuned.conf
/usr/lib/tuned/latency-performance/tuned.conf
/usr/lib/tuned/network-latency/tuned.conf
/usr/lib/tuned/network-throughput/tuned.conf
/usr/lib/tuned/powersave/tuned.conf
/usr/lib/tuned/recommend.d/50-tuned.conf
/usr/lib/tuned/throughput-performance/tuned.conf
/usr/lib/tuned/virtual-guest/tuned.conf
/usr/lib/tuned/virtual-host/tuned.conf
/usr/share/alsa/alsa.conf
/usr/share/alsa/cards/AACI.conf
/usr/share/alsa/cards/ATIIXP-MODEM.conf
/usr/share/alsa/cards/ATIIXP-SPDMA.conf
/usr/share/alsa/cards/ATIIXP.conf
/usr/share/alsa/cards/AU8810.conf
/usr/share/alsa/cards/AU8820.conf
/usr/share/alsa/cards/AU8830.conf
/usr/share/alsa/cards/Audigy.conf
/usr/share/alsa/cards/Audigy2.conf
/usr/share/alsa/cards/Aureon51.conf
/usr/share/alsa/cards/Aureon71.conf
/usr/share/alsa/cards/CA0106.conf
/usr/share/alsa/cards/CMI8338-SWIEC.conf
/usr/share/alsa/cards/CMI8338.conf
/usr/share/alsa/cards/CMI8738-MC6.conf
/usr/share/alsa/cards/CMI8738-MC8.conf
/usr/share/alsa/cards/CMI8788.conf
/usr/share/alsa/cards/CS46xx.conf
/usr/share/alsa/cards/EMU10K1.conf
/usr/share/alsa/cards/EMU10K1X.conf
/usr/share/alsa/cards/ENS1370.conf
/usr/share/alsa/cards/ENS1371.conf
/usr/share/alsa/cards/ES1968.conf
/usr/share/alsa/cards/Echo_Echo3G.conf
/usr/share/alsa/cards/FM801.conf
/usr/share/alsa/cards/FWSpeakers.conf
/usr/share/alsa/cards/FireWave.conf
/usr/share/alsa/cards/GUS.conf
/usr/share/alsa/cards/HDA-Intel.conf
/usr/share/alsa/cards/HdmiLpeAudio.conf
/usr/share/alsa/cards/ICE1712.conf
/usr/share/alsa/cards/ICE1724.conf
/usr/share/alsa/cards/ICH-MODEM.conf
/usr/share/alsa/cards/ICH.conf
/usr/share/alsa/cards/ICH4.conf
/usr/share/alsa/cards/Loopback.conf
/usr/share/alsa/cards/Maestro3.conf
/usr/share/alsa/cards/NFORCE.conf
/usr/share/alsa/cards/PC-Speaker.conf
/usr/share/alsa/cards/PMac.conf
/usr/share/alsa/cards/PMacToonie.conf
/usr/share/alsa/cards/PS3.conf
/usr/share/alsa/cards/RME9636.conf
/usr/share/alsa/cards/RME9652.conf
/usr/share/alsa/cards/SB-XFi.conf
/usr/share/alsa/cards/SI7018.conf
/usr/share/alsa/cards/TRID4DWAVENX.conf
/usr/share/alsa/cards/USB-Audio.conf
/usr/share/alsa/cards/VIA686A.conf
/usr/share/alsa/cards/VIA8233.conf
/usr/share/alsa/cards/VIA8233A.conf
/usr/share/alsa/cards/VIA8237.conf
/usr/share/alsa/cards/VX222.conf
/usr/share/alsa/cards/VXPocket.conf
/usr/share/alsa/cards/VXPocket440.conf
/usr/share/alsa/cards/YMF744.conf
/usr/share/alsa/cards/aliases.conf
/usr/share/alsa/cards/pistachio-card.conf
/usr/share/alsa/cards/vc4-hdmi.conf
/usr/share/alsa/firmware/usx2yloader/us122.conf
/usr/share/alsa/firmware/usx2yloader/us224.conf
/usr/share/alsa/firmware/usx2yloader/us428.conf
/usr/share/alsa/pcm/center_lfe.conf
/usr/share/alsa/pcm/default.conf
/usr/share/alsa/pcm/dmix.conf
/usr/share/alsa/pcm/dpl.conf
/usr/share/alsa/pcm/dsnoop.conf
/usr/share/alsa/pcm/front.conf
/usr/share/alsa/pcm/hdmi.conf
/usr/share/alsa/pcm/iec958.conf
/usr/share/alsa/pcm/modem.conf
/usr/share/alsa/pcm/rear.conf
/usr/share/alsa/pcm/side.conf
/usr/share/alsa/pcm/surround21.conf
/usr/share/alsa/pcm/surround40.conf
/usr/share/alsa/pcm/surround41.conf
/usr/share/alsa/pcm/surround50.conf
/usr/share/alsa/pcm/surround51.conf
/usr/share/alsa/pcm/surround71.conf
/usr/share/alsa/topology/broadwell/broadwell.conf
/usr/share/alsa/topology/bxtrt298/bxt_i2s.conf
/usr/share/alsa/topology/sklrt286/skl_i2s.conf
/usr/share/dbus-1/session.conf
/usr/share/dbus-1/system.conf
/usr/share/doc/NetworkManager/examples/server.conf
/usr/share/doc/alsa-lib/modprobe-dist-oss.conf
/usr/share/doc/dbus-1.10.24/examples/example-session-disable-stats.conf
/usr/share/doc/dbus-1.10.24/examples/example-system-enable-stats.conf
/usr/share/doc/glibc-common-2.17/gai.conf
/usr/share/doc/gnupg2-2.0.22/examples/gpgconf.conf
/usr/share/doc/httpd-2.4.6/httpd-dav.conf
/usr/share/doc/httpd-2.4.6/httpd-default.conf
/usr/share/doc/httpd-2.4.6/httpd-info.conf
/usr/share/doc/httpd-2.4.6/httpd-languages.conf
/usr/share/doc/httpd-2.4.6/httpd-manual.conf
/usr/share/doc/httpd-2.4.6/httpd-mpm.conf
/usr/share/doc/httpd-2.4.6/httpd-multilang-errordoc.conf
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
/usr/share/doc/httpd-2.4.6/proxy-html.conf
/usr/share/doc/krb5-libs-1.15.1/examples/kdc.conf
/usr/share/doc/krb5-libs-1.15.1/examples/krb5.conf
/usr/share/doc/python-configobj-4.7.2/docutils.conf
/usr/share/doc/python-slip-0.4.0/dbus/example/org.fedoraproject.slip.example.mechanism.conf
/usr/share/doc/python-slip-dbus-0.4.0/example/org.fedoraproject.slip.example.mechanism.conf
/usr/share/doc/sudo-1.8.23/examples/pam.conf
/usr/share/doc/sudo-1.8.23/examples/sudo.conf
/usr/share/doc/sudo-1.8.23/examples/syslog.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_arp_ping_1.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_arp_ping_2.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_ethtool_1.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_ethtool_2.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_ethtool_3.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_multi_lw_1.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_nsna_ping_1.conf
/usr/share/doc/teamd-1.27/example_configs/activebackup_tipc.conf
/usr/share/doc/teamd-1.27/example_configs/broadcast.conf
/usr/share/doc/teamd-1.27/example_configs/lacp_1.conf
/usr/share/doc/teamd-1.27/example_configs/loadbalance_1.conf
/usr/share/doc/teamd-1.27/example_configs/loadbalance_2.conf
/usr/share/doc/teamd-1.27/example_configs/loadbalance_3.conf
/usr/share/doc/teamd-1.27/example_configs/random.conf
/usr/share/doc/teamd-1.27/example_configs/roundrobin.conf
/usr/share/doc/teamd-1.27/example_configs/roundrobin_2.conf
/usr/share/doc/wpa_supplicant-2.6/wpa_supplicant.conf
/usr/share/doc/wpa_supplicant-2.6/examples/ieee8021x.conf
/usr/share/doc/wpa_supplicant-2.6/examples/openCryptoki.conf
/usr/share/doc/wpa_supplicant-2.6/examples/plaintext.conf
/usr/share/doc/wpa_supplicant-2.6/examples/udhcpd-p2p.conf
/usr/share/doc/wpa_supplicant-2.6/examples/wep.conf
/usr/share/doc/wpa_supplicant-2.6/examples/wpa-psk-tkip.conf
/usr/share/doc/wpa_supplicant-2.6/examples/wpa2-eap-ccmp.conf
/usr/src/kernels/3.10.0-957.el7.x86_64/include/config/auto.conf
/usr/src/kernels/3.10.0-957.el7.x86_64/include/config/tristate.conf
/var/lib/NetworkManager/NetworkManager-intern.conf
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate -r "\.conf$"          #之匹配以".conf"结尾的文件

7>.查看locate命令的帮助信息

[root@node101.yinzhengjie.org.cn ~]# locate --help
Usage: locate [OPTION]... [PATTERN]...
Search for entries in a mlocate database.

  -A, --all              only print entries that match all patterns
  -b, --basename         match only the base name of path names
  -c, --count            only print number of found entries
  -d, --database DBPATH  use DBPATH instead of default database (which is
                         /var/lib/mlocate/mlocate.db)
  -e, --existing         only print entries for currently existing files
  -L, --follow           follow trailing symbolic links when checking file
                         existence (default)
  -h, --help             print this help
  -i, --ignore-case      ignore case distinctions when matching patterns
  -l, --limit, -n LIMIT  limit output (or counting) to LIMIT entries
  -m, --mmap             ignored, for backward compatibility
  -P, --nofollow, -H     don't follow trailing symbolic links when checking file
                         existence
  -0, --null             separate entries with NUL on output
  -S, --statistics       don't search for entries, print statistics about each
                         used database
  -q, --quiet            report no error messages about reading databases
  -r, --regexp REGEXP    search for basic regexp REGEXP instead of patterns
      --regex            patterns are extended regexps
  -s, --stdio            ignored, for backward compatibility
  -V, --version          print version information
  -w, --wholename        match whole path name (default)

Report bugs to mitr@redhat.com.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# locate --help

 

二.实时查找find工具

实时查找工具,通过遍历指定路径完成文件查找 

工作特点:
  (1)查找速度略慢
  (2)精确查找
  (3)实时查找
  (4)可能只搜索用户具备读取和执行权限的目录

语法:
  find [OPTION]... [查找路径] [查找条件] [处理动作]
     查找路径:
      指定具体目标路径;默认为当前目录     查找条件:
      指定的查找标准,可以文件名、大小、类型、权限等标准进行; 默认为找出指定路径下的所有文件   处理动作:
      对符合条件的文件做操作,默认输出至屏幕

1>.查看find命令的帮助信息

[root@node101.yinzhengjie.org.cn ~]# find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:

operators (decreasing precedence; -and is implicit where no others are given):
      ( EXPR )   ! EXPR   -not EXPR   EXPR1 -a EXPR2   EXPR1 -and EXPR2
      EXPR1 -o EXPR2   EXPR1 -or EXPR2   EXPR1 , EXPR2

positional options (always true): -daystart -follow -regextype

normal options (always true, specified before other expressions):
      -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
      --version -xautofs -xdev -ignore_readdir_race -noignore_readdir_race

tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
      -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
      -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
      -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
      -nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
      -readable -writable -executable
      -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
      -used N -user NAME -xtype [bcdpfls]
      -context CONTEXT


actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print 
      -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
      -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
      -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

Report (and track progress on fixing) bugs via the findutils bug-reporting
page at http://savannah.gnu.org/ or, if you have no web access, by sending
email to <bug-findutils@gnu.org>.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find --help

2>.不指定查找路径,条件和处理动作默认递归查找查找当前目录的所有文件

[root@node101.yinzhengjie.org.cn ~]# find
.
./.lesshst
./a
./a/a
./a/f2.log
./a/mv
./.bash_profile
./.tcshrc
./.cshrc
./.viminfo
./.bash_logout
./.bash_history
./.pki
./.pki/nssdb
./.bashrc
./.mysql_history
./f1.log
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ls -aR
.:
.  ..  a  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  f1.log  .lesshst  .mysql_history  .pki  .tcshrc  .viminfo

./a:
.  ..  a  f2.log  mv

./.pki:
.  ..  nssdb

./.pki/nssdb:
.  ..
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find

3>.查找指定路径下的所有文件

[root@node101.yinzhengjie.org.cn ~]# ll -R test/ 
test/:
total 0
-rw-r--r-- 1 root root 0 Dec 12 10:08 a
-rw-r--r-- 1 root root 0 Dec 12 10:08 f2.log
-rw-r--r-- 1 root root 0 Dec 12 10:08 mv
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find test/  
test/
test/a
test/f2.log
test/mv
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find test/

4>.指定搜索层级

[root@node101.yinzhengjie.org.cn ~]# find / -maxdepth 1        #表示在根目录开始查找文件,最大搜索目录深度为1。
/
/media
/mnt
/lost+found
/dev
/tmp
/home
/run
/srv
/boot
/bin
/sbin
/lib64
/usr
/sys
/etc
/var
/lib
/proc
/opt
/root
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find / -maxdepth 1                 #表示在根目录开始查找文件,最大搜索目录深度为1。
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -maxdepth 1
/etc/pki/
/etc/pki/CA
/etc/pki/nss-legacy
/etc/pki/ca-trust
/etc/pki/rsyslog
/etc/pki/nssdb
/etc/pki/rpm-gpg
/etc/pki/tls
/etc/pki/java
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -maxdepth 1            #同上,表示从"/etc/pki"目录开始查找文件,最大搜索深度为1。
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -mindepth 1  
/etc/pki/CA
/etc/pki/CA/newcerts
/etc/pki/CA/private
/etc/pki/CA/crl
/etc/pki/CA/certs
/etc/pki/nss-legacy
/etc/pki/nss-legacy/nss-rhel7.config
/etc/pki/ca-trust
/etc/pki/ca-trust/ca-legacy.conf
/etc/pki/ca-trust/README
/etc/pki/ca-trust/source
/etc/pki/ca-trust/source/anchors
/etc/pki/ca-trust/source/blacklist
/etc/pki/ca-trust/source/ca-bundle.legacy.crt
/etc/pki/ca-trust/source/README
/etc/pki/ca-trust/extracted
/etc/pki/ca-trust/extracted/README
/etc/pki/ca-trust/extracted/pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/README
/etc/pki/ca-trust/extracted/openssl
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/openssl/README
/etc/pki/ca-trust/extracted/java
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/java/README
/etc/pki/rsyslog
/etc/pki/nssdb
/etc/pki/nssdb/cert9.db
/etc/pki/nssdb/secmod.db
/etc/pki/nssdb/key3.db
/etc/pki/nssdb/key4.db
/etc/pki/nssdb/pkcs11.txt
/etc/pki/nssdb/cert8.db
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Testing-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
/etc/pki/tls
/etc/pki/tls/private
/etc/pki/tls/misc
/etc/pki/tls/misc/CA
/etc/pki/tls/misc/c_issuer
/etc/pki/tls/misc/c_info
/etc/pki/tls/misc/c_hash
/etc/pki/tls/misc/c_name
/etc/pki/tls/certs
/etc/pki/tls/certs/ca-bundle.crt
/etc/pki/tls/certs/Makefile
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/pki/tls/certs/renew-dummy-cert
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/openssl.cnf
/etc/pki/tls/cert.pem
/etc/pki/java
/etc/pki/java/cacerts
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -mindepth 1            #和上面相反,表示最小深度为1,即贪婪搜索,一般情况下就是递归搜索"/etc/pki"目录下但所有文件
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -mindepth 3 -maxdepth 3
/etc/pki/ca-trust/source/anchors
/etc/pki/ca-trust/source/blacklist
/etc/pki/ca-trust/source/ca-bundle.legacy.crt
/etc/pki/ca-trust/source/README
/etc/pki/ca-trust/extracted/README
/etc/pki/ca-trust/extracted/pem
/etc/pki/ca-trust/extracted/openssl
/etc/pki/ca-trust/extracted/java
/etc/pki/tls/misc/CA
/etc/pki/tls/misc/c_issuer
/etc/pki/tls/misc/c_info
/etc/pki/tls/misc/c_hash
/etc/pki/tls/misc/c_name
/etc/pki/tls/certs/ca-bundle.crt
/etc/pki/tls/certs/Makefile
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/pki/tls/certs/renew-dummy-cert
/etc/pki/tls/certs/make-dummy-cert
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -mindepth 3 -maxdepth 3     #只搜索第三级目录

5>.先处理目录内的文件,再处理指定目录 

[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -depth         #先处理目录内的文件,再处理指定目录,即先显示文件,后显示文件夹
/etc/pki/CA/newcerts
/etc/pki/CA/private
/etc/pki/CA/crl
/etc/pki/CA/certs
/etc/pki/CA
/etc/pki/nss-legacy/nss-rhel7.config
/etc/pki/nss-legacy
/etc/pki/ca-trust/ca-legacy.conf
/etc/pki/ca-trust/README
/etc/pki/ca-trust/source/anchors
/etc/pki/ca-trust/source/blacklist
/etc/pki/ca-trust/source/ca-bundle.legacy.crt
/etc/pki/ca-trust/source/README
/etc/pki/ca-trust/source
/etc/pki/ca-trust/extracted/README
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/README
/etc/pki/ca-trust/extracted/pem
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/openssl/README
/etc/pki/ca-trust/extracted/openssl
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/java/README
/etc/pki/ca-trust/extracted/java
/etc/pki/ca-trust/extracted
/etc/pki/ca-trust
/etc/pki/rsyslog
/etc/pki/nssdb/cert9.db
/etc/pki/nssdb/secmod.db
/etc/pki/nssdb/key3.db
/etc/pki/nssdb/key4.db
/etc/pki/nssdb/pkcs11.txt
/etc/pki/nssdb/cert8.db
/etc/pki/nssdb
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Testing-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
/etc/pki/rpm-gpg
/etc/pki/tls/private
/etc/pki/tls/misc/CA
/etc/pki/tls/misc/c_issuer
/etc/pki/tls/misc/c_info
/etc/pki/tls/misc/c_hash
/etc/pki/tls/misc/c_name
/etc/pki/tls/misc
/etc/pki/tls/certs/ca-bundle.crt
/etc/pki/tls/certs/Makefile
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/pki/tls/certs/renew-dummy-cert
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs
/etc/pki/tls/openssl.cnf
/etc/pki/tls/cert.pem
/etc/pki/tls
/etc/pki/java/cacerts
/etc/pki/java
/etc/pki/
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ -depth             #先处理目录内的文件,再处理指定目录,即先显示文件,后显示文件夹
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/     #默认先显示文件夹,后显示文件                                             
/etc/pki/
/etc/pki/CA
/etc/pki/CA/newcerts
/etc/pki/CA/private
/etc/pki/CA/crl
/etc/pki/CA/certs
/etc/pki/nss-legacy
/etc/pki/nss-legacy/nss-rhel7.config
/etc/pki/ca-trust
/etc/pki/ca-trust/ca-legacy.conf
/etc/pki/ca-trust/README
/etc/pki/ca-trust/source
/etc/pki/ca-trust/source/anchors
/etc/pki/ca-trust/source/blacklist
/etc/pki/ca-trust/source/ca-bundle.legacy.crt
/etc/pki/ca-trust/source/README
/etc/pki/ca-trust/extracted
/etc/pki/ca-trust/extracted/README
/etc/pki/ca-trust/extracted/pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/README
/etc/pki/ca-trust/extracted/openssl
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/openssl/README
/etc/pki/ca-trust/extracted/java
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/java/README
/etc/pki/rsyslog
/etc/pki/nssdb
/etc/pki/nssdb/cert9.db
/etc/pki/nssdb/secmod.db
/etc/pki/nssdb/key3.db
/etc/pki/nssdb/key4.db
/etc/pki/nssdb/pkcs11.txt
/etc/pki/nssdb/cert8.db
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Testing-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7
/etc/pki/tls
/etc/pki/tls/private
/etc/pki/tls/misc
/etc/pki/tls/misc/CA
/etc/pki/tls/misc/c_issuer
/etc/pki/tls/misc/c_info
/etc/pki/tls/misc/c_hash
/etc/pki/tls/misc/c_name
/etc/pki/tls/certs
/etc/pki/tls/certs/ca-bundle.crt
/etc/pki/tls/certs/Makefile
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/pki/tls/certs/renew-dummy-cert
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/openssl.cnf
/etc/pki/tls/cert.pem
/etc/pki/java
/etc/pki/java/cacerts
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/                 #默认先显示文件夹,后显示文件

6>.根据文件名和inode查找

[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name ifcfg-eth0          #文件名称必须要精确匹配
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name ifcfg              #不存在叫ifcfg的文件,因此匹配不上
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name ifcfg-eth0          #文件名称必须要精确匹配
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name ifcfg
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "ifcfg*"            #支持使用glob,即通配符
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-lo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "ifcfg*"            #支持使用glob,即通配符
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name IFCFG-ETH0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -iname IFCFG-ETH0          #忽略匹配的文件名称大小写
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -iname IFCFG-ETH0          #忽略匹配的文件名称大小写
[root@node101.yinzhengjie.org.cn ~]# ll -i /etc/sysconfig/network-scripts/ifcfg-eth0 
788769 -rw-r--r--. 1 root root 162 Sep  5 02:37 /etc/sysconfig/network-scripts/ifcfg-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ln /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcf-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 4
-rw-r--r--. 2 root root 162 Sep  5 02:37 ifcf-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find / -inum 788769                  #基于inode节点编号查找文件
/etc/sysconfig/network-scripts/ifcfg-eth0
/root/ifcf-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find / -inum 788769               #基于inode节点编号查找文件
[root@node101.yinzhengjie.org.cn ~]# find / -inum 64 -ls             #列出查找到到文件
    64    4 -rw-rw-r--   1 yinzhengjie yinzhengjie      910 Sep  9 05:55 /home/yinzhengjie/.pyenv/versions/3.6.9/envs/jason/lib/python3.6/site-packages/notebook/static/components/MathJax/extensions/a11y/mathmaps/es/symbols/math_non_characters.js
    64    0 --w-------   1 root     root         4096 Dec 11 15:26 /sys/bus/memory/uevent
    64    0 -rw-r--r--   1 root     root            0 Dec 11 15:25 /sys/kernel/debug/tracing/function_profile_enabled
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find / -inum 64 -ls                #列出查找到到文件
[root@node101.yinzhengjie.org.cn ~]# ll -i /etc/sysconfig/network-scripts/ifcfg-eth0 
788769 -rw-r--r--. 2 root root 162 Sep  5 02:37 /etc/sysconfig/network-scripts/ifcfg-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll -i
total 4
788769 -rw-r--r--. 2 root root 162 Sep  5 02:37 ifcf-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -samefile /root/ifcf-eth0  #在"/etc"目录下找和"/root/ifcf-eth0"文件相同的文件,即是硬连接关系而非inode节点编号一样,inode节点编号一样可能是不同分区的文件哟,而硬连接是不可以跨越分区的。
/etc/sysconfig/network-scripts/ifcfg-eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -samefile /root/ifcf-eth0      #在"/etc"目录下找和"/root/ifcf-eth0"文件相同的文件,即是硬连接关系而非inode节点编号一样,inode节点编号一样可能是不同分区的文件哟,而硬连接是不可以跨越分区的。
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -links 6 -ls              #在"/etc"目录下查看链接数为6的文件
786505    4 drwxr-xr-x   6 root     root         4096 Dec 11 09:30 /etc/sysconfig
786977    4 drwxr-xr-x   6 root     root         4096 Sep  5 01:49 /etc/lvm
786680    4 drwxr-xr-x   6 root     root         4096 Mar 12  2019 /etc/pki/CA
786613    4 drwxr-xr-x   6 root     root         4096 Sep  5 01:48 /etc/security
786553    4 drwxr-xr-x   6 root     root         4096 Sep  5 01:49 /etc/yum
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -links 6 -ls              #在"/etc"目录下查看链接数为6的文件
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -regex ".*\.sh$"            #在"/etc"目录下查看以".sh"结尾的文件名称,注意,find和locate不同,find的正则表达式要求咱们匹配文件的全路径。
/etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
/etc/profile.d/less.sh
/etc/profile.d/which2.sh
/etc/profile.d/256term.sh
/etc/profile.d/vim.sh
/etc/profile.d/colorgrep.sh
/etc/profile.d/colorls.sh
/etc/profile.d/lang.sh
/etc/dhcp/dhclient.d/chrony.sh
/etc/dhcp/dhclient-exit-hooks.d/azure-cloud.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -regex ".*\.sh$"            #在"/etc"目录下查看以".sh"结尾的文件名称,注意,find和locate不同,find的正则表达式要求咱们匹配文件的全路径。

7>.根据属主、属组查找

-user USERNAME:
  查找属主为指定用户(UID)的文件

-group GRPNAME:
  查找属组为指定组(GID)的文件

-uid UserID:
  查找属主为指定的UID号的文件
-gid GroupID:
  查找属组为指定的GID号的文件

-nouser:
  查找没有属主的文件

-nogroup:
  查找没有属组的文件 
[root@node101.yinzhengjie.org.cn ~]# find /home/yinzhengjie/devops/ -user yinzhengjie -ls        #查找属主为yinzhengjie的文件
396207    4 drwxrwxr-x   4 yinzhengjie yinzhengjie     4096 Sep  9 06:05 /home/yinzhengjie/devops/
396389    4 drwxrwxr-x   2 yinzhengjie yinzhengjie     4096 Sep  9 06:06 /home/yinzhengjie/devops/op
396390    4 -rw-rw-r--   1 yinzhengjie yinzhengjie        9 Sep  9 06:06 /home/yinzhengjie/devops/op/.python-version
396209    4 drwxrwxr-x   2 yinzhengjie yinzhengjie     4096 Sep  9 05:55 /home/yinzhengjie/devops/cmdb
396206    4 -rw-rw-r--   1 yinzhengjie yinzhengjie        6 Sep  9 05:55 /home/yinzhengjie/devops/cmdb/.python-version
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /home/yinzhengjie/devops/ -user yinzhengjie -ls        #查找属主为yinzhengjie的文件
[root@node101.yinzhengjie.org.cn ~]# useradd centos     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# su -l centos     
[centos@node101.yinzhengjie.org.cn ~]$ 
[centos@node101.yinzhengjie.org.cn ~]$ touch /tmp/a{1..3}.txt
[centos@node101.yinzhengjie.org.cn ~]$ 
[centos@node101.yinzhengjie.org.cn ~]$ ll /tmp/
total 0
-rw-rw-r-- 1 centos centos 0 Dec 12 11:07 a1.txt
-rw-rw-r-- 1 centos centos 0 Dec 12 11:07 a2.txt
-rw-rw-r-- 1 centos centos 0 Dec 12 11:07 a3.txt
[centos@node101.yinzhengjie.org.cn ~]$ 
[centos@node101.yinzhengjie.org.cn ~]$ exit 
logout
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# userdel -r centos
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /tmp/
total 0
-rw-rw-r-- 1 1001 1001 0 Dec 12 11:07 a1.txt
-rw-rw-r-- 1 1001 1001 0 Dec 12 11:07 a2.txt
-rw-rw-r-- 1 1001 1001 0 Dec 12 11:07 a3.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /tmp/ -nouser -ls            #查看没有属主的文件
1179657    0 -rw-rw-r--   1 1001     1001            0 Dec 12 11:07 /tmp/a1.txt
1179661    0 -rw-rw-r--   1 1001     1001            0 Dec 12 11:07 /tmp/a2.txt
1179663    0 -rw-rw-r--   1 1001     1001            0 Dec 12 11:07 /tmp/a3.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /tmp/ -nouser -ls                          #查看没有属主的文件
[root@node101.yinzhengjie.org.cn ~]# find /tmp/ -nogroup -ls                          #查看没有属组的文件
1179657    0 -rw-rw-r--   1 1001     1001            0 Dec 12 11:07 /tmp/a1.txt
1179661    0 -rw-rw-r--   1 1001     1001            0 Dec 12 11:07 /tmp/a2.txt
1179663    0 -rw-rw-r--   1 1001     1001            0 Dec 12 11:07 /tmp/a3.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /tmp/ -nogroup -ls                          #查看没有属组的文件

8>.根据文件类型查找

-type TYPE
  f: 普通文件
  d: 目录文件
  l: 符号链接文件
  s:套接字文件
  b: 块设备文件   c: 字符设备文件
  p: 管道文件
[root@node101.yinzhengjie.org.cn ~]# find /etc/selinux/ -type d 
/etc/selinux/
/etc/selinux/tmp
/etc/selinux/targeted
/etc/selinux/targeted/contexts
/etc/selinux/targeted/contexts/files
/etc/selinux/targeted/contexts/users
/etc/selinux/targeted/active
/etc/selinux/targeted/active/modules
/etc/selinux/targeted/active/modules/disabled
/etc/selinux/targeted/active/modules/100
/etc/selinux/targeted/active/modules/100/rdisc
/etc/selinux/targeted/active/modules/100/tuned
/etc/selinux/targeted/active/modules/100/setroubleshoot
/etc/selinux/targeted/active/modules/100/wireshark
/etc/selinux/targeted/active/modules/100/permissivedomains
/etc/selinux/targeted/active/modules/100/prelude
/etc/selinux/targeted/active/modules/100/apcupsd
/etc/selinux/targeted/active/modules/100/courier
/etc/selinux/targeted/active/modules/100/nut
/etc/selinux/targeted/active/modules/100/bacula
/etc/selinux/targeted/active/modules/100/pwauth
/etc/selinux/targeted/active/modules/100/certwatch
/etc/selinux/targeted/active/modules/100/ipa
/etc/selinux/targeted/active/modules/100/tcsd
/etc/selinux/targeted/active/modules/100/sensord
/etc/selinux/targeted/active/modules/100/uucp
/etc/selinux/targeted/active/modules/100/mrtg
/etc/selinux/targeted/active/modules/100/kerberos
/etc/selinux/targeted/active/modules/100/firewalld
/etc/selinux/targeted/active/modules/100/kmscon
/etc/selinux/targeted/active/modules/100/sandboxX
/etc/selinux/targeted/active/modules/100/loadkeys
/etc/selinux/targeted/active/modules/100/smsd
/etc/selinux/targeted/active/modules/100/zarafa
/etc/selinux/targeted/active/modules/100/tftp
/etc/selinux/targeted/active/modules/100/hsqldb
/etc/selinux/targeted/active/modules/100/chronyd
/etc/selinux/targeted/active/modules/100/oracleasm
/etc/selinux/targeted/active/modules/100/vdagent
/etc/selinux/targeted/active/modules/100/ntop
/etc/selinux/targeted/active/modules/100/lockdev
/etc/selinux/targeted/active/modules/100/stapserver
/etc/selinux/targeted/active/modules/100/wdmd
/etc/selinux/targeted/active/modules/100/prosody
/etc/selinux/targeted/active/modules/100/aiccu
/etc/selinux/targeted/active/modules/100/ajaxterm
/etc/selinux/targeted/active/modules/100/guest
/etc/selinux/targeted/active/modules/100/publicfile
/etc/selinux/targeted/active/modules/100/nscd
/etc/selinux/targeted/active/modules/100/netlabel
/etc/selinux/targeted/active/modules/100/userhelper
/etc/selinux/targeted/active/modules/100/ntp
/etc/selinux/targeted/active/modules/100/portreserve
/etc/selinux/targeted/active/modules/100/cockpit
/etc/selinux/targeted/active/modules/100/isns
/etc/selinux/targeted/active/modules/100/callweaver
/etc/selinux/targeted/active/modules/100/rhgb
/etc/selinux/targeted/active/modules/100/gpsd
/etc/selinux/targeted/active/modules/100/realmd
/etc/selinux/targeted/active/modules/100/cachefilesd
/etc/selinux/targeted/active/modules/100/portmap
/etc/selinux/targeted/active/modules/100/mock
/etc/selinux/targeted/active/modules/100/freeipmi
/etc/selinux/targeted/active/modules/100/logging
/etc/selinux/targeted/active/modules/100/squid
/etc/selinux/targeted/active/modules/100/blkmapd
/etc/selinux/targeted/active/modules/100/mojomojo
/etc/selinux/targeted/active/modules/100/bcfg2
/etc/selinux/targeted/active/modules/100/miscfiles
/etc/selinux/targeted/active/modules/100/calamaris
/etc/selinux/targeted/active/modules/100/keystone
/etc/selinux/targeted/active/modules/100/vlock
/etc/selinux/targeted/active/modules/100/ipmievd
/etc/selinux/targeted/active/modules/100/rhsmcertd
/etc/selinux/targeted/active/modules/100/qmail
/etc/selinux/targeted/active/modules/100/cinder
/etc/selinux/targeted/active/modules/100/lircd
/etc/selinux/targeted/active/modules/100/snapper
/etc/selinux/targeted/active/modules/100/cmirrord
/etc/selinux/targeted/active/modules/100/xguest
/etc/selinux/targeted/active/modules/100/rkhunter
/etc/selinux/targeted/active/modules/100/ctdb
/etc/selinux/targeted/active/modules/100/thumb
/etc/selinux/targeted/active/modules/100/ncftool
/etc/selinux/targeted/active/modules/100/pingd
/etc/selinux/targeted/active/modules/100/finger
/etc/selinux/targeted/active/modules/100/inn
/etc/selinux/targeted/active/modules/100/lvm
/etc/selinux/targeted/active/modules/100/certmonger
/etc/selinux/targeted/active/modules/100/dbus
/etc/selinux/targeted/active/modules/100/cfengine
/etc/selinux/targeted/active/modules/100/daemontools
/etc/selinux/targeted/active/modules/100/mysql
/etc/selinux/targeted/active/modules/100/iptables
/etc/selinux/targeted/active/modules/100/mta
/etc/selinux/targeted/active/modules/100/w3c
/etc/selinux/targeted/active/modules/100/denyhosts
/etc/selinux/targeted/active/modules/100/cgroup
/etc/selinux/targeted/active/modules/100/sbd
/etc/selinux/targeted/active/modules/100/pki
/etc/selinux/targeted/active/modules/100/cyrus
/etc/selinux/targeted/active/modules/100/mon_statd
/etc/selinux/targeted/active/modules/100/rtkit
/etc/selinux/targeted/active/modules/100/rpm
/etc/selinux/targeted/active/modules/100/dbadm
/etc/selinux/targeted/active/modules/100/stunnel
/etc/selinux/targeted/active/modules/100/firstboot
/etc/selinux/targeted/active/modules/100/zebra
/etc/selinux/targeted/active/modules/100/certmaster
/etc/selinux/targeted/active/modules/100/apm
/etc/selinux/targeted/active/modules/100/drbd
/etc/selinux/targeted/active/modules/100/pads
/etc/selinux/targeted/active/modules/100/brctl
/etc/selinux/targeted/active/modules/100/quantum
/etc/selinux/targeted/active/modules/100/soundserver
/etc/selinux/targeted/active/modules/100/openct
/etc/selinux/targeted/active/modules/100/procmail
/etc/selinux/targeted/active/modules/100/mailscanner
/etc/selinux/targeted/active/modules/100/plymouthd
/etc/selinux/targeted/active/modules/100/slpd
/etc/selinux/targeted/active/modules/100/irc
/etc/selinux/targeted/active/modules/100/webadm
/etc/selinux/targeted/active/modules/100/zoneminder
/etc/selinux/targeted/active/modules/100/geoclue
/etc/selinux/targeted/active/modules/100/sblim
/etc/selinux/targeted/active/modules/100/container
/etc/selinux/targeted/active/modules/100/antivirus
/etc/selinux/targeted/active/modules/100/wine
/etc/selinux/targeted/active/modules/100/openshift
/etc/selinux/targeted/active/modules/100/mplayer
/etc/selinux/targeted/active/modules/100/bluetooth
/etc/selinux/targeted/active/modules/100/swift
/etc/selinux/targeted/active/modules/100/dhcp
/etc/selinux/targeted/active/modules/100/dbskk
/etc/selinux/targeted/active/modules/100/entropyd
/etc/selinux/targeted/active/modules/100/tvtime
/etc/selinux/targeted/active/modules/100/cvs
/etc/selinux/targeted/active/modules/100/brltty
/etc/selinux/targeted/active/modules/100/kdumpgui
/etc/selinux/targeted/active/modules/100/postfix
/etc/selinux/targeted/active/modules/100/postgresql
/etc/selinux/targeted/active/modules/100/getty
/etc/selinux/targeted/active/modules/100/slocate
/etc/selinux/targeted/active/modules/100/amanda
/etc/selinux/targeted/active/modules/100/sysstat
/etc/selinux/targeted/active/modules/100/fetchmail
/etc/selinux/targeted/active/modules/100/milter
/etc/selinux/targeted/active/modules/100/sasl
/etc/selinux/targeted/active/modules/100/lldpad
/etc/selinux/targeted/active/modules/100/rhcs
/etc/selinux/targeted/active/modules/100/logwatch
/etc/selinux/targeted/active/modules/100/gitosis
/etc/selinux/targeted/active/modules/100/qpid
/etc/selinux/targeted/active/modules/100/sectoolm
/etc/selinux/targeted/active/modules/100/nx
/etc/selinux/targeted/active/modules/100/hostname
/etc/selinux/targeted/active/modules/100/shorewall
/etc/selinux/targeted/active/modules/100/sysadm
/etc/selinux/targeted/active/modules/100/rpcbind
/etc/selinux/targeted/active/modules/100/openwsman
/etc/selinux/targeted/active/modules/100/netutils
/etc/selinux/targeted/active/modules/100/condor
/etc/selinux/targeted/active/modules/100/auditadm
/etc/selinux/targeted/active/modules/100/fstools
/etc/selinux/targeted/active/modules/100/smokeping
/etc/selinux/targeted/active/modules/100/nsd
/etc/selinux/targeted/active/modules/100/irqbalance
/etc/selinux/targeted/active/modules/100/rshd
/etc/selinux/targeted/active/modules/100/vmware
/etc/selinux/targeted/active/modules/100/pcp
/etc/selinux/targeted/active/modules/100/pcmcia
/etc/selinux/targeted/active/modules/100/tomcat
/etc/selinux/targeted/active/modules/100/sge
/etc/selinux/targeted/active/modules/100/openvswitch
/etc/selinux/targeted/active/modules/100/games
/etc/selinux/targeted/active/modules/100/sssd
/etc/selinux/targeted/active/modules/100/setrans
/etc/selinux/targeted/active/modules/100/devicekit
/etc/selinux/targeted/active/modules/100/mythtv
/etc/selinux/targeted/active/modules/100/podsleuth
/etc/selinux/targeted/active/modules/100/updfstab
/etc/selinux/targeted/active/modules/100/opendnssec
/etc/selinux/targeted/active/modules/100/mirrormanager
/etc/selinux/targeted/active/modules/100/zabbix
/etc/selinux/targeted/active/modules/100/xserver
/etc/selinux/targeted/active/modules/100/zosremote
/etc/selinux/targeted/active/modules/100/cdrecord
/etc/selinux/targeted/active/modules/100/radius
/etc/selinux/targeted/active/modules/100/ktalk
/etc/selinux/targeted/active/modules/100/xen
/etc/selinux/targeted/active/modules/100/sanlock
/etc/selinux/targeted/active/modules/100/acct
/etc/selinux/targeted/active/modules/100/authlogin
/etc/selinux/targeted/active/modules/100/usbmodules
/etc/selinux/targeted/active/modules/100/iscsi
/etc/selinux/targeted/active/modules/100/colord
/etc/selinux/targeted/active/modules/100/glusterd
/etc/selinux/targeted/active/modules/100/conman
/etc/selinux/targeted/active/modules/100/fprintd
/etc/selinux/targeted/active/modules/100/tlp
/etc/selinux/targeted/active/modules/100/dnsmasq
/etc/selinux/targeted/active/modules/100/rwho
/etc/selinux/targeted/active/modules/100/opensm
/etc/selinux/targeted/active/modules/100/base
/etc/selinux/targeted/active/modules/100/rpc
/etc/selinux/targeted/active/modules/100/speech-dispatcher
/etc/selinux/targeted/active/modules/100/glance
/etc/selinux/targeted/active/modules/100/mpd
/etc/selinux/targeted/active/modules/100/l2tp
/etc/selinux/targeted/active/modules/100/ulogd
/etc/selinux/targeted/active/modules/100/gdomap
/etc/selinux/targeted/active/modules/100/secadm
/etc/selinux/targeted/active/modules/100/jabber
/etc/selinux/targeted/active/modules/100/consolekit
/etc/selinux/targeted/active/modules/100/vmtools
/etc/selinux/targeted/active/modules/100/dirsrv
/etc/selinux/targeted/active/modules/100/mozilla
/etc/selinux/targeted/active/modules/100/rhnsd
/etc/selinux/targeted/active/modules/100/puppet
/etc/selinux/targeted/active/modules/100/authconfig
/etc/selinux/targeted/active/modules/100/gssproxy
/etc/selinux/targeted/active/modules/100/redis
/etc/selinux/targeted/active/modules/100/munin
/etc/selinux/targeted/active/modules/100/nagios
/etc/selinux/targeted/active/modules/100/cloudform
/etc/selinux/targeted/active/modules/100/snort
/etc/selinux/targeted/active/modules/100/ricci
/etc/selinux/targeted/active/modules/100/awstats
/etc/selinux/targeted/active/modules/100/su
/etc/selinux/targeted/active/modules/100/pcscd
/etc/selinux/targeted/active/modules/100/unprivuser
/etc/selinux/targeted/active/modules/100/rngd
/etc/selinux/targeted/active/modules/100/sendmail
/etc/selinux/targeted/active/modules/100/lsm
/etc/selinux/targeted/active/modules/100/kismet
/etc/selinux/targeted/active/modules/100/jetty
/etc/selinux/targeted/active/modules/100/ninfod
/etc/selinux/targeted/active/modules/100/rhev
/etc/selinux/targeted/active/modules/100/ksmtuned
/etc/selinux/targeted/active/modules/100/firewallgui
/etc/selinux/targeted/active/modules/100/logrotate
/etc/selinux/targeted/active/modules/100/pulseaudio
/etc/selinux/targeted/active/modules/100/memcached
/etc/selinux/targeted/active/modules/100/ipsec
/etc/selinux/targeted/active/modules/100/smartmon
/etc/selinux/targeted/active/modules/100/spamassassin
/etc/selinux/targeted/active/modules/100/bugzilla
/etc/selinux/targeted/active/modules/100/udev
/etc/selinux/targeted/active/modules/100/tangd
/etc/selinux/targeted/active/modules/100/cpuplug
/etc/selinux/targeted/active/modules/100/rssh
/etc/selinux/targeted/active/modules/100/samba
/etc/selinux/targeted/active/modules/100/fcoe
/etc/selinux/targeted/active/modules/100/dnssec
/etc/selinux/targeted/active/modules/100/mount
/etc/selinux/targeted/active/modules/100/gnome
/etc/selinux/targeted/active/modules/100/clock
/etc/selinux/targeted/active/modules/100/hddtemp
/etc/selinux/targeted/active/modules/100/telepathy
/etc/selinux/targeted/active/modules/100/raid
/etc/selinux/targeted/active/modules/100/cobbler
/etc/selinux/targeted/active/modules/100/roundup
/etc/selinux/targeted/active/modules/100/apache
/etc/selinux/targeted/active/modules/100/comsat
/etc/selinux/targeted/active/modules/100/watchdog
/etc/selinux/targeted/active/modules/100/varnishd
/etc/selinux/targeted/active/modules/100/clogd
/etc/selinux/targeted/active/modules/100/motion
/etc/selinux/targeted/active/modules/100/virt
/etc/selinux/targeted/active/modules/100/openvpn
/etc/selinux/targeted/active/modules/100/arpwatch
/etc/selinux/targeted/active/modules/100/livecd
/etc/selinux/targeted/active/modules/100/nslcd
/etc/selinux/targeted/active/modules/100/thin
/etc/selinux/targeted/active/modules/100/keyboardd
/etc/selinux/targeted/active/modules/100/cgdcbxd
/etc/selinux/targeted/active/modules/100/dictd
/etc/selinux/targeted/active/modules/100/libraries
/etc/selinux/targeted/active/modules/100/gpm
/etc/selinux/targeted/active/modules/100/polipo
/etc/selinux/targeted/active/modules/100/oddjob
/etc/selinux/targeted/active/modules/100/usernetctl
/etc/selinux/targeted/active/modules/100/fail2ban
/etc/selinux/targeted/active/modules/100/minidlna
/etc/selinux/targeted/active/modules/100/lttng-tools
/etc/selinux/targeted/active/modules/100/vhostmd
/etc/selinux/targeted/active/modules/100/nis
/etc/selinux/targeted/active/modules/100/tcpd
/etc/selinux/targeted/active/modules/100/keepalived
/etc/selinux/targeted/active/modules/100/blueman
/etc/selinux/targeted/active/modules/100/bind
/etc/selinux/targeted/active/modules/100/dmesg
/etc/selinux/targeted/active/modules/100/snmp
/etc/selinux/targeted/active/modules/100/ppp
/etc/selinux/targeted/active/modules/100/sosreport
/etc/selinux/targeted/active/modules/100/accountsd
/etc/selinux/targeted/active/modules/100/dovecot
/etc/selinux/targeted/active/modules/100/bumblebee
/etc/selinux/targeted/active/modules/100/minissdpd
/etc/selinux/targeted/active/modules/100/uuidd
/etc/selinux/targeted/active/modules/100/mongodb
/etc/selinux/targeted/active/modules/100/pesign
/etc/selinux/targeted/active/modules/100/anaconda
/etc/selinux/targeted/active/modules/100/modutils
/etc/selinux/targeted/active/modules/100/cipe
/etc/selinux/targeted/active/modules/100/ccs
/etc/selinux/targeted/active/modules/100/osad
/etc/selinux/targeted/active/modules/100/policykit
/etc/selinux/targeted/active/modules/100/abrt
/etc/selinux/targeted/active/modules/100/privoxy
/etc/selinux/targeted/active/modules/100/psad
/etc/selinux/targeted/active/modules/100/likewise
/etc/selinux/targeted/active/modules/100/rsync
/etc/selinux/targeted/active/modules/100/prelink
/etc/selinux/targeted/active/modules/100/init
/etc/selinux/targeted/active/modules/100/targetd
/etc/selinux/targeted/active/modules/100/mailman
/etc/selinux/targeted/active/modules/100/unconfineduser
/etc/selinux/targeted/active/modules/100/mcelog
/etc/selinux/targeted/active/modules/100/usbmuxd
/etc/selinux/targeted/active/modules/100/usermanage
/etc/selinux/targeted/active/modules/100/tmpreaper
/etc/selinux/targeted/active/modules/100/rasdaemon
/etc/selinux/targeted/active/modules/100/cyphesis
/etc/selinux/targeted/active/modules/100/openhpid
/etc/selinux/targeted/active/modules/100/uml
/etc/selinux/targeted/active/modules/100/pegasus
/etc/selinux/targeted/active/modules/100/telnet
/etc/selinux/targeted/active/modules/100/selinuxutil
/etc/selinux/targeted/active/modules/100/readahead
/etc/selinux/targeted/active/modules/100/mediawiki
/etc/selinux/targeted/active/modules/100/staff
/etc/selinux/targeted/active/modules/100/cron
/etc/selinux/targeted/active/modules/100/cpufreqselector
/etc/selinux/targeted/active/modules/100/nova
/etc/selinux/targeted/active/modules/100/networkmanager
/etc/selinux/targeted/active/modules/100/jockey
/etc/selinux/targeted/active/modules/100/chrome
/etc/selinux/targeted/active/modules/100/rabbitmq
/etc/selinux/targeted/active/modules/100/avahi
/etc/selinux/targeted/active/modules/100/ptchown
/etc/selinux/targeted/active/modules/100/rtas
/etc/selinux/targeted/active/modules/100/asterisk
/etc/selinux/targeted/active/modules/100/svnserve
/etc/selinux/targeted/active/modules/100/lpd
/etc/selinux/targeted/active/modules/100/gpg
/etc/selinux/targeted/active/modules/100/ddclient
/etc/selinux/targeted/active/modules/100/sysnetwork
/etc/selinux/targeted/active/modules/100/ftp
/etc/selinux/targeted/active/modules/100/inetd
/etc/selinux/targeted/active/modules/100/linuxptp
/etc/selinux/targeted/active/modules/100/aide
/etc/selinux/targeted/active/modules/100/postgrey
/etc/selinux/targeted/active/modules/100/screen
/etc/selinux/targeted/active/modules/100/mip6d
/etc/selinux/targeted/active/modules/100/amtu
/etc/selinux/targeted/active/modules/100/icecast
/etc/selinux/targeted/active/modules/100/dcc
/etc/selinux/targeted/active/modules/100/bootloader
/etc/selinux/targeted/active/modules/100/collectd
/etc/selinux/targeted/active/modules/100/webalizer
/etc/selinux/targeted/active/modules/100/iotop
/etc/selinux/targeted/active/modules/100/freqset
/etc/selinux/targeted/active/modules/100/passenger
/etc/selinux/targeted/active/modules/100/man2html
/etc/selinux/targeted/active/modules/100/dspam
/etc/selinux/targeted/active/modules/100/obex
/etc/selinux/targeted/active/modules/100/radvd
/etc/selinux/targeted/active/modules/100/pkcs
/etc/selinux/targeted/active/modules/100/journalctl
/etc/selinux/targeted/active/modules/100/couchdb
/etc/selinux/targeted/active/modules/100/dmidecode
/etc/selinux/targeted/active/modules/100/sambagui
/etc/selinux/targeted/active/modules/100/systemd
/etc/selinux/targeted/active/modules/100/modemmanager
/etc/selinux/targeted/active/modules/100/remotelogin
/etc/selinux/targeted/active/modules/100/namespace
/etc/selinux/targeted/active/modules/100/openshift-origin
/etc/selinux/targeted/active/modules/100/exim
/etc/selinux/targeted/active/modules/100/numad
/etc/selinux/targeted/active/modules/100/quota
/etc/selinux/targeted/active/modules/100/bitlbee
/etc/selinux/targeted/active/modules/100/userdomain
/etc/selinux/targeted/active/modules/100/iodine
/etc/selinux/targeted/active/modules/100/application
/etc/selinux/targeted/active/modules/100/locallogin
/etc/selinux/targeted/active/modules/100/alsa
/etc/selinux/targeted/active/modules/100/vpn
/etc/selinux/targeted/active/modules/100/hwloc
/etc/selinux/targeted/active/modules/100/dirsrv-admin
/etc/selinux/targeted/active/modules/100/cups
/etc/selinux/targeted/active/modules/100/logadm
/etc/selinux/targeted/active/modules/100/tgtd
/etc/selinux/targeted/active/modules/100/smoltclient
/etc/selinux/targeted/active/modules/100/canna
/etc/selinux/targeted/active/modules/100/unconfined
/etc/selinux/targeted/active/modules/100/sysadm_secadm
/etc/selinux/targeted/active/modules/100/vnstatd
/etc/selinux/targeted/active/modules/100/ldap
/etc/selinux/targeted/active/modules/100/hypervkvp
/etc/selinux/targeted/active/modules/100/piranha
/etc/selinux/targeted/active/modules/100/cpucontrol
/etc/selinux/targeted/active/modules/100/boinc
/etc/selinux/targeted/active/modules/100/ssh
/etc/selinux/targeted/active/modules/100/automount
/etc/selinux/targeted/active/modules/100/seunshare
/etc/selinux/targeted/active/modules/100/rlogin
/etc/selinux/targeted/active/modules/100/tor
/etc/selinux/targeted/active/modules/100/kdump
/etc/selinux/targeted/active/modules/100/git
/etc/selinux/targeted/active/modules/100/mandb
/etc/selinux/targeted/active/modules/100/afs
/etc/selinux/targeted/active/modules/100/unlabelednet
/etc/selinux/targeted/active/modules/100/sudo
/etc/selinux/targeted/modules
/etc/selinux/targeted/modules/active
/etc/selinux/targeted/modules/active/modules
/etc/selinux/targeted/policy
/etc/selinux/targeted/logins
/etc/selinux/final
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/selinux/ -type d                #只查看"/etc/selinux"目录下的所有目录 

9>.空文件或目录

[root@node101.yinzhengjie.org.cn ~]# find /etc/selinux/ -type d -empty
/etc/selinux/tmp
/etc/selinux/targeted/active/modules/disabled
/etc/selinux/targeted/modules/active/modules
/etc/selinux/targeted/logins
/etc/selinux/final
[root@node101.yinzhengjie.org.cn ~]# ll /etc/selinux/targeted/logins
total 0
[root@node101.yinzhengjie.org.cn ~]# find /etc/selinux/ -type d -empty
/etc/selinux/tmp
/etc/selinux/targeted/active/modules/disabled
/etc/selinux/targeted/modules/active/modules
/etc/selinux/targeted/logins
/etc/selinux/final
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /etc/selinux/tmp
total 0
[root@node101.yinzhengjie.org.cn ~]# ll /etc/selinux/targeted/active/modules/disabled
total 0
[root@node101.yinzhengjie.org.cn ~]# ll /etc/selinux/targeted/modules/active/modules
total 0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /etc/selinux/targeted/logins
total 0
[root@node101.yinzhengjie.org.cn ~]# ll /etc/selinux/final
total 0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/selinux/ -type d -empty          #只查看"/etc/selinux"目录下的所有空目录
[root@node101.yinzhengjie.org.cn ~]# find /etc/selinux/ -type f -empty
/etc/selinux/targeted/contexts/files/file_contexts.subs
/etc/selinux/targeted/semanage.trans.LOCK
/etc/selinux/targeted/semanage.read.LOCK
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/selinux/targeted/contexts/files/file_contexts.subs
[root@node101.yinzhengjie.org.cn ~]# cat /etc/selinux/targeted/semanage.trans.LOCK
[root@node101.yinzhengjie.org.cn ~]# cat /etc/selinux/targeted/semanage.read.LOCK
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/selinux/ -type f -empty          #只查看"/etc/selinux"目录下的所有空文件

10>.组合查找

[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -a -user root        #在"/etc"目录下查找以".sh"结尾,而且用户名是root的文件,这是逻辑与的关系。
/etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
/etc/profile.d/less.sh
/etc/profile.d/which2.sh
/etc/profile.d/256term.sh
/etc/profile.d/vim.sh
/etc/profile.d/colorgrep.sh
/etc/profile.d/colorls.sh
/etc/profile.d/lang.sh
/etc/dhcp/dhclient.d/chrony.sh
/etc/dhcp/dhclient-exit-hooks.d/azure-cloud.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -user root             #匹配多个条件时默认就是逻辑与的关系
/etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
/etc/profile.d/less.sh
/etc/profile.d/which2.sh
/etc/profile.d/256term.sh
/etc/profile.d/vim.sh
/etc/profile.d/colorgrep.sh
/etc/profile.d/colorls.sh
/etc/profile.d/lang.sh
/etc/dhcp/dhclient.d/chrony.sh
/etc/dhcp/dhclient-exit-hooks.d/azure-cloud.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -user root | wc -l
10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -a -user root | wc -l
10
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -a -user root        #在"/etc"目录下查找以".sh"结尾,而且用户名是root的文件,这是逻辑与的关系。
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -a -user apache
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -o -user apache        #在"/etc"目录下查找以".sh"结尾,或者用户名是apache的文件,这是逻辑或的关系。
/etc/kernel/postinst.d/51-dracut-rescue-postinst.sh
/etc/profile.d/less.sh
/etc/profile.d/which2.sh
/etc/profile.d/256term.sh
/etc/profile.d/vim.sh
/etc/profile.d/colorgrep.sh
/etc/profile.d/colorls.sh
/etc/profile.d/lang.sh
/etc/dhcp/dhclient.d/chrony.sh
/etc/dhcp/dhclient-exit-hooks.d/azure-cloud.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -name "*.sh" -o -user apache        #在"/etc"目录下查找以".sh"结尾,或者用户名是apache的文件,这是逻辑或的关系。
[root@node101.yinzhengjie.org.cn ~]# ll /etc/pki/ca-trust/                                  
total 16
-rw-r--r--. 1 root root  980 May 14  2018 ca-legacy.conf
drwxr-xr-x. 5 root root 4096 Sep  5 01:48 extracted
-rw-r--r--. 1 root root  166 May 14  2018 README
drwxr-xr-x. 4 root root 4096 Sep  5 01:48 source
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ca-trust/ ! -name "*.conf"                   #查找"/etc/pki/ca-trust"不是以".conf"结尾的文件或目录。                  
/etc/pki/ca-trust/
/etc/pki/ca-trust/README
/etc/pki/ca-trust/source
/etc/pki/ca-trust/source/anchors
/etc/pki/ca-trust/source/blacklist
/etc/pki/ca-trust/source/ca-bundle.legacy.crt
/etc/pki/ca-trust/source/README
/etc/pki/ca-trust/extracted
/etc/pki/ca-trust/extracted/README
/etc/pki/ca-trust/extracted/pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/README
/etc/pki/ca-trust/extracted/openssl
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/openssl/README
/etc/pki/ca-trust/extracted/java
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/java/README
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/pki/ca-trust/ ! -name "*.conf"       #查找"/etc/pki/ca-trust"不是以".conf"结尾的文件或目录。

11>.德·摩根定律 

(非 A)或 (非 B) = 非(A 且 B)
(非 A)且 (非 B) = 非(A 或 B)

示例:
    !A -a !B = !(A -o B) 
    !A -o !B = !(A -a B)
[root@node101.yinzhengjie.org.cn ~]# mkdir /etc/yinzhengjie
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chown yinzhengjie /etc/yinzhengjie/
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# su -l yinzhengjie
Last login: Mon Sep  9 04:52:36 EDT 2019 on pts/0
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ 
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ touch a{1..3}.txt
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ 
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ 
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ touch /etc/yinzhengjie/httpd{1..3}.conf
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ 
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ echo "yinzhengjie.org.cn" > /etc/yinzhengjie/domain.info
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ 
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ ll /etc/yinzhengjie/
total 4
-rw-rw-r-- 1 yinzhengjie yinzhengjie 19 Dec 12 19:50 domain.info
-rw-rw-r-- 1 yinzhengjie yinzhengjie  0 Dec 12 19:49 httpd1.conf
-rw-rw-r-- 1 yinzhengjie yinzhengjie  0 Dec 12 19:49 httpd2.conf
-rw-rw-r-- 1 yinzhengjie yinzhengjie  0 Dec 12 19:49 httpd3.conf
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ 
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ exit 
logout
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not \( -user root -o -user apache \)        #在"/etc"目录下找到属主不是root或者apache的文件
/etc/polkit-1/rules.d
/etc/yinzhengjie
/etc/yinzhengjie/httpd3.conf
/etc/yinzhengjie/httpd1.conf
/etc/yinzhengjie/httpd2.conf
/etc/yinzhengjie/domain.info
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not \( -user root -o -user apache \) -ls
786771    4 drwx------   2 polkitd  root         4096 Sep  5 01:49 /etc/polkit-1/rules.d
788795    4 drwxr-xr-x   2 yinzhengjie root         4096 Dec 12 19:50 /etc/yinzhengjie
788827    0 -rw-rw-r--   1 yinzhengjie yinzhengjie        0 Dec 12 19:49 /etc/yinzhengjie/httpd3.conf
788824    0 -rw-rw-r--   1 yinzhengjie yinzhengjie        0 Dec 12 19:49 /etc/yinzhengjie/httpd1.conf
788825    0 -rw-rw-r--   1 yinzhengjie yinzhengjie        0 Dec 12 19:49 /etc/yinzhengjie/httpd2.conf
788828    4 -rw-rw-r--   1 yinzhengjie yinzhengjie       19 Dec 12 19:50 /etc/yinzhengjie/domain.info
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not \( -user root -o -user apache \) | wc -l
6
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not \( -user root -o -user apache \)        #在"/etc"目录下找到属主不是root或者apache的文件
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not -user  root  -a -not -user  apache                   #在"/etc"目录下递归查找属主不是root而且属主也不是apache的所有文件
/etc/polkit-1/rules.d
/etc/yinzhengjie
/etc/yinzhengjie/httpd3.conf
/etc/yinzhengjie/httpd1.conf
/etc/yinzhengjie/httpd2.conf
/etc/yinzhengjie/domain.info
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not -user  root  -a -not -user  apache  | wc -l    
6
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not -user  root  -a -not -user  apache  -ls
786771    4 drwx------   2 polkitd  root         4096 Sep  5 01:49 /etc/polkit-1/rules.d
788795    4 drwxr-xr-x   2 yinzhengjie root         4096 Dec 12 19:50 /etc/yinzhengjie
788827    0 -rw-rw-r--   1 yinzhengjie yinzhengjie        0 Dec 12 19:49 /etc/yinzhengjie/httpd3.conf
788824    0 -rw-rw-r--   1 yinzhengjie yinzhengjie        0 Dec 12 19:49 /etc/yinzhengjie/httpd1.conf
788825    0 -rw-rw-r--   1 yinzhengjie yinzhengjie        0 Dec 12 19:49 /etc/yinzhengjie/httpd2.conf
788828    4 -rw-rw-r--   1 yinzhengjie yinzhengjie       19 Dec 12 19:50 /etc/yinzhengjie/domain.info
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -not -user root -a -not -user apache         #和上面的功能一样,在"/etc"目录下递归查找属主不是root而且属主也不是apache的所有文件

12>.根据文件大小来查找 

-size [+|-]#UNIT
  常用单位:
    k, M, G,c(
byte)
  #UNIT: (#-1, #]     如:6k 表示(5k,6k],即查找大于5k小于等于6k的文件。
  -#UNIT:[0,#-1]     如:-6k 表示[0,6k],即查找小于6k的文件。
  +#UNIT:(#,∞)     如:+6k 表示(6k,∞),即查找大于6k的文件。 
[root@node101.yinzhengjie.org.cn ~]# dd if=/dev/zero of=a.txt bs=1K count=10   
10+0 records in
10+0 records out
bytes (10 kB) copied, 0.000461065 s, 22.2 MB/s
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# dd if=/dev/zero of=b.txt bs=1K count=9   
9+0 records in
9+0 records out
bytes (9.2 kB) copied, 0.000257093 s, 35.8 MB/s
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# dd if=/dev/zero of=c.txt bs=1K count=11  
11+0 records in
11+0 records out
bytes (11 kB) copied, 0.000290539 s, 38.8 MB/s
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# dd if=/dev/zero of=d4.txt bs=1K count=9 
9+0 records in
9+0 records out
bytes (9.2 kB) copied, 0.000514858 s, 17.9 MB/s
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw-r--r-- 1 root root 10240 Dec 12 20:23 a.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:23 b.txt
-rw-r--r-- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll -h
total 48K
-rw-r--r-- 1 root root  10K Dec 12 20:23 a.txt
-rw-r--r-- 1 root root 9.0K Dec 12 20:23 b.txt
-rw-r--r-- 1 root root  11K Dec 12 20:23 c.txt
-rw-r--r-- 1 root root 9.0K Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size 10k
./a.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo >> b.txt       #追加换行符"\n",即增加一个字节。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw-r--r-- 1 root root 10240 Dec 12 20:23 a.txt
-rw-r--r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--r-- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll -h         
total 48K
-rw-r--r-- 1 root root  10K Dec 12 20:23 a.txt
-rw-r--r-- 1 root root 9.1K Dec 12 20:25 b.txt
-rw-r--r-- 1 root root  11K Dec 12 20:23 c.txt
-rw-r--r-- 1 root root 9.0K Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size 10k
./a.txt
./b.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size 10k -ls        #注意,size命令是模糊匹配,即匹配10k表示大于9k小于等于10k的文件。
  12 -rw-r--r--   1 root     root        10240 Dec 12 20:23 ./a.txt
  12 -rw-r--r--   1 root     root         9217 Dec 12 20:25 ./b.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size 10k -ls        #注意,size命令是模糊匹配,即查找10k表示大于9k小于等于10k的文件。
[root@node101.yinzhengjie.org.cn ~]# find -size -10k -ls        #和上面不同,"-10k"表示匹配小于10k的文件哟
   4 dr-xr-x---   3 root     root         4096 Dec 12 20:24 .
   4 -rw-------   1 root     root           48 Sep  5 03:31 ./.lesshst
   4 -rw-r--r--   1 root     root          176 Dec 28  2013 ./.bash_profile
  12 -rw-r--r--   1 root     root         9216 Dec 12 20:24 ./d4.txt
   4 -rw-r--r--   1 root     root          129 Dec 28  2013 ./.tcshrc
   4 -rw-r--r--   1 root     root          100 Dec 28  2013 ./.cshrc
   8 -rw-------   1 root     root         6442 Dec 11 17:32 ./.viminfo
   4 -rw-r--r--   1 root     root           18 Dec 28  2013 ./.bash_logout
   4 drwxr-----   3 root     root         4096 Dec 11 16:20 ./.pki
   4 drwxr-----   2 root     root         4096 Dec 11 16:20 ./.pki/nssdb
   4 -rw-r--r--   1 root     root          176 Dec 28  2013 ./.bashrc
   4 -rw-------   1 root     root         1191 Dec 12 09:08 ./.mysql_history
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size -10k -ls        #和上面不同,"-10k"表示查找小于10k的文件哟
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw-r--r-- 1 root root 10240 Dec 12 20:23 a.txt
-rw-r--r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--r-- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll -h
total 48K
-rw-r--r-- 1 root root  10K Dec 12 20:23 a.txt
-rw-r--r-- 1 root root 9.1K Dec 12 20:25 b.txt
-rw-r--r-- 1 root root  11K Dec 12 20:23 c.txt
-rw-r--r-- 1 root root 9.0K Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size +10k -ls
  24 -rw-------   1 root     root        21053 Dec 12 20:09 ./.bash_history
  12 -rw-r--r--   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo >> a.txt              #添加一个"\n"字节
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size +10k -ls          #表示查找大于10k的文件
  24 -rw-------   1 root     root        21053 Dec 12 20:09 ./.bash_history
  12 -rw-r--r--   1 root     root        10241 Dec 12 20:35 ./a.txt
  12 -rw-r--r--   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -size +10k -ls        #表示查找大于10k的文件

13>.根据时间戳查找 

""为单位:
  -atime(可以指定创建时间的天数范围)
    #: [#,#+1)
      如10,表示[10,11),即查找大于10天小于第11天的文件
    +#: [#+1,∞]
      如10,表示[11,∞],即查找大于10天的文件       

    -#: [0,#)
      如10,表示[0,10),即查找小于10天的文件
  -mtime(和atime一样,也可以指定修改天数范围)
  -ctime(和atime一样,也可以指定创建天数范围) 

以"分钟"为单位(按照分钟和按照天数用法几乎一样,只不过单位时间不同而已,指定时间范围,如下图所示。)
  -amin 
  -mmin 
  -cmin
[root@node101.yinzhengjie.org.cn ~]# useradd jason
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -mmin -1 -ls      #表示查找1分钟之内修改的文件
786433    4 drwxr-xr-x  77 root     root         4096 Dec 12 20:51 /etc/
788826    4 ----------   1 root     root          603 Dec 12 20:51 /etc/shadow
788833    4 -rw-r--r--   1 root     root         1051 Dec 12 20:51 /etc/passwd
788779    4 -rw-r--r--   1 root     root          544 Dec 12 20:51 /etc/group
788823    4 ----------   1 root     root          438 Dec 12 20:51 /etc/gshadow
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# date 
Thu Dec 12 20:52:07 EST 2019
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find /etc/ -mmin -1 -ls      #表示查找1分钟之内修改的文件
 

14>.根据权限查找

-perm [/|-]MODE
  MODE: 
    精确权限匹配   
/MODE:
    任何一类(u,g,o)对象的权限中只要能一位匹配即可,或关系,+ 从centos7开始淘汰   -MODE:
    每一类对象都必须同时拥有指定权限,与关系 0 表示不关注
示例:
  find -perm 755 会匹配权限模式恰好是755的文件   只要当任意人有写权限时,find -perm +222就会匹配   只有当每个人都有写权限时,find -perm -222才会匹配   只有当其它人(other)有写权限时,find -perm -002才会匹配
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw-r--r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw-r--r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--r-- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chmod 640 a.txt 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm 640 -ls        #在当前目录下查找权限是640的文件
1048583   12 -rw-r-----   1 root     root        10241 Dec 12 20:35 ./a.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw-r----- 1 root root 10241 Dec 12 20:35 a.txt
-rw-r--r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--r-- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm 640 -ls        #在当前目录下精确查找权限是640的文件 
[root@node101.yinzhengjie.org.cn ~]# find -perm -640 -ls        #权限640对应着"rw-r-----",即要求所有者必须拥有读写权限,所属组有权限,0表示不关心,即有没有权限无所谓。
   4 -rw-r--r--   1 root     root          176 Dec 28  2013 ./.bash_profile
  12 -rw-r--r--   1 root     root         9216 Dec 12 20:24 ./d4.txt
   4 -rw-r--r--   1 root     root          129 Dec 28  2013 ./.tcshrc
   4 -rw-r--r--   1 root     root          100 Dec 28  2013 ./.cshrc
   4 -rw-r--r--   1 root     root           18 Dec 28  2013 ./.bash_logout
  12 -rw-r-----   1 root     root        10241 Dec 12 20:35 ./a.txt
   4 drwxr-----   3 root     root         4096 Dec 11 16:20 ./.pki
   4 drwxr-----   2 root     root         4096 Dec 11 16:20 ./.pki/nssdb
   4 -rw-r--r--   1 root     root          176 Dec 28  2013 ./.bashrc
  12 -rw-r--r--   1 root     root         9217 Dec 12 20:25 ./b.txt
  12 -rw-r--r--   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chmod g-r a.txt b.txt 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -640 -ls                         #再次匹配时发现匹配不到a.txt和b.txt文件啦,因为这两个文件的所属组权限不满足咱们咋着条件4啦。
1048579    4 -rw-r--r--   1 root     root          176 Dec 28  2013 ./.bash_profile
1056283   12 -rw-r--r--   1 root     root         9216 Dec 12 20:24 ./d4.txt
1048582    4 -rw-r--r--   1 root     root          129 Dec 28  2013 ./.tcshrc
1048581    4 -rw-r--r--   1 root     root          100 Dec 28  2013 ./.cshrc
1048578    4 -rw-r--r--   1 root     root           18 Dec 28  2013 ./.bash_logout
1049804    4 drwxr-----   3 root     root         4096 Dec 11 16:20 ./.pki
1049806    4 drwxr-----   2 root     root         4096 Dec 11 16:20 ./.pki/nssdb
1048580    4 -rw-r--r--   1 root     root          176 Dec 28  2013 ./.bashrc
1048588   12 -rw-r--r--   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw----r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--r-- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -640 -ls        #权限640对应着"rw-r-----",即要求所有者必须拥有读写权限,所属组有权限,0表示不关心,即有没有权限无所谓。
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -ls
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw----r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--r-- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chmod a+w a.txt c.txt 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw--w-rw- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-rw-rw- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -ls          #这里强制要求所有者,所属组和其他人都必须有写入权限。
1048583   12 -rw--w-rw-   1 root     root        10241 Dec 12 20:35 ./a.txt
1048588   12 -rw-rw-rw-   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -ls        #这里强制要求所有者,所属组和其他人都必须有写入权限。 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw--w-rw- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-rw-rw- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--r-- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -642 -ls          #表示查找所有者必须有rw权限,所属组必须有r权限,其他人必须有w权限。
1048588   12 -rw-rw-rw-   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -642 -ls         #表示查找所有者必须有rw权限,所属组必须有r权限,其他人必须有w权限。
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-rw-rw- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--rw- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm /022 -ls          #022对应的权限为"----w--w-",表示查找所属组或者其他人有写入权限的文件,即2个条件满足一个即可。
1056283   12 -rw-r--rw-   1 root     root         9216 Dec 12 20:24 ./d4.txt
1048583   12 -rw--w-r--   1 root     root        10241 Dec 12 20:35 ./a.txt
1048588   12 -rw-rw-rw-   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm /022 -ls          #022对应的权限为"----w--w-",表示查找所属组或者其他人有写入权限的文件,即2个条件满足一个即可。

15>.处理动作 

搜索到文件后咱们可以做相应的处理,find命令支持以下处理动作:
  print:
    默认的处理动作,显示至屏幕   
-ls:
    类似于对查找到的文件执行"ls -l"命令   -delete:
    删除查找到的文件   
-fls file:
    查找到的所有文件的长格式信息保存至指定文件中   
-ok COMMAND {} \;
    对查找到的每个文件执行由COMMAND指定的命令,{}表示引用查找到的文件名称自身,"\;"表示命令执行结束标示符。ok表示对于每个文件执行命令之前,都会交互式要求用户确认。   exec COMMAND {} \;
    对查找到的每个文件执行由COMMAND指定的命令,和上面到功能类似,只不过执行命令时并不会有交互式要求用户确认,虽然方便,但是我们应该注意安全使用。   {}:
    用于引用查找到的文件名称自身
find传递查找到的文件至后面指定的命令时,查找到所有符合条件的文件一次性传递给后面的命令
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-rw-rw- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--rw- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -ls        #将查找的文件以常列表的形式列举出来。
1048588   12 -rw-rw-rw-   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -ls                        #将查找的文件以常列表的形式列举出来。
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -ls
1048588   12 -rw-rw-rw-   1 root     root        11264 Dec 12 20:23 ./c.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 48
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-rw-rw- 1 root root 11264 Dec 12 20:23 c.txt
-rw-r--rw- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -delete      #将查找到的文件直接删除掉
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 36
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--rw- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -222 -delete                      #将查找到的文件直接删除掉
[root@node101.yinzhengjie.org.cn ~]# ll
total 36
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--rw- 1 root root  9216 Dec 12 20:24 d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -002 -ls
1056283   12 -rw-r--rw-   1 root     root         9216 Dec 12 20:24 ./d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -002 -fls /root/res.log          #将查找到的结果重定向到指定文件中。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat res.log 
1056283   12 -rw-r--rw-   1 root     root         9216 Dec 12 20:24 ./d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -002 -ls > /root/res2.log
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat res2.log                         
1056283   12 -rw-r--rw-   1 root     root         9216 Dec 12 20:24 ./d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -002 -fls /root/res.log                #将查找到的结果重定向到指定文件中。
[root@node101.yinzhengjie.org.cn ~]# ll
total 44
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--rw- 1 root root  9216 Dec 12 20:24 d4.txt
-rw-r--r-- 1 root root    77 Dec 12 21:39 res2.log
-rw-r--r-- 1 root root    77 Dec 12 21:38 res.log
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -002 -ls 
1056283   12 -rw-r--rw-   1 root     root         9216 Dec 12 20:24 ./d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -002 -ok mv {} /tmp \;
< mv ... ./d4.txt > ? y
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 32
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
-rw-r--r-- 1 root root    77 Dec 12 21:39 res2.log
-rw-r--r-- 1 root root    77 Dec 12 21:38 res.log
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /tmp/d4.txt 
-rw-r--rw- 1 root root 9216 Dec 12 20:24 /tmp/d4.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -perm -002 -ok mv {} /tmp \;                #将查找到的文件移动到"/tmp"目录下,只能移动文件不能移动目录。使用-ok语法必须使用"\;"表示命令结束,而且执行命令前还会有交互式信息呢。
[root@node101.yinzhengjie.org.cn ~]# ll
total 32
drwxr-xr-x 2 root root  4096 Dec 12 21:51 apache
-rw--w-r-- 1 root root 10241 Dec 12 20:35 a.txt
-rw----r-- 1 root root  9217 Dec 12 20:25 b.txt
drwxr-xr-x 2 root root  4096 Dec 12 21:51 nginx
-rw-r--r-- 1 root root    77 Dec 12 21:39 res2.log
-rw-r--r-- 1 root root    77 Dec 12 21:38 res.log
drwxr-xr-x 2 root root  4096 Dec 12 21:51 tomcat
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -type f -exec chmod a=rwx {} \;               #在当前目录下查找所有到文件类型并授权为"rwx"
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 44
drwxr-xr-x 2 root root  4096 Dec 12 21:51 apache
-rwxrwxrwx 1 root root 10241 Dec 12 20:35 a.txt
-rwxrwxrwx 1 root root  9217 Dec 12 20:25 b.txt
drwxr-xr-x 2 root root  4096 Dec 12 21:51 nginx
-rwxrwxrwx 1 root root    77 Dec 12 21:39 res2.log
-rwxrwxrwx 1 root root    77 Dec 12 21:38 res.log
drwxr-xr-x 2 root root  4096 Dec 12 21:51 tomcat
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -type f -exec chmod a=rwx {} \;               #在当前目录下查找所有到文件类型并授权为"rwx",和上面相比,不会有交互界面。

 

  如上图所示,首先看一下我的家目录/root下被标记的文件,其次,让我们用find这个命令去做一件事情,如下图所示。 

  学东西要学会举一反三,我要删除30天之前的文件怎么搞呢?先闭上眼睛想一想,然后看看你跟我的操作是一样的吗?如下图所示。

 

三.xargs参数传递

xargs的由来:
  由于很多命令不支持管道|来传递参数,而日常工作中有这个必要,所以就有了xargs命令。

xargs的功能:
  xargs用于产生某个命令的参数,xargs可以读入stdin的数据,并且以空格符或回车符将stdin的数据分隔成为arguments。
  有些命令不能接受过多参数,命令执行可能会失败,xargs可以解决。

注意:
  文件名或者是其他意义的名词内含有空格符的情况 

1>.xargs的默认处理方式

[root@node101.yinzhengjie.org.cn ~]# seq 10
1
2
3
4
5
6
7
8
9
10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs                      #默认情况下,xargs可以读入stdin的数据,并且以空格符将数据分为多个arguments
1 2 3 4 5 6 7 8 9 10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs                         #默认情况下,xargs可以读入stdin的数据,并且以空格符将数据分为多个arguments
[root@node101.yinzhengjie.org.cn ~]# seq 10
1
2
3
4
5
6
7
8
9
10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs    
1 2 3 4 5 6 7 8 9 10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs echo
1 2 3 4 5 6 7 8 9 10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs echo                      #和上面输出等效

2>.将上一个标准输出的参数作为在一个命令的参数传递

[root@node101.yinzhengjie.org.cn ~]# echo "/etc/fstab"
/etc/fstab
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo "/etc/fstab" | xargs cat            #xargs可以将echo的标准输出传递给cat命令作为参数

#
# /etc/fstab
# Created by anaconda on Thu Sep  5 01:48:13 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=4e7ecb93-20a7-4ced-bf95-91974fc0b66a /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_home /home                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Sep  5 01:48:13 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=4e7ecb93-20a7-4ced-bf95-91974fc0b66a /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_home /home                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo "/etc/fstab" | xargs cat                #xargs可以将echo的标准输出传递给cat命令作为参数

3>."-n"参数使用

[root@node101.yinzhengjie.org.cn ~]# seq 10
1
2
3
4
5
6
7
8
9
10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs -n 2        
1 2
3 4
5 6
7 8
9 10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs -n 3            #可以通过"-n"来指定每行显示的最大参数个数。
1 2 3
4 5 6
7 8 9
10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# seq 10 | xargs -n 3                       #可以通过"-n"来指定每行显示的最大参数个数。

4>.删除使用find命令找到的参数 

[root@node101.yinzhengjie.org.cn ~]# touch "user name.txt"
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# touch file{1..3}.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 4
-rw-r--r-- 1 root root  0 Dec 13 17:24 file1.txt
-rw-r--r-- 1 root root  0 Dec 13 17:24 file2.txt
-rw-r--r-- 1 root root  0 Dec 13 17:24 file3.txt
-rw-r--r-- 1 root root  0 Dec 13 17:24 user name.txt
-rw-r--r-- 1 root root 27 Dec 13 17:12 user.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# mkdir nginx tomcat httpd
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 16
-rw-r--r-- 1 root root    0 Dec 13 17:24 file1.txt
-rw-r--r-- 1 root root    0 Dec 13 17:24 file2.txt
-rw-r--r-- 1 root root    0 Dec 13 17:24 file3.txt
drwxr-xr-x 2 root root 4096 Dec 13 17:25 httpd
drwxr-xr-x 2 root root 4096 Dec 13 17:25 nginx
drwxr-xr-x 2 root root 4096 Dec 13 17:25 tomcat
-rw-r--r-- 1 root root    0 Dec 13 17:24 user name.txt
-rw-r--r-- 1 root root   27 Dec 13 17:12 user.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -name "*.txt" -print0 | xargs -0 ls
./file1.txt  ./file2.txt  ./file3.txt  ./user name.txt  ./user.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -name "*.txt" -print0 | xargs -0 rm        #删除匹配查找到到文件,注意"-print0"表示不以默认空格符来切分文件,而是使用ASCII表到0来分隔开文件,通常要和xargs到"-0"配合使用。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 12
drwxr-xr-x 2 root root 4096 Dec 13 17:25 httpd
drwxr-xr-x 2 root root 4096 Dec 13 17:25 nginx
drwxr-xr-x 2 root root 4096 Dec 13 17:25 tomcat
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# find -name "*.txt" -print0 | xargs -0 rm          #删除匹配查找到到文件,注意"-print0"表示不以默认空格符来切分文件,而是使用ASCII表到0来分隔开文件,通常要和xargs到"-0"(表示null)配合使用。

5>.批量创建和删除用户案例

[root@node101.yinzhengjie.org.cn ~]# echo user{1..10} | xargs -n 1
user1
user2
user3
user4
user5
user6
user7
user8
user9
user10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grep user /etc/passwd
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo user{1..10} | xargs -n 1 useradd             #可以使用该命令批量创建10个用户
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grep user /etc/passwd                 
user1:x:1001:1001::/home/user1:/bin/bash
user2:x:1002:1002::/home/user2:/bin/bash
user3:x:1003:1003::/home/user3:/bin/bash
user4:x:1004:1004::/home/user4:/bin/bash
user5:x:1005:1005::/home/user5:/bin/bash
user6:x:1006:1006::/home/user6:/bin/bash
user7:x:1007:1007::/home/user7:/bin/bash
user8:x:1008:1008::/home/user8:/bin/bash
user9:x:1009:1009::/home/user9:/bin/bash
user10:x:1010:1010::/home/user10:/bin/bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo user{1..10} | xargs -n 1 useradd             #可以使用该命令批量创建10个用户
[root@node101.yinzhengjie.org.cn ~]# ll /home/
total 60
drwx------. 2 root        root        16384 Sep  5 01:48 lost+found
drwx------  2 user1       user1        4096 Dec 13 17:07 user1
drwx------  2 user10      user10       4096 Dec 13 17:07 user10
drwx------  2 user2       user2        4096 Dec 13 17:07 user2
drwx------  2 user3       user3        4096 Dec 13 17:07 user3
drwx------  2 user4       user4        4096 Dec 13 17:07 user4
drwx------  2 user5       user5        4096 Dec 13 17:07 user5
drwx------  2 user6       user6        4096 Dec 13 17:07 user6
drwx------  2 user7       user7        4096 Dec 13 17:07 user7
drwx------  2 user8       user8        4096 Dec 13 17:07 user8
drwx------  2 user9       user9        4096 Dec 13 17:07 user9
drwx------. 7 yinzhengjie yinzhengjie  4096 Dec 12 19:48 yinzhengjie
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grep user /etc/passwd
user1:x:1001:1001::/home/user1:/bin/bash
user2:x:1002:1002::/home/user2:/bin/bash
user3:x:1003:1003::/home/user3:/bin/bash
user4:x:1004:1004::/home/user4:/bin/bash
user5:x:1005:1005::/home/user5:/bin/bash
user6:x:1006:1006::/home/user6:/bin/bash
user7:x:1007:1007::/home/user7:/bin/bash
user8:x:1008:1008::/home/user8:/bin/bash
user9:x:1009:1009::/home/user9:/bin/bash
user10:x:1010:1010::/home/user10:/bin/bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo user{1..10} | xargs -n 1 userdel -r          #咱们也可以批量删除用户了
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /home/                               
total 20
drwx------. 2 root        root        16384 Sep  5 01:48 lost+found
drwx------. 7 yinzhengjie yinzhengjie  4096 Dec 12 19:48 yinzhengjie
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grep user /etc/passwd                   
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo user{1..10} | xargs -n 1 userdel -r          #咱们也可以批量删除用户了
[root@node101.yinzhengjie.org.cn ~]# cat user.txt
jason100
jason200
jason300
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat user.txt | xargs -n 1 
jason100
jason200
jason300
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat user.txt | xargs -n 1 useradd
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grep jason /etc/passwd
jason100:x:1001:1001::/home/jason100:/bin/bash
jason200:x:1002:1002::/home/jason200:/bin/bash
jason300:x:1003:1003::/home/jason300:/bin/bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat user.txt | xargs -n 1 userdel -r
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grep jason /etc/passwd              
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat user.txt | xargs -n 1 useradd              #也可以读取文件文件内容并进行创建或删除用户

6>.查看xargs命令的帮助信息

[root@node101.yinzhengjie.org.cn ~]# xargs --help
Usage: xargs [OPTION]... COMMAND INITIAL-ARGS...
Run COMMAND with arguments INITIAL-ARGS and more arguments read from input.

Mandatory arguments to long options are mandatory for short options too.
Non-mandatory arguments are indicated by [square brackets]
  -0, --null                   Items are separated by a null, not whitespace.
                               Disables quote and backslash processing
  -a, --arg-file=FILE          Read arguments from FILE, not standard input
  -d, --delimiter=CHARACTER    Input items are separated by CHARACTER, not by
                               blank space. Disables quote and backslash
                               processing
  -E END                       If END occurs as a line of input, the rest of
                               the input is ignored.
  -e [END], --eof[=END]        Equivalent to -E END if END is specified.
                               Otherwise, there is no end-of-file string
  --help                       Print a summary of the options to xargs.
  -I R                         same as --replace=R (R must be specified)
  -i,--replace=[R]             Replace R in initial arguments with names
                               read from standard input. If R is
                               unspecified, assume {}
  -L,-l, --max-lines=MAX-LINES Use at most MAX-LINES nonblank input lines per
                               command line
  -l                           Use at most one nonblank input line per
                               command line
  -n, --max-args=MAX-ARGS      Use at most MAX-ARGS arguments per command
                               line
  -P, --max-procs=MAX-PROCS    Run up to max-procs processes at a time
  -p, --interactive            Prompt before running commands
  --process-slot-var=VAR       Set environment variable VAR in child
                               processes
  -r, --no-run-if-empty        If there are no arguments, run no command.
                               If this option is not given, COMMAND will be
                               run at least once.
  -s, --max-chars=MAX-CHARS    Limit commands to MAX-CHARS at most
  --show-limits                Show limits on command-line length.
  -t, --verbose                Print commands before executing them
  --version                    Print the version number
  -x, --exit                   Exit if the size (see -s) is exceeded

Report bugs to <bug-findutils@gnu.org>.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# xargs --help 
posted @ 2016-12-21 12:56  尹正杰  阅读(83998)  评论(0编辑  收藏  举报