linux查询关键词上下行_【已解决】Linux下通过关键字模糊查找搜索文件

本文介绍了在Linux中寻找包含特定关键词的文件的方法,通过`find`命令结合通配符实现模糊搜索。当遇到权限问题时,可以使用`sudo`提升权限继续搜索。例如,搜索关键词为'tomcat'或'dovecot.pem'的文件。
摘要由CSDN通过智能技术生成

【背景】

想要在Linux下面,找之前不知道放到哪里的一个tomcat的文件。

【折腾过程】

1.最后是参考:

去搜:root@bogon:openfire# find / -name '*tomcat*'

/usr/local/tomcat1

/usr/local/tomcat1/conf/tomcat-users.xml

/usr/local/tomcat1/lib/tomcat-util.jar

/usr/local/tomcat1/lib/tomcat-i18n-ja.jar

/usr/local/tomcat1/lib/tomcat-coyote.jar

/usr/local/tomcat1/lib/tomcat-i18n-fr.jar

/usr/local/tomcat1/lib/tomcat7-websocket.jar

/usr/local/tomcat1/lib/tomcat-dbcp.jar

/usr/local/tomcat1/lib/tomcat-i18n-es.jar

/usr/local/tomcat1/lib/tomcat-jdbc.jar

/usr/local/tomcat1/lib/tomcat-api.jar

/usr/local/tomcat1/webapps/manager/images/tomcat.gif

/usr/local/tomcat1/webapps/ROOT/tomcat.css

/usr/local/tomcat1/webapps/ROOT/tomcat.gif

/usr/local/tomcat1/webapps/ROOT/tomcat-power.gif

/usr/local/tomcat1/webapps/ROOT/tomcat.svg

/usr/local/tomcat1/webapps/ROOT/tomcat.png

/usr/local/tomcat1/webapps/host-manager/images/tomcat.gif

/usr/local/tomcat1/webapps/docs/images/tomcat.gif

/usr/local/tomcat1/webapps/docs/images/tomcat.svg

/usr/local/tomcat1/webapps/docs/appdev/sample/web/images/tomcat.gif

/usr/local/tomcat1/bin/tomcat-native.tar.gz

/usr/local/tomcat1/bin/tomcat-juli.jar

/usr/sbin/tomcat6

/usr/sbin/dtomcat6

/usr/bin/tomcat6-digest

/usr/bin/tomcat6-tool-wrapper

/usr/share/tomcat6

/usr/share/tomcat6/bin/tomcat-juli.jar

/usr/share/tomcat6/bin/tomcat-juli-6.0.24.jar

/usr/share/selinux/devel/include/services/tomcat.if

/usr/share/selinux/targeted/tomcat.pp.bz2

/usr/share/doc/apache-tomcat-apis-0.1

/usr/share/doc/tomcat6-6.0.24

/usr/share/java/tomcat6

/usr/share/java/tomcat6/tomcat-i18n-fr-6.0.24.jar

/usr/share/java/tomcat6/tomcat-i18n-ja.jar

/usr/share/java/tomcat6/tomcat-juli.jar

/usr/share/java/tomcat6/tomcat-coyote.jar

/usr/share/java/tomcat6/tomcat-i18n-fr.jar

/usr/share/java/tomcat6/tomcat6-jsp-2.1-api-6.0.24.jar

/usr/share/java/tomcat6/tomcat-i18n-ja-6.0.24.jar

/usr/share/java/tomcat6/tomcat6-el-2.1-api-6.0.24.jar

/usr/share/java/tomcat6/tomcat6-servlet-2.5-api-6.0.24.jar

/usr/share/java/tomcat6/tomcat-coyote-6.0.24.jar

/usr/share/java/tomcat6/tomcat-i18n-es.jar

/usr/share/java/tomcat6/extras/tomcat-juli.jar

/usr/share/java/tomcat6/extras/tomcat-juli-adapters.jar

/usr/share/java/tomcat6/tomcat-i18n-es-6.0.24.jar

/usr/share/java/apache-tomcat-apis

