日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux查找文件内容

發布時間:2025/3/20 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux查找文件内容 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

Linux查找文件內容

使用vim命令查找文件內容

我們可以使用/string命令來向前(Forward)查找字符串string,按下回車后,光標就能跳到正確的地方。在這個命令中,/后的字符是我們想要查找的字符,而回車鍵則表明了命令的結束。

有時想要查找的內容并不僅在一處,我們可以在整個文章中進行查找:/可以繼續剛才的查找操作。我們還可以使用n命令來繼續剛才的查找命令。這兩個命令都能達到同樣的效果。

一般來說,在進行查找時總是在向前查找。我們也可以使用?命令向后(Backward)查找。N也是逆向查找命令,他可以實現立即反向查找。

如果我們想要停止這一查找,可以使用ctrl+C命令。

?

使用grep命令查找文件內容

Linux系統中grep命令是一種強大的文本搜索工具,它能使用正則表達式搜索文本,并把匹配的行打印出來。

常用的命令參數有:

-c:只輸出匹配行的計數。

-i:不區分大小寫

-n:顯示匹配行及行號。

-h:查詢多文件時不顯示文件名。

-v:顯示不包含匹配文本的所有行。

使用示例

查找以log結尾的文件中的"error"文本(忽略error大小寫)匹配的行的計數。

? logs grep -ic 'error' *.log error_uc4s.log:0 error_uc4sadmin.log:3758 error_ucvms.log:301 uc4s.log:0 uc4s_log.2016-10-12.log:207 ...... ...... ......

查找文件中"ERROR"文本并顯示所在行

? logs grep -n 'ERROR' uc4sadmin.log 1:2016-08-12 15:20:28.850 ERROR [RMI TCP Connection(2)-127.0.0.1] com.zuche.confcenter.client.manager.DefaultConfigCenterManager:108 - init confcenter fail,the reason is not found conf_center.properties file,the current project as common project and read common datasource,domain is null 2:2016-08-12 15:20:31.860 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.common.func.FuncConfirm:168 - funcClassName is not find 82:2016-08-12 15:20:37.510 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.util.InitDomainUtil:39 - remote domain = {loginImg=testImg, ucASMSURL=http://asmstest.maimaiche.com/ucasms, ucDomain=maimaiche.com, ucCRMURL=http://crmtest.maimaiche.com/uccrm, ucAdminURL=http://admintest.maimaiche.com/ucadmin, ucVMURL=http://vmstest.maimaiche.com/ucvms, ucbi=http://bitest.maimaiche.com/ucbi, ucwap=http://waptest.zhunxinche.com/ucwap, ucweb=http://webtest.zhunxinche.com/ucweb, ucRMURL=http://statictest.zhunxinche.com, env=test, zucheMapiURL=http://mapitest.zuche.com:9080, ucURMSURL=${ucURMSURL}, ucCMSURL=http://cmstest.maimaiche.com/uccms, ucRMimageURL=http://imagetest.zhunxinche.com, loginUrl=http://admintest.maimaiche.com/ucadmin/login.jsp, ucFINURL=http://fintest.maimaiche.com/ucfin, baseContextPath=http://admintest.maimaiche.com/ucadmin, ucRMjsURL=http://jstest.zhunxinche.com, ucRMcssURL=http://csstest.zhunxinche.com}

這里查出來有三條結果,“ERROR”分別在1,2還有82行。

那如果想看 82 行的上文和下文怎么辦呢 ,sed 可以實現。這里打印82行到90行,p是sed的打印指令。

? logs sed -n '82,90p' uc4sadmin.log 2016-08-12 15:20:37.510 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.util.InitDomainUtil:39 - remote domain = {loginImg=testImg, ucASMSURL=http://asmstest.maimaiche.com/ucasms, ucDomain=maimaiche.com, ucCRMURL=http://crmtest.maimaiche.com/uccrm, ucAdminURL=http://admintest.maimaiche.com/ucadmin, ucVMURL=http://vmstest.maimaiche.com/ucvms, ucbi=http://bitest.maimaiche.com/ucbi, ucwap=http://waptest.zhunxinche.com/ucwap, ucweb=http://webtest.zhunxinche.com/ucweb, ucRMURL=http://statictest.zhunxinche.com, env=test, zucheMapiURL=http://mapitest.zuche.com:9080, ucURMSURL=${ucURMSURL}, ucCMSURL=http://cmstest.maimaiche.com/uccms, ucRMimageURL=http://imagetest.zhunxinche.com, loginUrl=http://admintest.maimaiche.com/ucadmin/login.jsp, ucFINURL=http://fintest.maimaiche.com/ucfin, baseContextPath=http://admintest.maimaiche.com/ucadmin, ucRMjsURL=http://jstest.zhunxinche.com, ucRMcssURL=http://csstest.zhunxinche.com} 2016-08-12 15:20:37.512 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.util.InitDomainUtil:42 - local domain = {mapKey=595c2643c16cefd2fdece3fb111042f7, baseContextPath=http://4sadmintest.maimaiche.com/uc4sadmin, env=development} 2016-08-12 15:23:17.624 ERROR [RMI TCP Connection(2)-127.0.0.1] com.zuche.confcenter.client.manager.DefaultConfigCenterManager:108 - init confcenter fail,the reason is not found conf_center.properties file,the current project as common project and read common datasource,domain is null 2016-08-12 15:23:18.893 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.common.func.FuncConfirm:168 - funcClassName is not find java.lang.NullPointerExceptionat java.util.Properties$LineReader.readLine(Properties.java:434)at java.util.Properties.load0(Properties.java:353)at java.util.Properties.load(Properties.java:341)at com.uc.ucBase.util.PropertiesUtil.doLoad(PropertiesUtil.java:101)

========END========

轉載于:https://my.oschina.net/xinxingegeya/blog/846915

總結

以上是生活随笔為你收集整理的Linux查找文件内容的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。