在linux下如果要查找包含某個關(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)前目錄下的所有文件中是否含有某個字符串吹埠,假設(shè)關(guān)鍵字為zcwyou
[root@zcwyou ~]# find .|xargs grep -ri "zcwyou"
查找當(dāng)前目錄下的所有文件中是否含有某個字符串(以關(guān)鍵字zcwyou為例),并且只打印出文件名
[root@zcwyou ~]# find .|xargs grep -ri "zcwyou" -l
linux 查找某目錄下包含關(guān)鍵字內(nèi)容的文件
grep -r “{關(guān)鍵字}” {路徑}