/usr/share/java/apache-tomcat-apis/tomcat-jsp2.1-api.jar

/usr/share/java/apache-tomcat-apis/tomcat-servlet2.5-api.jar

/usr/share/java/apache-tomcat-apis/tomcat-jsp2.0-api.jar

/usr/share/java/apache-tomcat-apis/tomcat-servlet2.4-api.jar

/usr/share/java/tomcat6-servlet-2.5-api.jar

/usr/share/java/tomcat6-jsp-2.1-api-6.0.24.jar

/usr/share/java/tomcat6-el-2.1-api-6.0.24.jar

/usr/share/java/tomcat6-servlet-2.5-api-6.0.24.jar

/usr/share/java/tomcat6-el-2.1-api.jar

/usr/share/java/tomcat6-jsp-2.1-api.jar

/var/lib/tomcat6

/var/lib/tomcat6/webapps/manager/images/tomcat.gif

/var/lib/tomcat6/webapps/sample/images/tomcat.gif

/var/lib/tomcat6/webapps/ROOT/tomcat.gif

/var/lib/tomcat6/webapps/ROOT/tomcat-power.gif

/var/lib/tomcat6/webapps/ROOT/tomcat.svg

/var/lib/tomcat6/webapps/host-manager/images/tomcat.gif

/var/lib/yum/yumdb/a/e35f1b8f8c6e2f285fc0214286e0b03beaf5e852-apache-tomcat-apis-0.1-1.el6-noarch

/var/lib/yum/yumdb/t/0c3c81b5aaba908a837902db4cba8076f2e7cc5d-tomcat6-lib-6.0.24-83.el6_6-x86_64

/var/lib/yum/yumdb/t/02426ee47b3a07f259586c51c37c8359f1c7627d-tomcat6-servlet-2.5-api-6.0.24-83.el6_6-x86_64

/var/lib/yum/yumdb/t/b60f2e9f994eb122122cf02114b51164ff7dd4c3-tomcat6-admin-webapps-6.0.24-83.el6_6-x86_64

/var/lib/yum/yumdb/t/f3acc3eab248f6f1009abdc219c1d3bea9a025ec-tomcat6-webapps-6.0.24-83.el6_6-x86_64

/var/lib/yum/yumdb/t/508295a2c951bee066ef29f46f78a02b6c50a11c-tomcat6-el-2.1-api-6.0.24-83.el6_6-x86_64

/var/lib/yum/yumdb/t/bc2836feb5319c5623fe1c243697dba038203642-tomcat6-6.0.24-83.el6_6-x86_64

/var/lib/yum/yumdb/t/9cd8fa43f523ea3019f4e806f1cb75cbd65343df-tomcat6-jsp-2.1-api-6.0.24-83.el6_6-x86_64

/var/run/tomcat6.pid

/var/log/tomcat6

/var/log/tomcat6-initd.log

/var/lock/subsys/tomcat6

/var/cache/tomcat6

/etc/tomcat6

/etc/tomcat6/tomcat-users.xml

/etc/tomcat6/tomcat6.conf

/etc/selinux/targeted/modules/active/modules/tomcat.pp

/etc/rc.d/init.d/tomcat6

/etc/rc.d/rc4.d/K20tomcat6

/etc/rc.d/rc2.d/K20tomcat6

/etc/rc.d/rc1.d/K20tomcat6

/etc/rc.d/rc6.d/K20tomcat6

/etc/rc.d/rc3.d/K20tomcat6

/etc/rc.d/rc5.d/K20tomcat6

/etc/rc.d/rc0.d/K20tomcat6

/etc/logrotate.d/tomcat6

/etc/sysconfig/tomcat6

/tmp/hsperfdata_tomcat

root@bogon:openfire#

2.后来又去试试其他的:crifan@crifan:~$ find / -name '*dovecot.pem*'

find: ‘/sys/kernel/debug’: Permission denied

find: ‘/home/vmail’: Permission denied

/home/crifan/mail_server/dovecot/certs/dovecot.pem

/home/crifan/mail_server/dovecot/private/dovecot.pem

