Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I love less, which I can use to follow logs with the +F flag (or the ShiftF hotkey), search forwards and backwards, and generally move freely through the document.

But there is one thing missing in less: usually I am at the end of the file, and I want to see new things happening. In tail -f I would just hit enter several times, and new log lines would just appear clearly separated from old lines.

Is it possible to add this to less? How?

share|improve this question
    
I don't think you can do this, though sometimes I will do echo -e '\n\n\n\n\n' >> /dev/pts/0 for example, it isn't as clean but atleast lets me have a point of reference where I left off when i look away. –  David Houde Apr 26 '13 at 10:19

4 Answers 4

up vote 5 down vote accepted

This isn't really tail's behavior -- it's the terminal. Tail is just sending a stream of output to stdout, which goes to your terminal, and you're inserting blank lines in the middle of that output by hitting enter. Tail itself isn't actually accepting input from you at all. You can type whatever else you want and that will show up too.

less, however, is a console app, and it takes input and processes it. It's managing the console using terminal control sequences, which is how you can scroll around. Letting you insert arbitrary characters into the stream would mess up the display, and anyway less uses your input to control the program.

Unfortunately, it doesn't seem to have a way to mark the current position visually. That's not a terrible feature request, though, and less does still get new features from time to time.

share|improve this answer
    
Do you have a link at hand to request this feature to the less mantainers? –  jeckyll2hide Apr 29 '13 at 9:12
    
@gonvaled gnu.org/software/less –  Michael Hampton Oct 25 '13 at 3:02

I found your question while seeking the same answer for myself.

Disappointed by the accepted answer, I came up with a workaround. It's less than ideal, but it allows me to mark my position in the log I'm following with less, which is the whole point.

I created a small executable script (I called it marklog) with the following contents, and put it in my path:

#!/bin/sh
echo >> $1
echo >> $1
echo >> $1
echo `date` ---------------------------------------------------------------------- >> $1
echo >> $1
echo >> $1

Of course, this only works if you have write access to the log file--which could be a deal-breaker in many situations. I've also created this version which I use to write to log files I don't own (but to which I have sudo access):

#!/bin/sh
sudo sh -c "echo >> $1"
sudo sh -c "echo >> $1"
sudo sh -c "echo >> $1"
sudo sh -c "echo `date` ------------------------------------------------------------------------- >> $1"
sudo sh -c "echo >> $1"
sudo sh -c "echo >> $1"

These scripts provide just the sort of visual break I was looking for. There are at least 3 ways you can use them:

  1. At the point where you would normally press enter a few times when using tail -f, instead run marklog from another terminal (providing the path to the log file as an argument).

  2. Use CtrlZ to suspend less so you can run the script in the same terminal window, but when you re-foreground less (using fg, of course), it will no longer be in 'follow' mode, so you'll need to hit ShiftF again...

  3. Lastly--and this might be the most convenient way, because you don't need to type the path to the log file: Run marklog directly from less by typing !marklog %. Less will substitute the current filename for %. However, less won't respond to the ! while it is in 'follow' mode, so you'll have to hit CtrlC first to exit follow mode, run !marklog %, then ShiftF again.

With method 3, you also get the added bonus of of Less's command history: Just hit the ! and then use the up-arrow to select the most recent command (for me, it's always marklog).

Hope this helps someone as much as has already helped me.

share|improve this answer

I don't think you can do this. I've used m and ' to mark places of interest and then goto them again but this doesn't give you the separation that you ask for. Perhaps something like multitail will do what you want.

share|improve this answer

Press Shift+F at the end of file and less will start to work as tail -f.

share|improve this answer
1  
No, it won't. It will follow new lines, but it will not work as tail -f. Specifically it will not accept enter as newlines, which is the only point of my question. Besides, I already mentioned Shift+F in the question (with a small error, I must say) –  jeckyll2hide Apr 26 '13 at 10:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.