Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade Teachers Spaces Bootcamps Get Certified Upgrade Teachers Spaces Bootcamps
   ❮   
     ❯   

Bashtail Command - Display Last Part of Files


Using thetail Command

Thetail command is used to display the last part of files.

It's particularly useful for viewing the end of log files or any file that is being updated in real-time.


Syntax

The basic syntax of thetail command is:

tail [OPTION]... [FILE]...

Example

tail logfile.txtline 91line 92line 93line 94line 95line 96line 97line 98line 99line 100

Options

Thetail command has several options to customize its behavior:

  • -n [number]: Display the last [number] lines of the file.
  • -f: Follow the file as it grows, useful for monitoring log files.
  • -c [number]: Display the last [number] bytes of the file.
  • --pid=[pid]: Terminate after the process with the given PID dies.
  • --retry: Keep trying to open a file even if it is inaccessible.


Option: -n [number]

The-n option allows you to specify the number of lines to display from the end of the file.

By default,tail shows the last 10 lines.

Example: Display Last 5 Lines

tail -n 5 logfile.txtline 96line 97line 98line 99line 100

Option: -f

The-f option is used to follow a file as it grows, which is particularly useful for monitoring log files in real-time.

Example: Follow Log File

tail -f logfile.txtline 91line 92line 93line 94line 95line 96line 97line 98line 99line 100line 101

Option: -c [number]

The-c option allows you to display the last [number] bytes of a file instead of lines.

Example: Display Last 20 Bytes

tail -c 20 logfile.txtend of logfile.txt

Option: --pid=[pid]

The--pid option terminates tailing after the process with the given PID dies. This is useful for stopping the tail operation when a related process ends.

Example: Terminate After Process Ends

tail -f --pid=1234 logfile.txtline 91line 92line 93...

Option: --retry

The--retry option makestail keep trying to open a file even if it is inaccessible. This is useful for files that may be temporarily unavailable.

Example: Retry Opening File

tail --retry -f logfile.txttail: cannot open 'logfile.txt' for reading: No such file or directoryline 91line 92line 93...

Use Cases

Common scenarios where thetail command is beneficial include:

  • Monitoring server logs to detect issues in real-time.
  • Checking the latest entries in a continuously updated file.
  • Debugging applications by reviewing recent log entries.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.


[8]ページ先頭

©2009-2026 Movatter.jp