find: ‘/tmp/systemd-private-rCKJi3’: Permission denied

find: ‘/tmp/systemd-private-Fuif7J’: Permission denied

find: ‘/tmp/systemd-private-FhTYag’: Permission denied

find: ‘/run/httpd’: Permission denied

find: ‘/run/dovecot/token-login’: Permission denied

find: ‘/run/dovecot/login’: Permission denied

find: ‘/run/systemd/ask-password-block’: Permission denied

find: ‘/run/systemd/inaccessible’: Permission denied

find: ‘/usr/share/polkit-1/rules.d’: Permission denied

find: ‘/usr/lib/firewalld/icmptypes’: Permission denied

find: ‘/usr/lib/firewalld/services’: Permission denied

find: ‘/usr/lib/firewalld/zones’: Permission denied

find: ‘/usr/libexec/initscripts/legacy-actions/auditd’: Permission denied

find: ‘/var/cache/httpd/proxy’: Permission denied

find: ‘/var/db/sudo’: Permission denied

find: ‘/var/tmp/systemd-private-sl8Rw5’: Permission denied

find: ‘/var/tmp/systemd-private-4xjKJH’: Permission denied

find: ‘/var/tmp/systemd-private-ckkDHo’: Permission denied

find: ‘/var/spool/postfix/flush’: Permission denied

find: ‘/var/spool/postfix/corrupt’: Permission denied

find: ‘/var/spool/postfix/incoming’: Permission denied

find: ‘/var/spool/postfix/hold’: Permission denied

find: ‘/var/spool/postfix/public’: Permission denied

find: ‘/var/spool/postfix/active’: Permission denied

find: ‘/var/spool/postfix/deferred’: Permission denied

find: ‘/var/spool/postfix/bounce’: Permission denied

find: ‘/var/spool/postfix/saved’: Permission denied

find: ‘/var/spool/postfix/trace’: Permission denied

find: ‘/var/spool/postfix/defer’: Permission denied

find: ‘/var/spool/postfix/private’: Permission denied

find: ‘/var/spool/postfix/maildrop’: Permission denied

find: ‘/var/lib/authconfig/last’: Permission denied

find: ‘/var/lib/polkit-1/localauthority’: Permission denied

find: ‘/var/lib/php/session’: Permission denied

find: ‘/var/lib/mysql/crifan_wiki’: Permission denied

find: ‘/var/lib/mysql/mail’: Permission denied

find: ‘/var/lib/dovecot’: Permission denied

find: ‘/var/lib/postfix’: Permission denied

find: ‘/var/lib/tpm’: Permission denied

find: ‘/var/lib/yum/history/2014-07-07/32’: Permission denied

find: ‘/var/lib/yum/history/2014-07-07/36’: Permission denied

find: ‘/var/lib/yum/history/2014-07-07/35’: Permission denied

find: ‘/var/lib/yum/history/2014-07-07/31’: Permission denied

find: ‘/var/lib/yum/history/2014-07-07/37’: Permission denied

find: ‘/var/lib/yum/history/2014-07-07/34’: Permission denied

find: ‘/var/lib/yum/history/2014-07-07/33’: Permission denied

^C

crifan@crifan:~$ sudo find / -name '*dovecot.pem*'

[sudo] password for crifan:

/home/crifan/mail_server/dovecot/certs/dovecot.pem

/home/crifan/mail_server/dovecot/private/dovecot.pem

/etc/pki/dovecot/certs/dovecot.pem

/etc/pki/dovecot/private/dovecot.pem

如图:

其中的^C是发现很多文件没有权限,所以Ctrl+C去终止了。

然后加上sudo,就有权限去搜索了。

【总结】

想要在Linux下面查找文件,尤其是只知道部分文件名,关键字,则可以去用:find 路径 -name ‘*要搜的关键字*’

比如:find / -name '*tomcat*'

即可。

如果要搜的路径或文件涉及到没有权限,即出现Permission denied,则可以加上前缀sudo,比如:sudo find / -name '*dovecot.pem*'

即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值