Linux查找文件內(nèi)容關(guān)鍵字

在linux下如果要查找包含某個(gè)關(guān)鍵字的文件,如要在/root/目錄下搜索帶有關(guān)鍵字“zcwyou”的文件,在終端下運(yùn)行命令:

[root@zcwyou ~]# find /root/ –type f |xargs grep "give_flower_log_json"

./20200424/04/give_flower_log.log: Dlogback.configurationFile=/data1/datax/conf/logback.xml -Dlog.file.name=give_flower_log_json

在當(dāng)前目錄下查找?guī)в蠴utOfMemory關(guān)鍵字的文件

[work@dt-001 dataxLog]$ grep -r 'OutOfMemory' .
./20200422/21/discussion_oper_log.log: - java.lang.OutOfMemoryError: unable to create new native thread
./20200422/21/discussion_oper_log.log:Caused by: java.lang.OutOfMemoryError: unable to create new native thread

查找當(dāng)前目錄及其子目錄下所有l(wèi)og文件中包含某關(guān)鍵字的文件,假設(shè)關(guān)鍵字為:OutOfMemory

(base) [work@dt-001 dataxLog]$ find -name "*.log" | xargs grep -l 'OutOfMemory'
./20200422/21/discussion_oper_log.log
./20200422/21/exclusive_privilege_signature_log.log
./20200422/21/pyramid_delegate_cancel_log.log
./20200422/21/alliancebuild_log.log

查找目錄/var/www/html/test/里,包含帶關(guān)鍵字linuxrumen.com的文件并刪除這些文件

[root@zcwyou ~]# find /var/www/html/test/ -type f -exec grep “l(fā)inuxrumen.com” {} \; -print -exec rm {} \;

查找當(dāng)前目錄下的所有文件中是否含有某個(gè)字符串,假設(shè)關(guān)鍵字為zcwyou

[root@zcwyou ~]# find .|xargs grep -ri "zcwyou"

查找當(dāng)前目錄下的所有文件中是否含有某個(gè)字符串(以關(guān)鍵字zcwyou為例),并且只打印出文件名

[root@zcwyou ~]# find .|xargs grep -ri "zcwyou" -l

linux 查找某目錄下包含關(guān)鍵字內(nèi)容的文件

grep -r “{關(guān)鍵字}” {路徑}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容