前言
决心把 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的文件