> 查看命令所属文件
[root@localhost ~]# which ip
/usr/sbin/ip
ps: 一些命令的路径都被配置到了环境变量PATH里
echo $PATH
> 查找文件
find [options] [path...] [expression]
按文件名:
[root@localhost ~]# find /etc -name "ifcfg-eth0"
[root@localhost ~]# find /etc -iname "ifcfg-eth0" # -i忽略大小写
[root@localhost ~]# find /etc -iname "ifcfg-eth*"
按文件大小:
[root@localhost ~]# find /etc -size +3M # 大于3M
[root@localhost ~]# find /etc -size 3M
[root@localhost ~]# find /etc -size -3M
[root@localhost ~]# find /etc -size +3M -ls # -ls找到的处理动作
指定查找的目录深度:
-maxdepth levels
[root@localhost ~]# find / -maxdepth 5 -a -name "ifcfg-eth0" # -a并且,-o或者,不加-a,默认就是-a
按时间找(atime,mtime,ctime):
[root@localhost ~]# find /etc -mtime +3 # 修改时间超过3天
[root@localhost ~]# find /etc -mtime 3 # 修改时间等于3天
[root@localhost ~]# find /etc -mtime -3 # 修改时间3天以内
按文件属主、属组找:
[root@localhost ~]# find /home -user egon # 属主是egon的文件
[root@localhost ~]# find /home -group it # 属组是it组的文件
[root@localhost ~]# find /home -user egon -group it
[root@localhost ~]# find /home -user egon -a -group it # 同上意思一样
[root@localhost ~]# find /home -user egon -o -group it
[root@localhost ~]# find /home -nouser # 用户还存在,在/etc/passwd中删除了记录
[root@localhost ~]# find /home -nogroup # 用户还存在,在/etc/group中删除了记录
[root@localhost ~]# find /home -nouser -o -nogroup
按文件类型:
[root@localhost ~]# find /dev -type f # f普通
[root@localhost ~]# find /dev -type d # d目录
[root@localhost ~]# find /dev -type l # l链接
[root@localhost ~]# find /dev -type b # b块设备
[root@localhost ~]# find /dev -type c # c字符设备
[root@localhost ~]# find /dev -type s # s套接字
[root@localhost ~]# find /dev -type p # p管道文件
根据inode号查找:-inum n
[root@localhost ~]# find / -inum 1811
按文件权限:
[root@localhost ~]# find . -perm 644 -ls
[root@localhost ~]# find . -perm -644 -ls
[root@localhost ~]# find . -perm -600 -ls
[root@localhost ~]# find /sbin -perm -4000 -ls # 包含set uid
[root@localhost ~]# find /sbin -perm -2000 -ls # 包含set gid
[root@localhost ~]# find /sbin -perm -1000 -ls # 包含sticky
找到后处理的动作:
-ls
-delete
-exec
-ok
[root@localhost ~]# find /etc -name "ifcfg" -print # 必须加引号
[root@localhost ~]# find /etc -name "ifcfg" -ls
[root@localhost ~]# find /etc -name "ifcfg" -exec cp -rvf {} /tmp \; # 非交互
[root@localhost ~]# find /etc -name "ifcfg" -ok cp -rvf {} /tmp \; # 交互
[root@localhost ~]# find /etc -name "ifcfg" -exec rm -rf {} \;
[root@localhost ~]# find /etc -name "ifcfg" -delete # 同上
扩展知识:find结合xargs
[root@localhost ~]# find . -name "egon.txt" |xargs rm -rf
[root@localhost ~]# find /etc -name "ifcfg-eth0" |xargs -I {} cp -rf {} /var/tmp
[root@localhost ~]# find /test -name "ifcfg-ens33" |xargs -I {} mv {} /ttt
[root@localhost ~]# find /ttt/ -name "ifcfg" |xargs -I {} chmod 666 {}