linux常用查詢命令

Linux Sed NoSQL Redis 十號火星人 十號火星人 2017-09-28

查詢命令是否存在(whereis)

whereis composer

composer: /usr/local/bin/composer

說明:whereis - locate the binary, source, and manual page files for a command

查詢命令是否存在(which)

which grep

/bin/grep

在PATH變量指定的路徑中,搜索某個系統命令的位置,並且返回第一個搜索結果

說明:which - shows the full path of (shell) commands

查詢關鍵字 (grep)

grep --color -rni 'redis' ./* #從當前目錄遞歸,忽略大小寫,並顯示行號,查詢redis關鍵字,並高亮顯示

常用參數有:

-c:只輸出匹配行的計數。

-I:不區分大 小寫(只適用於單字符)。

-h:查詢多文件時不顯示文件名。

-l:查詢多文件時只輸出包含匹配字符的文件名。

-n:顯示匹配行及 行號。

-s:不顯示不存在或無匹配文本的錯誤信息。

-v:顯示不包含匹配文本的所有行。

建議:在小文件中查詢使用,待查詢字符串可正則代替

說明:grep, egrep, fgrep - print lines matching a pattern

查詢關鍵字 (sed)

sed -n '/redis/p' base.20170913.log | grep --color 'redis' #查詢redis關鍵字,並高亮顯示

建議:較大文件查詢關鍵字時使用,因為是流式處理

說明:sed - stream editor for filtering and transforming text

查詢文件是否存在(find)

sudo find / -name 'supervisord.conf' #從當前目錄查詢文件名稱

/etc/supervisord.conf

說明:find - search for files in a directory hierarchy

建議:最好安裝man,隨時查看命令詳情。

相關推薦

推薦中...