日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

for命令不跳过空白行_Java程序员必备:查看日志常用的linux命令

發(fā)布時間:2023/12/10 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 for命令不跳过空白行_Java程序员必备:查看日志常用的linux命令 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
iwenhou
趁周末,復(fù)習(xí)一下鳥哥的linux私房菜,看了文件內(nèi)容查閱部分,做個筆記,哈哈,希望對你有幫助哦。

cat

cat : 由第一行開始顯示文件所有內(nèi)容

參數(shù)說明

cat [-AbEnTv]

參數(shù):

-A : 相當(dāng)于-vET 的整合參數(shù),可列出一些特殊字符,而不是空白而已 -b :列出行號,僅針對非空白行做行號顯示,空白行不標(biāo)行號 -E :將結(jié)尾的斷行字符$顯示出來 -n : 打印行號,連同空白行也會有行號,與-b的參數(shù)不同

范例demo

范例一:

查看cattest.txt的內(nèi)容[root@iZ2zehkwp9rwg4azsvnjbuZ whx]# cat cattest.txt test cat command jaywei #####

范例二:

查看cattest.txt的內(nèi)容,并且顯示行號[root@iZ2zehkwp9rwg4azsvnjbuZ whx]# cat -n cattest.txt 1 test cat command 2 jaywei 3 4 #####

適用場景

  • cat是Concatenate的縮寫,主要功能是將一個文件的內(nèi)容連續(xù)顯示在屏幕上面。
  • 一般文件內(nèi)容行數(shù)較少時,如40行之內(nèi),適合用cat。
  • 如果是一般的DOS文件時,就需要特別留意一些奇怪的符號,例如斷行與[Tab]等,要顯示出來,就得加入-a之類的參數(shù)了。

tac

tac : 從最后一行開始顯示,可以看出tac是cat的倒寫形式

范例demo

[root@iZ2zehkwp9rwg4azsvnjbuZ whx]# tac cattest.txt ##### jaywei test cat command

適用場景

  • tac 的功能跟cat相反,cat是由“第一行到最后一行連續(xù)顯示在屏幕上”,而tac則是“由最后一行到第一行反向在屏幕上顯示出來”。

head

head :顯示文件開頭的內(nèi)容,以行為單位,默認(rèn)文件開頭的前10行

參數(shù)說明

head [OPTION]... FILE... -n<行數(shù)> 顯示的行數(shù) -q 隱藏文件名 -v 顯示文件名 -c<字節(jié)> 顯示字節(jié)數(shù)

范例demo

