一、文件查找
1.which :命令查找
[root@localhost ~]#
[root@localhost ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@localhost ~]# which ll
alias ll='ls -l --color=auto'
/usr/bin/ls
[root@localhost ~]# which cat
/usr/bin/cat
[root@localhost ~]# which find
/usr/bin/find
[root@localhost ~]#
2.find: 文件查找,针对文件名
3.locate:文件查找,依赖数据库
*查找任意文件(find命令)
语法:find [path…] [options] [expression] [action]
命令 路径 选项 表达式 动作
1.按文件名字查找
[root@localhost ~]# find /etc -name "hosts"
/etc/hosts
[root@localhost ~]# find /etc -iname "HoSts"
/etc/hosts
[root@localhost ~]# find /etc -name "hos*"
/etc/selinux/targeted/active/modules/100/hostname
/etc/host.conf
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/hostname
[root@localhost ~]#
-i忽略大小写
2.按文件大小:
[root@localhost ~]# find /etc -size +5M
/etc/udev/hwdb.bin
[root@localhost ~]# find /etc -size =5M
find: Invalid argument `=5M' to -size
[root@localhost ~]#
文件大于5M,用+5M ,小于5M用-5M
3.指定查找的目录深度:
[root@localhost ~]# find / -maxdepth 4 -a -name "ifcfg-en*"
/etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost ~]# find / -maxdepth 4 -a -name "ifcfg-en*"
/etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost ~]# find / -maxdepth 3 -a -name "ifcfg-en*"
[root@localhost ~]# find / -maxdepth 3 -a -name "ifcfg-en*"
`
ifcfg-en在第四层目录,在第三层是查不到的
4按文件属主、属组找:
```powershell
[root@localhost ~]# find /home -user jack
/home/jack
/home/jack/.bash_logout
/home/jack/.bash_profile
/home/jack/.bashrc
/home/jack/1.txt
/home/jack/2.txt
/home/jack/3.txt
/home/jack/4.txt
/home/jack/5.txt
/home/jack/.bash_history
[root@localhost ~]#
属主
[root@localhost ~]# find /home -user jack
/home/jack
/home/jack/.bash_logout
/home/jack/.bash_profile
/home/jack/.bashrc
/home/jack/1.txt
/home/jack/2.txt
/home/jack/3.txt
/home/jack/4