python中判断在文件中是否存在某字符串
a = 'abc' #--------------------要查询的字符串with open('1.txt','r') as foo: for line in foo.readlines(): if a in line: print line
怎样查找包含指定字符串的文件
find 具体的查找目录 -name "*" | xargs grep "要查询的特定字符串"。例如在/etc下找含有enable的文件sudo find /etc -name "*" | xargs grep "enable"结果:....../etc/yum.repos.d/rpmfusion-nonfree-updates.repo:enabled=1/etc/yum.repos.d/rpmfusion-nonfree-updates.repo:enabled=0/etc/yum.repos.d/rpmfusion-nonfree-updates.repo:enabled=0/etc/yum.repos.d/CentOS-Vault.repo:enabled=0/etc/yum.repos.d/CentOS-Vault.repo:enabled=0/etc/yum.repos.d/CentOS-Vault.repo:enabled=0/etc/yum.repos.d/CentOS-Vault.repo:enabled=0/etc/yum.repos.d/CentOS-Vault.repo:enabled=0......