Linux

文件查找方法

1.which

查找可执行文件的位置

[root@local /]# which passwd
/usr/bin/passwd

2.whereis

查找可执行文件的位置与相关的文件

[root@local /]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz

3.grep

过滤

[root@local /]# grep home /etc/passwd
jiqing:x:1000:1000:jiqing:/home/jiqing:/bin/bash
www:x:1001:1001::/home/www:/sbin/nologin
zhubajie:x:2018:2018::/home/zhubajie:/bin/bash
sunwukong:x:2019:2018::/home/sunwukong:/bin/bash
niumowang:x:2020:2018::/home/niumowang:/bin/bash
[root@local /]# netstat -anpo | grep :22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      5711/sshd            off (0.00/0/0)
tcp        0     52 192.168.70.77:22        192.168.70.33:59072     ESTABLISHED 9414/sshd: root@pts  on (0.23/0/0)
tcp        0      0 192.168.70.77:22        192.168.70.33:56269     ESTABLISHED 5732/sshd: www [pri  keepalive (1019.14/0/0)
tcp6       0      0 :::22                   :::*                    LISTEN      5711/sshd            off (0.00/0/0)
-a (all)显示所有选项,默认不显示LISTEN相关。
-n 拒绝显示别名,能显示数字的全部转化成数字。
-p 显示建立相关链接的程序名。

4.find

找文件 . 当前目/ 根目录。

-type 
b 设备文件
d 目录
c 字符设备文件
p 管道文件
l 符号链接文件
f 普通文件
[root@local /]# find  / -name  passwd -type f
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[root@local /]# find  /etc/ -name  "host*"
/etc/selinux/targeted/modules/active/modules/hostname.pp
/etc/host.conf
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/avahi/hosts
/etc/hostname

搜索以host开头的文件

原文地址:https://www.cnblogs.com/jiqing9006/p/8252057.html