Learn to use grep & find in Linux

前言

决心把 linux commands 都记录一下,以下使用场景均来自于实习或课内项目

grep

基本操作

  • grep接在管道后面
$ ls -lrt | grep xxxx
  • 从文件中查找字符串
# files可以包含通配符,匹配文件集合
$ grep 'string' files
# -r 递归查找目录与子目录
$ grep -r 'string' /
  • 反向查找 -v
    查找不匹配的行
  • 正则表达式 -e
    -e 普通正则 -E 扩展正则
  • 递归查找文件夹
    -d | -r

场景

  • 正则递归查找文件夹中继承了 xxxCreater类的代码
$ grep -r -e 'public .*ChunkCreater' .
./shit/stream/unittest/common.h:class MockOutputChunkCreater : public OutputChunkCreater
./shit/stream/unittest/common.h:class MockInputChunkCreater : public InputChunkCreater
./shit/stream/unittest/common.h:class SyncChunkCreaterForSync: public SyncChunkCreater

find

基本操作

牢牢记住!!!

$ find . -name "*.c"

以下引用runoob的文章:https://www.runoob.com/linux/linux-comm-find.html
在这里插入图片描述
exec

$ find . -name "*/client" -exec ls -al {} \;

regex
linux下匹配文件路径一版使用通配符,所以要用-regex来指定用正则表达式

wholename
匹配整个文件路径时,使用wholename

$ find . -wholename "*/client"

场景

find /home -mmin +60                  # 在/home下查 60分 前 改动过的文件
find /home -mtime -60                 # 在/home下查 60天 内 改动过的文件
find   /home   -size   +512k          # 查大于512k的文件
find   /home   -size   -512k          # 查小于512k的文件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值