find 查找

find查找
(1)根据文件名,类型查找
[root@lsr7 ~]# find / -type d -name 'ip' //查找/下面类型是目录,名字是ip的
/usr/src/kernels/3.10.0-957.5.1.el7.x86_64.debug/include/config/ip
/usr/src/kernels/3.10.0-957.5.1.el7.x86_64.debug/include/config/net/ip

[root@lsr7 ~]# find oldboy -type f -name '*.txt' //查看oldboy目录,里面以txt为结尾的文件
find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments. //警告信息-maxdepth要放在前面
(2)根据-maxdepth(文件深度查找)
[root@lsr7 oldboy]# find / -maxdepth 1 -type d //-maxdepth(最多深度)1层次是1 -type d类型是目录
/
/dev
/home
/proc
/run
/sys
[root@lsr7 ~]# find /etc/ -maxdepth 1 -type f -iname .conf //找出/etc/目录下面第1层目录中以.conf结尾的文件(不区分大小写)(mai si di pai te)
/etc/resolv.conf
/etc/libaudit.conf
(3)! 取反
[root@lsr7 ~]# find /etc/ -type f ! -iname '
.conf' //查找/etc/目录下除了conf的其它文件(不区分大小写)
/etc/zlogout
/etc/zprofile
/etc/zshenv
(4)size 根据大小查找文件
[root@lsr7 ~]# find /etc/ -size +1M //查找/etc/下大于1M的文件
[root@lsr7 ~]# find /etc/ -size -5k //查找/etc/下小于5k的文件

  1. xargs分组(只有xargs和tr用<)
    [root@lsr7 ~]# echo {A..Z} > oldboy/huahua.txt
    [root@lsr7 ~]# cat oldboy/huahua.txt
    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
    [root@lsr7 ~]# xargs -n5 < oldboy/huahua.txt
    A B C D E
    F G H I J
    K L M N O
    P Q R S T
    U V W X Y
    Z

你可能感兴趣的:(find 查找)