1. grep命令
它能在文件中搜索符合要求的文本,并把匹配的行打印出来
语法: grep [-acinv] [--color=auto] '搜寻字符串' filename
选项与参数:
-r :递归搜索
-a :将 binary 文件以 text 文件的方式搜寻数据
-c :计算找到 '搜寻字符串' 的次数
-i :忽略大小写的不同,所以大小写视为相同
-n :顺便输出行号
-v :反向选择,亦即显示出没有 '搜寻字符串' 内容的那一行!
--color=auto :可以将找到的关键词部分加上颜色的显示喔!
查找包含teacher文本的所有行并打印在屏幕上,
命令:grep ‘teacher’ /root/Linux.txt。
不区分大小写的查找teacher文本的所有行并打印在屏幕上,
命令:grep -i 'teacher' /root/Linux.txt。
查找包含teacher文本的所有行并将匹配行的总数打印在屏幕上,
命令:grep -c 'teacher' /root/Linux.txt。
查找包含teacher文本的所有行并打印在屏幕上同时显示行号,
命令:grep -n 'teacher' /root/Linux.txt。
查找root目录下包含Linux的文件,
命令:ls /root | grep 'Linux'。
排除当前目录下面的configs和reference目录,查找CONFIG_SCREEN_ST7796S_RGB16BIT字符串:
grep --exclude-dir={configs,reference} -nr 'CONFIG_SCREEN_ST7796S_RGB16BIT'
grep --include=\*.{c,py} --exclude-dir=out --exclude=*.img -irn "over newer" .
排除当前目录下面的configs目录,查找CONFIG_SCREEN_ST7796S_RGB16BIT字符串:
grep --exclude-dir="configs" -nr 'CONFIG_SCREEN_ST7796S_RGB16BIT'
2. find命令
查找目录:find /(查找范围) -name '查找关键字' -type d
查找文件:find /(查找范围) -name 查找关键字 -print
find -name '*.c'|xargs grep 'set_log_level'
find -name '*.[ch]'|xargs grep 'hiLsAdc_release' --color
watch "dmesg | tail -20" 实时监控内核打印
dmesg | head -20 打印前20条
dmesg | tail -20 打印后20条
dmesg | more 打印所有
dmesg | less
将当前目录下面的所有文件,拷贝到目的文件夹,注意当前目录下有一个点
cp currentDir/. destDir/