|
Using The Tail Command
How to used the tail command in unix?
I want to use tail -f with sleep and number of lines, to display
at a time.
I am using:
tail -f -s 20 -n 5 filename.
This is displaying correct result for 1st time, but as tail -f is
appending, I am not able to view 5 lines.
Answer:
You need to put it in an infinite loop and not use the -f option. Try
this, using the syslog file as an example:
while true
do
tail -n 5 /usr/adm/syslog
sleep 20
done
About tail
Delivers the last part of the file.
Syntax
tail [+ number] [-l] [-b] [-c] [-r] [-f] [-c number | -n number] [file]
+number
-number
This option is only recognized if it is specified first. COUNT is a
decimal number optionally followed by a size letter (`b', `k', `m') as
in `-c', or `l' to mean count by lines, or other option letters (`cfqv').
-l
Units of lines.
-b
Units of blocks.
-c
Units of bytes.
-r Reverse.
Copies lines from the specified starting point in the file in reverse
order. The default for r is to print the entire file in reverse order.
-f Follow.
If the input-file is not a pipe, the program will not terminate after
the line of the input-file has been copied, but will enter an endless loop,
wherein it sleeps for a second and then attempts to read and copy further
records from the input-file. Thus it may be used to monitor the growth
of a file that is being written by some other process.
-c number
The number option-argument must be a decimal integer whose sign affects
the location in the file, measured in bytes, to begin the copying:
+ Copying starts relative to the beginning of the file.
- Copying starts relative to the end of the file.
none Copying starts relative to the end of the file.
The origin for counting is 1; that is, -c+1 represents the first byte
of the file, -c-1 the last.
-n number
Equivalent to -c number, except the starting location in the file is
measured in lines instead of bytes. The origin for counting is 1; that
is, -n+1 represents the first line of the file, -n-1 the last.
file
Name of the file you wish to display
Examples
tail myfile.txt
The above example would list the last 10 (default) lines of the file
myfile.txt.
tail myfile.txt -n 100
The above example would list the last 100 lines in the file myfile.txt.
Have a Unix Problem
Do you have
a UNIX Question?
Unix Books :-
UNIX
Programming, Certification, System Administration, Performance Tuning Reference
Books
Return to : - Unix
System Administration Hints and Tips
(c) www.gotothings.com All material on this site is
Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies.
The site www.gotothings.com is in no way affiliated
with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.
|