Linux command
tail 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Show last 10 lines
tail [file]
Show last N lines
tail -n [20] [file]
Show all lines starting from line N
tail -n +[10] [file]
Follow a file
tail -f [file]
Follow multiple files
tail -f [file1] [file2]
Follow and retry
tail -F [file]
Show last N bytes
tail -c [100] [file]
说明
tail outputs the last part of files. By default, it shows the last 10 lines. It's commonly used to view log files and monitor file changes in real-time. The -f (follow) option is particularly useful for monitoring log files. Tail continues reading as new lines are appended, displaying them immediately. Using -n +N outputs starting from line N rather than the last N lines. This is useful for skipping headers or combining with head for extracting specific ranges. Multiple files can be specified; tail shows headers indicating which file output comes from.
参数
- -n _N_, --lines=_N_
- Output last N lines (or +N for starting from line N)
- -c _N_, --bytes=_N_
- Output last N bytes (or +N for starting from byte N)
- -f, --follow
- Output appended data as file grows
- -F
- Same as --follow=name --retry
- --retry
- Keep trying to open file if inaccessible
- -s _N_, --sleep-interval=_N_
- Sleep N seconds between iterations with -f
- --pid=_PID_
- With -f, terminate after process PID dies
- -q, --quiet
- Never output headers with file names
- -v, --verbose
- Always output headers with file names
FAQ
What is the tail command used for?
tail outputs the last part of files. By default, it shows the last 10 lines. It's commonly used to view log files and monitor file changes in real-time. The -f (follow) option is particularly useful for monitoring log files. Tail continues reading as new lines are appended, displaying them immediately. Using -n +N outputs starting from line N rather than the last N lines. This is useful for skipping headers or combining with head for extracting specific ranges. Multiple files can be specified; tail shows headers indicating which file output comes from.
How do I run a basic tail example?
Run `tail [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n _N_, --lines=_N_ do in tail?
Output last N lines (or +N for starting from line N)