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

您所在的位置:网站首页 linux指定范围查找文件命令 linux查找包含指定文件名的文件位置/找包含指定内容的文件位置/找文件中的指定内容

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

2023-11-18 13:34| 来源: 网络整理| 查看: 265

                       筚路蓝缕,以启山林。抚有蛮夷,以属华夏。不鸣则已,一鸣惊人。                                                                                                           ——《左传`宣公十二年》

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

目录

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

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

通过文件找指定内容

找某程序路径

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

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

[root@ump03 ~]# find / -name uiy.log /var/log/httpd/uiy.log

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

[root@ump03 bin]# find / -name uiy-er* /var/log/httpd/uiy-error.log-20200405 /var/log/httpd/uiy-error.log-20200412 /var/log/httpd/uiy-error.log

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

[root@ump03 bin]# find / -name *mp*-error* /var/log/httpd/ump-api-error.log-20200405 /var/log/httpd/ump-api-error.log-20200412 /var/log/httpd/ump-api-error.log 通过目录找含有指定内容的文件

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

[root@scrum-staging-4 harbor]# grep -r "443" ./ ./common/templates/nginx/notary.upstream.conf: server notary-server:4443; ./common/templates/nginx/nginx.https.conf: listen 443 ssl; ./common/templates/nginx/notary.server.conf: listen 4443 ssl; ./common/templates/notary/server-config.json: "http_addr": ":4443" ./common/templates/notary/server-config.postgres.json: "http_addr": ":4443" ./common/config/adminserver/env:NOTARY_URL=http://notary-server:4443 ./prepare:notary_url = "http://notary-server:4443" ./docker-compose.yml: - 443:443 ./docker-compose.yml: - 4443:4443 通过文件找指定内容

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

[root@ump03 ~]# cat test demo for two hyzx-1 hyzx hhh,hyzx [root@ump03 ~]# grep hyzx ./test hyzx-1 hyzx hhh,hyzx

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

[root@ump03 ~]# cat test2 hyzx-2 hhh-hyzx h [root@ump03 ~]# grep hyzx ./test test2 ./test:hyzx-1 ./test:hyzx ./test:hhh,hyzx test2:hyzx-2 test2:hhh-hyzx

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

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

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

[root@scrum-staging-4 harbor]# grep -C 5 "443" ./docker-compose.yml networks: - harbor dns_search: . ports: - 8880:80 - 443:443 - 4443:4443 depends_on: - postgresql - registry - core - portal [root@scrum-staging-4 harbor]# grep -A 5 "443" ./docker-compose.yml - 443:443 - 4443:4443 depends_on: - postgresql - registry - core - portal 找某程序路径 [root@scrum-staging-4 ~]# whereis docker-compose docker-compose: /usr/bin/docker-compose



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3