feed-image  Delivered by FeedBurner  ISSN 1836-5930





Visitors Online

We have 49 guests online

Poll

Which of following tutorials would you like to see on the Linuxconfig.org?
 
Partner Linux Sites
TuxMachines
DebianAdmin
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
FreeSoftwareLinux
Jam's Ubuntu Blog
All For Linux

tail
Article Index
1. Name
2. Synopsis
3. Frequently used options
4. Examples

1. Name

tail [man page] - output the last part of files

2. Synopsis

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

3. Frequently used options

-c, --bytes=N
output the last N bytes
-f, --follow[={name|descriptor}]
output appended data as the file grows; -f, --follow, and
--follow=descriptor are equivalent
-n, --lines=N
output the last N lines, instead of the last 10

4. Examples

Lets create sample file. This file will contain names of all directories in /var/. We can also number each line for better overview.
for f in $( ls /var/ ); do echo $f; done | nl > file1 
tail - create sample file
By default a tail command displays last 10 lines of given file.
tail 
tail command displays last 10 lines
To display just last 3 lines from this file we use -n option:
tail -n 3 file1 
tail - display last 3 lines
Moreover the same output can be produced by command:
tail -3 file1 

tail - display last 3 lines without -n

To use tail command on byte level we can use -c option. This option will make tail command to display last 4 bytes (4 characters) if a given file:

tail -c 4 file1 
tail command on byte level
If you wonder why we can see only 3 characters, use od command to see where the 4th byte is:
tail -c 4 file1 | od -a 
tail command on byte level and od
Another very useful option for tail command is -f. This option will continuously display a file as it is dynamically edited by another process. This option is very useful for watching log files.
tail -f /var/log/syslog