Is there a way to modify so that the tail -f
lists the line number of the current file as well.
Something similar to grep -n <Strings> *
.
Tail is a command which prints the last few number of lines (10 lines by default) of a certain file, then terminates. Example 1: By default “tail” prints the last 10 lines of a file, then exits.
The tail command is used to print last 10 lines of a file by default. However, like the head command, we can change the number number of lines to be displayed by using the -n option, or just -<number> , to display a different number of lines as specified.
To look at the last few lines of a file, use the tail command. tail works the same way as head: type tail and the filename to see the last 10 lines of that file, or type tail -number filename to see the last number lines of the file.
less
Instead of using tail
to follow data and less
or nl
for numbering, I suggest using a single tool for both:
less -N +F <filename>
This will make less
print line numbers and follow the file. From man less
:
F
Scroll forward, and keep trying to read when the end of file is reached. Normally this command would be used when already at the end of the file. It is a way to monitor the tail of a file which is growing while it is being viewed. (The behavior is similar to the
tail -f
command.)
You could do a Ctrl+C to stop following when inside less
; to start following again, you could press F again. With this method, you get the additional goodies that less
offers like regex-based search, tags, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With