Linux查找文件、目录、单词、短语

  • locate:

    • locate filename:搜索文件和目录的名称
    • locate -i filename:不区分大小写的搜索文件名和目录
  • grep :

    • grep want_to_find filename:搜索文件总包含想找的单词

    • want_to_find 单词中间有特殊符号的时候,可以加’’,告诉shell正在搜索一个字符串,使用""则表示要使用shell变量

    • grep -R want_to_find *:搜索多个目录的结果

    • grep -R want_to_find * > want_to_find .txt:把搜索的过多的结果放到want_to_find.txt中

    • grep -R want_to_find * --color=auto:把搜索出来的单词变成彩色

    • grep -i want_to_find *:找出不区分大小写的单词

    • grep -w want_to_find *:在文件中搜索完整的单词

    • grep -n want_to_find *:显示搜索单词在文件的行数

    • tail info.log | grep -B 3 "want_to_find " --color=auto 找含有want_to_find 字符的哪一行的前3行(before)

    • tail info.log | grep -A 3 "want_to_find " --color=auto 找含有want_to_find 字符的哪一行的后3行(after)

    • tail info.log | grep -C 3 "want_to_find " --color=auto 找含有want_to_find 字符的前后的完整的上下文信息(context)

    • ls -l | grep -n want_to_find --color=auto 可以把找到的含有want_to_find 字符的那一行的行号打印出来

    • ls -l | grep -v do_not_want_to_find 可以把不含有do_not_want_to_find 的结果打印出来

    • grep -il -l want_to_find filename_path/* 可以把含有do_not_want_to_find 的文件名称打印出来

    • grep -c 广告 info.log 把info.log中出现的广告的次数打印出来

    • ls -l | grep 196[6-7] | grep -v live 在某个搜索结果中搜索单词

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值