Linux tail command

Linux command: show end of file

  Head/Tail

  Head and tail are as easy to understand as their names, it is used to display a certain number of text blocks at the beginning or end, head is used to display the beginning of the file to the standard output, and tail is of course the end of the file. , see the following example:

(1)

  displays the first 6 lines of a file

  head -6 readme.txt

  (2) displays the last 25 lines of a file

  tail -25 mail.txt

  The first example is to display the first 6 lines of the file, and the second example is to display the last 25 lines of the file.

  The following range, which combines the head and tail commands, displays lines 11 to 20 of the file:

(3)

  head -20 file | tail -10

   The manual page of tail shows more available parameters than head, and there is a very useful parameter " -f ". When using this parameter, tail will not return the end signal, unless we go to interrupt it ourselves. ; instead, it waits until it finds that the data has been added to a new line since it was last read:

(4)

  display ongoing updates to the given

  log file

  tail -f /usr/tmp/logs/daemon_log.txt

  The above example can dynamically display the dynamic update of the log file.

  Assuming that the service program has been adding dynamic data to the log file of /usr/adm/logs/daemon_log.txt  , use tail -f in the command line control window, it will track the file in real time for a certain period of time. All updates. (The -f can only be used if its input is a file).

  If you have multiple file parameters after tail, you can track several log files at once in the same window:

  track the mail log and the server error log

  at the same time.

  tail -f /var/log/mail.log /var/log/apache/error_log

  tac -- concatenate in reverse

   How to spell cat in reverse!! This is the function of tac~ It is used to concatenate the sequential contents of files in reverse, so~ under what circumstances is it used? It's useful for arranging components! The following command, for example, lists the three most recently created user accounts, in order from last created to first:

(5)

  last 3 /etc/passwd records - in reverse

  $ tail -3 /etc/passwd | tac

  curly:x:1003:100:3rd Stooge:/homes/curly:/bin/ksh

  larry:x:1002:100:2nd Stooge:/homes/larry:/bin/ksh

  moe:x:1001:100:1st Stooge:/homes/moe:/bin/ksh

 

A special method for viewing file contents
  I believe you are already familiar with the most basic cat and less, more. If you have special requirements:
1. If you only want to see the first 5 lines of a file, you can use the head command, such as:
head - 5 /etc/passwd
2. If you want to view the last 10 lines of the file, you can use the tail command, such as:
tail -10 /etc/passwd
tail -f /var/log/messages
parameter -f makes tail keep reading The latest content, which has the effect of real-time monitoring

  Head/Tail

  Head and tail are as easy to understand as their names, it is used to display a certain number of text blocks at the beginning or end, head is used to display the beginning of the file to the standard output, and tail is of course the end of the file. , see the following example:

(1)

  displays the first 6 lines of a file

  head -6 readme.txt

  (2) displays the last 25 lines of a file

  tail -25 mail.txt

  The first example is to display the first 6 lines of the file, and the second example is to display the last 25 lines of the file.

  The following range, which combines the head and tail commands, displays lines 11 to 20 of the file:

(3)

  head -20 file | tail -10

   The manual page of tail shows more available parameters than head, and there is a very useful parameter " -f ". When using this parameter, tail will not return the end signal, unless we go to interrupt it ourselves. ; instead, it waits until it finds that the data has been added to a new line since it was last read:

(4)

  display ongoing updates to the given

  log file

  tail -f /usr/tmp/logs/daemon_log.txt

  The above example can dynamically display the dynamic update of the log file.

  Assuming that the service program has been adding dynamic data to the log file of /usr/adm/logs/daemon_log.txt  , use tail -f in the command line control window, it will track the file in real time for a certain period of time. All updates. (The -f can only be used if its input is a file).

  If you have multiple file parameters after tail, you can track several log files at once in the same window:

  track the mail log and the server error log

  at the same time.

  tail -f /var/log/mail.log /var/log/apache/error_log

  tac -- concatenate in reverse

   How to spell cat in reverse!! This is the function of tac~ It is used to concatenate the sequential contents of files in reverse, so~ under what circumstances is it used? It's useful for arranging components! The following command, for example, lists the three most recently created user accounts, in order from last created to first:

(5)

  last 3 /etc/passwd records - in reverse

  $ tail -3 /etc/passwd | tac

  curly:x:1003:100:3rd Stooge:/homes/curly:/bin/ksh

  larry:x:1002:100:2nd Stooge:/homes/larry:/bin/ksh

  moe:x:1001:100:1st Stooge:/homes/moe:/bin/ksh

 

A special method for viewing file contents
  I believe you are already familiar with the most basic cat and less, more. If you have special requirements:
1. If you only want to see the first 5 lines of a file, you can use the head command, such as:
head - 5 /etc/passwd
2. If you want to view the last 10 lines of the file, you can use the tail command, such as:
tail -10 /etc/passwd
tail -f /var/log/messages
parameter -f makes tail keep reading The latest content, which has the effect of real-time monitoring

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325084543&siteId=291194637