Linux - 文件查找方法

本文介绍了在Linux环境下使用which、whereis、grep及find命令进行文件查找的方法。通过具体实例展示了如何定位可执行文件、过滤特定内容及搜索指定目录下的文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文件查找方法

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开头的文件



本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/8252057.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值