The usage of tail command in Linux is explained in detail
- 2020-05-10 23:21:50
- OfStack
The tail command is also a very common file view class command, so today I'll show you how to use the Linux tail command.
For more details on the Linux command, see the Linux command quick reference manual
The Linux tail command is primarily used to write files to standard output from a specified point. Many people like to use tail and f to monitor log files.
1. Linux tail command format
The Linux tail command format is shown below
tail [OPTION]... [FILE]...
The Linux tail command parameters are shown below
-f loop read
-q does not display processing information
-v displays detailed processing information
-c < The number of > Number of bytes displayed
-n < The number of rows > According to the number of rows
--pid=PID combined with -f to indicate that the process ends after ID,PID dies.
-q, --quiet, --silent never outputs the header of a given file name
-s, -- sleep-interval =S combined with -f to indicate that S sleeps for seconds at intervals between each iteration
2. Sample Linux tail command
1) look at the last few lines of the file
$tail -5 linuxdaxue.com-access_log
180.175.51.163 - - [14/Jun/2016:11:45:09 +0800] "GET http://www.linuxdaxue.com/wp-content/uploads/2016/05/Shell-printf_thumb.jpg&h=64&w=100&q=90&zc=0&ct=1 HTTP/1.1" 200 2611
180.175.51.163 - - [14/Jun/2016:11:45:09 +0800] "GET http://www.linuxdaxue.com/wp-content/uploads/2016/05/Shell_thumb-2.jpg&h=64&w=100&q=90&zc=0&ct=1 HTTP/1.1" 200 2572
180.175.51.163 - - [14/Jun/2016:11:45:09 +0800] "GET http://www.linuxdaxue.com/wp-content/uploads/2016/05/Shell_thumb-3.jpg&h=64&w=100&q=90&zc=0&ct=1 HTTP/1.1" 200 2580
180.175.51.163 - - [14/Jun/2016:11:45:09 +0800] "GET http://www.linuxdaxue.com/wp-content/uploads/2016/05/Shell_thumb-1.jpg&h=64&w=100&q=90&zc=0&ct=1 HTTP/1.1" 200 2646
180.175.51.163 - - [14/Jun/2016:11:45:09 +0800] "GET http://www.linuxdaxue.com/wp-content/uploads/2016/06/Shell_thumb-1.jpg&h=64&w=100&q=90&zc=0&ct=1 HTTP/1.1" 200 2850
$
2) display the file from line 10
tail -n +10 linuxdaxue.com-access_log
3) circular monitoring log files
$tail -f linuxdaxue.com-access_log
180.175.51.163 - - [14/Jun/2016:11:45:09 +0800] "GET http://www.linuxdaxue.com/wp-content/uploads/2016/05/Shell_thumb-1.jpg&h=64&w=100&q=90&zc=0&ct=1 HTTP/1.1" 200 2646
180.175.51.163 - - [14/Jun/2016:11:45:09 +0800] "GET http://www.linuxdaxue.com/wp-content/uploads/2016/06/Shell_thumb-1.jpg&h=64&w=100&q=90&zc=0&ct=1 HTTP/1.1" 200 2850
In practice, one of the most common features is the ability to monitor log files, which is a very useful feature.