grep -rl 'python' /root
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了grep -rl 'python' /root相关的知识,希望对你有一定的参考价值。
# grep -rl ‘python‘ /root 搜索root目录下文件内容包含python的文件名路径 import os def init(func): def wrapper(*args,**kwargs): res = func(*args,**kwargs) next(res) return res return wrapper @init def search(target): while True: search_path = yield g=os.walk(search_path) for par_dir,_,files in g: for file in files: file_abs_path = r‘%s\%s‘ % (par_dir,file) target.send(file_abs_path) @init def opener(target): while True: file_abs_path = yield with open(file_abs_path,‘r‘,encoding=‘utf-8‘) as f: target.send((file_abs_path,f)) @init def cat(target): while True: file_abs_path,f = yield for line in f: tag =target.send((file_abs_path,line)) #注意:对于需要传两个yield的,在send时需要将这两个值放在一个元组中传递(()) if tag: break @init def grep(target,pattern): tag = False while True: file_abs_path,line = yield tag tag = False if pattern in line: tag = True target.send(file_abs_path) @init def printer(): while True: file_abs_path = yield print(file_abs_path) #调用 x = r‘D:\Python_OldBoy\课程\day5\day5\a‘ g = search(opener(cat(grep(printer(),‘python‘)))) g= search(opener(cat(grep(printer(),‘python‘)))) g.send(x)
以上是关于grep -rl 'python' /root的主要内容,如果未能解决你的问题,请参考以下文章
利用Python监控MySQL当前跑的TOP SESSION
'grep' 不是内部或外部命令,也不是可运行的程序 或批处理文件
解析 pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}' `