linux查找包含指定文件名的文件位置/找包含指定内容的文件位置/找文件中的指定内容

青旅半醒 2023-07-25 09:58 106阅读 0赞
  1. 筚路蓝缕,以启山林。抚有蛮夷,以属华夏。不鸣则已,一鸣惊人。
  2. ——《左传\`宣公十二年》

非常详细和实用!记得收藏哦!

目录

通过具体/模糊文件名找文件位置

通过目录找含有指定内容的文件

通过文件找指定内容

找某程序路径


通过具体/模糊文件名找文件位置

1,找名为ump-api-error.log的文件在什么位置,通过-name指定文件名

  1. [root@ump03 ~]# find / -name ump-api-error.log
  2. /var/log/httpd/ump-api-error.log

2,找文件名前缀是ump-api-er的文件在什么位置,名字后面的我记不清了,用*匹配

  1. [root@ump03 bin]# find / -name ump-api-er*
  2. /var/log/httpd/ump-api-error.log-20200405
  3. /var/log/httpd/ump-api-error.log-20200412
  4. /var/log/httpd/ump-api-error.log

2,只记得文件名中有mp和-error,我想知道这个文件在什么位置

  1. [root@ump03 bin]# find / -name *mp*-error*
  2. /var/log/httpd/ump-api-error.log-20200405
  3. /var/log/httpd/ump-api-error.log-20200412
  4. /var/log/httpd/ump-api-error.log
  5. /usr/lib/dracut/modules.d/99kdumpbase/kdump-error-handler.service
  6. /usr/lib/dracut/modules.d/99kdumpbase/kdump-error-handler.sh

通过目录找含有指定内容的文件

1,查找当前目录下含有内容443的文件

  1. [root@scrum-staging-4 harbor]# grep -r "443" ./
  2. ./common/templates/nginx/notary.upstream.conf: server notary-server:4443;
  3. ./common/templates/nginx/nginx.https.conf: listen 443 ssl;
  4. ./common/templates/nginx/notary.server.conf: listen 4443 ssl;
  5. ./common/templates/notary/server-config.json: "http_addr": ":4443"
  6. ./common/templates/notary/server-config.postgres.json: "http_addr": ":4443"
  7. ./common/config/adminserver/env:NOTARY_URL=http://notary-server:4443
  8. ./prepare:notary_url = "http://notary-server:4443"
  9. ./docker-compose.yml: - 443:443
  10. ./docker-compose.yml: - 4443:4443

通过文件找指定内容

1,在文件test中找含有内容hyzx的行

  1. [root@ump03 ~]# cat test
  2. demo for
  3. two
  4. hyzx-1
  5. hyzx
  6. hhh,hyzx
  7. [root@ump03 ~]# grep hyzx ./test
  8. hyzx-1
  9. hyzx
  10. hhh,hyzx

2,在文件test、test2中找含有内容hyzx的行(多个文件时后面空格分隔)

  1. [root@ump03 ~]# cat test2
  2. hyzx-2
  3. hhh-hyzx
  4. h
  5. [root@ump03 ~]# grep hyzx ./test test2
  6. ./test:hyzx-1
  7. ./test:hyzx
  8. ./test:hhh,hyzx
  9. test2:hyzx-2
  10. test2:hhh-hyzx

3,找test文件中含有内容hyzx的行数

  1. [root@ump03 ~]# grep -c hyzx ./test
  2. 3

4,查找docker-compose.yml文件中出现字符443的及其前(-B)、后(-A)、前后各5行(-C)的内容

  1. [root@scrum-staging-4 harbor]# grep -C 5 "443" ./docker-compose.yml
  2. networks:
  3. - harbor
  4. dns_search: .
  5. ports:
  6. - 8880:80
  7. - 443:443
  8. - 4443:4443
  9. depends_on:
  10. - postgresql
  11. - registry
  12. - core
  13. - portal
  14. [root@scrum-staging-4 harbor]# grep -A 5 "443" ./docker-compose.yml
  15. - 443:443
  16. - 4443:4443
  17. depends_on:
  18. - postgresql
  19. - registry
  20. - core
  21. - portal

找某程序路径

  1. [root@scrum-staging-4 ~]# whereis docker-compose
  2. docker-compose: /usr/bin/docker-compose

来取匆匆,有缘再会。

发表评论

表情:
评论列表 (有 0 条评论,106人围观)

还没有评论,来说两句吧...

相关阅读