加入收藏 | 设为首页 | 会员中心 | 我要投稿 网站开发网_马鞍山站长网 (https://www.0555zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

Common Linux log files name and usage--reference

发布时间:2021-01-24 09:04:08 所属栏目:站长百科 来源:网络整理
导读:副标题#e# div id="post-body-7256318887016413630" class="post-single-body post-body" div dir="ltr"If you spend lot of time in Linux environment,it is essential that you know where the log files are located,and what is contained in each and

Example 6: View growing log file in real time using tail commandThis is probably one of the most used command by sysadmins.To view a growing log file and see only the newer contents use tail -f as shown below.The following example shows the content of the /var/log/syslog command in real-time.<div class="block-panel">
Syntax:?tail -f FILENAME$ tail -f /var/log/syslog

Example 7: Display specific lines (based on line number) of a file using head and tail commandThe example below will display line numbers 101 – 110 of /var/log/anaconda.log fileM – Starting line numberN – Ending line number<div class="block-panel">
Syntax:?cat file | tail -n +N | head -n (M-N+1)$ cat /var/log/anaconda.log | tail -n +101 | head -n10

cat : prints the whole file to the stdout.tail -n +101 : ignores lines upto the given line number,and then start printing lines after the given number.head -n 10 : prints the first 10 line,that is 101 to 110 and ignores the remaining lines.Example 8: Display lines matching a pattern,and few lines following the match.The following example displays the line that matches “Initializing CPU” from the /var/log/dmesg and 5 lines immediately after this match.<div class="block-panel">
# grep "Initializing CPU#1" /var/log/dmesgInitializing CPU#1[Note: The above shows only the line matching the pattern]# grep -A 5 "Initializing CPU#1" dmesgInitializing CPU#1Calibrating delay using timer specific routine.. 3989.96 BogoMIPS (lpj=1994982)CPU: After generic identify,caps: bfebfbff 20100000 00000000 00000000CPU: After vendor identify,caps: bfebfbff 20100000 00000000 00000000monitor/mwait feature present.CPU: L1 I cache: 32K,L1 D cache: 32K

[Note: The above shows the line and 5 lines after the pattern matching]Example 9: Displaying specific bytes from a file.The following example explains how to display either the top 40 or the last 30 bytes of a file.<div class="block-panel">Display first 40 bytes from syslog.$ head -c40 /var/log/syslog

<div class="block-panel">Display last 30 bytes from syslog.$ tail -c30 /var/log/syslog

(编辑:网站开发网_马鞍山站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!