测试过程中常用的linux命令之【查找指定的文件内容】

    之前遇到过这种情况,在查看日志定位问题时,会将log 传输到本地,然后用本地的文本编辑工具打开文件,然后查找关键字,再进行分析。 这样做无疑会降低效率。

整理了几个常用的命令,可以进行快速的查找。


测试文件:

文件名称为execution.log, 文件内容如下:

[error] Timed out after 50000ms

[error] Element css=#href_20_Id > span.title not found

[error] Element css=#addUserBtn not found

[error] Element css=td[title="13011094548"] not found

[error] Element id=userIdList not found

[error] Element css=div.toast.toast-success not found

[error] There was an unexpected Alert! 

[error] Element name=id[] not found

[error] Element xpath=//table/tbody/tr/td[3] not found

[error] Element css=div.toast-message not found

[error] Unexpected Exception: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIFileOutputStream.init]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"  location: "JS frame :: chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js :: newFileOutputStream :: line 3112"  data: no]. toString -> function toString() {

需求:查找Timed关键字的信息


grep方法

grep -i Timed execution.log  # -i,忽略大小写

测试过程中常用的linux命令之【查找指定的文件内容】


grep -e .*ime execution.log   #-e, 支持正则表达式

测试过程中常用的linux命令之【查找指定的文件内容】


vi方法

/str,正向查找,自顶向下的查找;

?str,反向查找,自底向上的查找。

点击n,查找下次出现的位置;点击N,查找上一次出现的位置

测试过程中常用的linux命令之【查找指定的文件内容】