Common Linux log files name and usage--reference
In the following example,you can view the content of var/log/cron from line number 101 to 110.M – Starting line numberN – Ending line number<div class="block-panel"> Example 2: Display first N lines of a file using head commandThis example displays only first 15 lines of /var/log/maillog file. Change 15 to 10 to display the first 10 lines of a log file.?<div class="block-panel"> Example 3: Ignore last N lines of a file using head commandThis example shows how to ignore the last N lines,and show only the remaining lines from the top of file. The following example will display all the lines of the /var/log/secure except the last 250 lines.<div class="block-panel"> Example 4: Display last N lines of the file using tail commandThis example displays only last 50 lines of /var/log/messages file. Change 50 to 100 to display the last 100 lines of the log file.<div class="block-panel"> Example 5: Ignore first N-1 lines of the file using tail commandThis example shows how to ignore the first N-1 lines and show only the remaining of the lines. The following example ignores the 1st four lines of the /etc/xinetd.conf,which contains only the comments.<div class="block-panel"> 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"> 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"> 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"> [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 (编辑:淮北站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |