Linux基础命令(more 管道 grep find)

当文件内容较多时,从头开始显示文件内容(enter往后看一行,空格往下翻页B往回翻页按q键退出)

 管道

把左边返回的数据交给右边处理

 grep命令:文本搜索(相当于ctrl+F)

1.查找带有指定文本的内容

 2.查找指定文本在哪一行

grep -n 搜索文本 指定文件

 3.不区分大小写搜索

   grep -i 搜索文本 指定文件

 4.查找当前目录下有那些文件中包含hello

grep -n  查找内容 . -r

 5.在文件中查找以D开头的内容

grep -n ^D 4.txt 

 6.在文件中查找以O结尾的文本

grep - n o$ 4.txt

 grep 查找文件内容总结:

grep hello test.txt 在某个文件中查找包含hello的内容,只要一行中有hello会把整行显示

grep -niv hello test.txt  n显示查找到的内容的行号,i查找时不区分大小写,v反向查找,查找不包含hello的行

grep  -n hello /home/admin -r查找整个目录下的所有文件

find:查找文件

grep:查找文件内容

find:find . -name 2.txt(find+目录+-name+要找的文件名)

find /home -name  1.txt (在/home目录下,查找文件名为1.txt的文件 )

find /home -name ‘*txt’ (在/home目录下查找以txt结尾的文件 )

猜你喜欢

转载自www.cnblogs.com/bestxia/p/12287433.html