![](/img/trans.png)
[英]grep : sort strings CASE INSENSITIVE which end or begin with specific letter
[英]Searching all files that begin with 's' and end with '.conf' with grep
使用grep命令在所有文件中搜索字符串ip
,該文件以s
(區分大小寫)開頭,在/etc
目錄中以.conf
結尾。 將輸出重定向到/usr/local/thirdrock/grep1.txt
。
您應該獲得8行輸出。
這是我進行實際考試復習時遇到的問題,到目前為止,我已經
grep "ip" s*.conf /etc
但返回"no such file or directory"
。
我的問題是如何在/etc
目錄中的所有以s
開頭並以.conf
結尾的文件中搜索。
嘗試這個:
grep ip /etc/s*.conf
grep "ip" s*.conf /etc
正在當前目錄中與s * .conf和目錄“ file” / etc匹配的所有文件中搜索字符串“ ip”。
grep "ip" /etc/s*.conf
應該執行您想要的操作。
您可以使用>
重定向標准輸出,但這不是問題的一部分,因此我不會破壞它。
這應該為您解決問題
cd /etc && grep -r --include='s*.conf' ip
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.