顯示 sentinel.conf 文件前12行.[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# head -n 12 sentinel.conf # Example sentinel.conf # *** IMPORTANT *** # # By default Sentinel will not be reachable from interfaces different than # localhost, either use the 'bind' directive to bind to a list of network # interfaces, or disable protected mode with "protected-mode no" by # adding it to this configuration file. # # Before doing that MAKE SURE the instance is protected from the outside # world via firewalling or other means. #

tail

查看文件的內(nèi)容,也是以行為單位,默認(rèn)10行,從尾往前看。監(jiān)聽Java動態(tài)日志時,一般跟 -f參數(shù)配合使用。

參數(shù)說明

tail [參數(shù)] [文件] -f 循環(huán)讀取 -q 不顯示處理信息 -v 顯示詳細(xì)的處理信息 -c<數(shù)目> 顯示的字節(jié)數(shù) -n<行數(shù)> 顯示文件的尾部 n 行內(nèi)容

范例一

顯示sentinel.conf文件的最后12行[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# tail -n 12 sentinel.conf # <role> is either "leader" or "observer" # # The arguments from-ip, from-port, to-ip, to-port are used to communicate # the old address of the master and the new address of the elected slave # (now a master). # # This script should be resistant to multiple invocations. # # Example: # # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh

范例二

持續(xù)檢測sentinel.conf的內(nèi)容[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# tail -f sentinel.conf # The arguments from-ip, from-port, to-ip, to-port are used to communicate # the old address of the master and the new address of the elected slave # (now a master). # # This script should be resistant to multiple invocations. # # Example: # # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh <==要等到輸入[ctrl]-c 之后才離開tail 這個命令的檢測

范例三

持續(xù)檢測sentinel.conf的內(nèi)容,并匹配redis關(guān)鍵字。匹配關(guān)鍵字,一般用 grep , tail 一般也會跟 grep搭檔使用。[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# tail -f sentinel.conf | grep redis # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh <==要等到輸入[ctrl]-c 之后才離開tail 這個命令的檢測

適用場景

  • tial-f 被用來動態(tài)監(jiān)聽Java日志,開發(fā)聯(lián)調(diào)經(jīng)常使用到,它一般跟 grep 一起搭檔使用。

more

more :一頁一頁地顯示文件內(nèi)容

參數(shù)說明

more [-dlfpcsu] [-num] [+/pattern] [+linenum] [fileNames..]

參數(shù):

-num :一次顯示的行數(shù)

-p :不以卷動的方式顯示每一頁,而是先清除螢?zāi)缓笤亠@示內(nèi)容

-c : 跟 -p 相似,不同的是先顯示內(nèi)容再清除其他舊資料

-s : 當(dāng)遇到有連續(xù)兩行以上的空白行,就代換為一行的空白行

+/pattern : 在每個文檔顯示前搜尋該字串(pattern),然后從該字串之后開始顯示

-u :不顯示下引號 (根據(jù)環(huán)境變數(shù) TERM 指定的 terminal 而有所不同)

+num : 從第 num 行開始顯示

fileNames :欲顯示內(nèi)容的文檔,可為復(fù)數(shù)個數(shù)

常用操作命令

[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# more sentinel.conf # Example sentinel.conf ...(中間省略) ... # Note that whatever is the ODOWN quorum, a Sentinel will require to # be elected by the majority of the known Sentinels in order to # start a failover, so no failover can be performed in minority. # # Slaves are auto-discovered, so you don't need to specify slaves in --More--(29%)仔細(xì)看上面的范例,如果more后面接的文件內(nèi)容行數(shù)大于屏幕輸出的行數(shù)時,就會出現(xiàn)類似上面的圖示。重點在最后一行,最后一行會顯示出目前顯示的百分比,而且還可以在最后一行輸入一些有用的命令。在more這個程序的運行過程中,你可以使用一些常用的操作命令:
  • 空格鍵 :代表往下翻一頁
  • Enter : 代表往下滾動一行
  • /字符串 :代表在這個顯示的內(nèi)容當(dāng)中,向下查詢“字符串” 這個關(guān)鍵字
  • :f :立刻顯示出文件名以及目前顯示的行數(shù)
  • q :代表立刻離開more,不再顯示該文件內(nèi)容
  • b或[Ctrl]-b :代表往回翻頁,不過這操作只對文件有用,對管道無用。

最常用的是:按 q離開,按 空格鍵往下翻頁,按 b往回翻頁,以及 /字符串搜索功能,請看以下demo

范例demo

范例一

[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# more -10 sentinel.conf # Example sentinel.conf ...(此處省略)... # Before doing that MAKE SURE the instance is protected from the outside --More--(4%)

分頁查看sentinel.conf文件,一頁展示10行。按下 空格鍵,可以往下翻頁,

[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# more -10 sentinel.conf # Example sentinel.conf ...(此處省略)... # protected-mode no # port <sentinel-port> # The port that this sentinel instance will run on --More--(7%)

按下 b,可以回退到上一頁

# *** IMPORTANT *** ...(此處省略)... # Before doing that MAKE SURE the instance is protected from the outside # world via firewalling or other means. --More--(5%)

按下 q,可以立刻離開more

[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]#

范例二

如果想在sentinel.conf文件中,搜尋sentinel關(guān)鍵字,可以這樣做[root@iZ2zehkwp9rwg4azsvnjbuZ redis-4.0.7]# more -10 sentinel.conf # Example sentinel.conf ...(此處省略)... # Before doing that MAKE SURE the instance is protected from the outside /sentinel 輸入/之后,光標(biāo)就會自動跑到最下面一行等待輸入

如同上面的說明,輸入了/之后,光標(biāo)就會跑到最下面一行,并且等待你的輸入,你輸入了字符串并按下[Enter]之后,more就會開始向下查詢該字符串,而重復(fù)查詢同一個字符串,可以直接按下n即可。最后不想看了,就按下q離開more。

# Before doing that MAKE SURE the instance is protected from the outside /sentinel ...skipping # protected-mode no # port <sentinel-port> # The port that this sentinel instance will run on port 26379 # sentinel announce-ip <ip> # sentinel announce-port <port> # / ...skipping # Example: # # sentinel announce-ip 1.2.3.4 # dir <working-directory> # Every long running process should have a well-defined working directory. # For Redis Sentinel to chdir to /tmp at startup is the simplest thing # for the process to don't interfere with administrative tasks such as # unmounting filesystems. --More--(23%)

適用場景

  • more適合日志比較大的文件查看,可以一頁一頁查看,不會讓前面的數(shù)據(jù)看不到。

less

less 與 more 類似,但less的用法比起more又更加有彈性。

  • 若使用了less時,就可以使用下、下等按鍵的功能來往前往后翻看文件。
  • 除此之外,在less里頭可以擁有更多的查詢功能。不止可以向下查詢,也可以向上查詢。

常用操作命令

  • 空格鍵:往下翻動一頁
  • [pagedown]:向下翻動一頁
  • [pageup]:向上翻動一頁
  • Enter : 代表往下滾動一行
  • y :向前滾動一行
  • /字符串:向下搜索"字符串"的功能
  • ?字符串:向上搜索"字符串"的功能
  • n:重復(fù)前一個搜索(與 / 或 ? 有關(guān))
  • N:反向重復(fù)前一個搜索(與 / 或 ? 有關(guān))
  • q: 離開less這個程序
  • b 向后翻一頁

范例demo

范例一

在sentinel.conf文件中,搜尋sentinel關(guān)鍵字,如下

less sentinel.conf

輸入反斜杠 /,輸入關(guān)鍵字 sentinel,回車

重復(fù)前一個搜索,可以按n,反向重復(fù)前一個搜索,按N

范例二

Linux 動態(tài)查看日志文件,一般用tail -f ,但是我們也可以用less+ F 實現(xiàn)。less + file-name + 命令 F = tail -f + file-name

我們經(jīng)常用tail -f +grep 關(guān)鍵字,動態(tài)查找報錯的日志,也可以用less實現(xiàn)。先輸入shirft+g,到達(dá)文件結(jié)尾

然后輸入 ?,輸入搜索關(guān)鍵字,如 sentinel,回車,然后按 n鍵往上搜索,效果是不是也不錯?尤其日志文件動態(tài)刷新太快的時候,奸笑臉。

適用場景

less適合日志比較大的文件查看,可以一頁一頁查看,并且比more更靈活,也可以動態(tài)查看日志,我一般用它查看Java日志。

小結(jié)

本文總結(jié)了查看日志的幾個linux命令,cat、tac、head、tail、more、less,其中l(wèi)ess真的很適合日常開發(fā)日志查看,非常推薦less。

原文鏈接:https://blog.csdn.net/weiwenhou/article/details/102774286

總結(jié)

以上是生活随笔為你收集整理的for命令不跳过空白行_Java程序员必备:查看日志常用的linux命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。