tft每日頭條

 > 生活

 > linux命令grep的用法

linux命令grep的用法

生活 更新时间:2024-08-26 04:25:48
每周一個linux命令(grep)

grep每周一個linux命令

基礎環境

linux命令grep的用法(grep每周一個linux命令)1

基礎環境

grep 命令介紹

grep 查找文件裡符合條件的字符串,常與管道符|、cat、ps一起使用;主要用于查找文件中符合條件的字符串、統計文件中符合條件的字符串行數、grep 不顯示自身進程

grep 常用命令參數

-c:統計符合字符串條件的行數-v:顯示不包括文本的所有信息

grep 常用命令過濾test.txt文件中hello内容

grep hello test.txt

linux命令grep的用法(grep每周一個linux命令)2

UPlquA

說明:

  • hello 關鍵字
  • test.txt 文件名
統計test.txt中hello内容的行數

grep -c hello test.txt

linux命令grep的用法(grep每周一個linux命令)3

AmgNtZ

說明:

  • hello 關鍵字
  • test.txt 文件名
  • -c 統計符合字符串條件的行數
grep、cat、管道符配合使用

cat test.txt |grep hello

linux命令grep的用法(grep每周一個linux命令)4

O7R6y3

說明:過濾test.txt文件中hello内容

  • hello 關鍵字
  • test.txt 文件名
  • cat 打印文件内容
  • |管道符,将一個命令的輸出作為另外一個命令的輸入
grep、ps、管道符配合使用

ps -ef|grep ssh

linux命令grep的用法(grep每周一個linux命令)5

eDzAoO

說明:過濾ssh進程信息

  • ps 打印進程信息
  • ssh 過濾關鍵字
  • |管道符,将一個命令的輸出作為另外一個命令的輸入
去掉grep自身進程

ps -ef|grep ssh|grep -v grep

linux命令grep的用法(grep每周一個linux命令)6

lqtm3W

說明:過濾ssh進程信息,并去除最後一行的grep信息

  • ps 打印進程信息
  • ssh 過濾關鍵字
  • |管道符,将一個命令的輸出作為另外一個命令的輸入
  • -v 顯示排除grep關鍵字的所有信息
,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关生活资讯推荐

热门生活资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved