7 ms·
I was introduced to less +F a while ago and it is quite nice, but there is one simple "feature" of tail -f that I miss quite a lot: being able 'mark' the log wi
by pimlottc 12y ago
I was introduced to less +F a while ago and it is quite nice, but there is one simple "feature" of tail -f that I miss quite a lot: being able 'mark' the log with gaps by hitting enter a few times. This is especially handy when you have to first load a page or warm up the app before performing the operation you're interested in watching, letting you separate the earlier output from the lines generated by what you're testing.
With less, you have to keep track of the current position by timestamp or other unique message, and it's easy to lose your place when the output starts streaming in. With tail, you only need a moment to mark your spot and then it's visually distinct even as more message come in.
- evincarofautumn 12y agoWith less, you can use m<letter> to mark the current position and '<letter> to go to a marked position. h will show you lots of useful help.
- jimktrains2 12y agoGP isn't meaning it like that, they mean being able to add some spaces so that the next log entries stand out for quick visual identification as you're making changes and reloading the application.
- toddkaufmann 12y agoUse '/' (search) to enter a regexp to match a pattern on that line, and it will be highlighted.
- lgas 12y agoThis has nothing to do with what is being discussed in this subthread.
- teraflop 12y agoSure it does. If your log lines are distinct (e.g. they have timestamps or unique IDs) then you can use less's search highlighting to provide a visual marker for a specific line, similar to what you can do by manually inserting a bunch of blank lines on the console. This trick doesn't work if your log file has a bunch of identical lines and you want to keep an eye on their rate, though.
- shawabawa3 12y agoimagine the scenario: "I want to see everything that happens in a single request" Enter method: 1. Press enter a bunch of times 2. Reload browser 3. Press enter a bunch of times and scroll up Your method: 1. Search for last line in output to highlight it? 2. Reload page 3. Try and figure out where stuff starts and ends with loads of visual noise
- MadcapJake 12y agoless method: 1. ma 2. Reload browser 3. 'a less method with two marks: 1. ma 2. Reload browser 3. mb 4. 'a
- ajanuary 12y agoUnfortunately mark doesn't seem to work while you're following.
- teraflop 12y agoI won't argue that for this specific use case, tail isn't friendlier than less. But the original poster posted a useful tip, and is now getting aggressive downvotes and comments like "This has nothing to do with what is being discussed in this subthread." I think that's unwarranted.
- gojomo 12y agoHaving to remember & type a timestamp has much more mental overhead (planning & memory) than "scan/scroll back to last block of vertical whitespace". That's why suggestions of either named-marks or back-searches aren't considered equally-attractive alternatives to marking the scrollback with a batch of <return>s.
- bch 12y agoAn example of some of the vi commands that less(1) has adopted. You can also: * page forward and backward, including using numeric prefixes to indicate a lineno or indicate "repeat 'n' times". * launch vi if less(1) is working on a file (versus (eg) stdout of some process) * search fwd/backward * start examining a new file w/o leaving less(1) * ...
- pjungwir 12y agoJust the other day I was looking for a way to do this in less: yank 10 lines, open a new file, paste the 10 lines, save the file. Is that possible? My Googling last week didn't find a good solution.
- bch 12y agoIf you wanted to grab 10 lines from /var/log/messages, starting at the first line that has "pjungwlr" in it, you could: $ less /var/log/msgs /pjungwlr^M ^G (note line informational line numbers) v (launch vi) [double check your line #s, etc] :d1,. (delete from 1st line, to current line) 10j (go down 10 lines) :d,$ (delete to EOF) :w my_newfile :q
- technofiend 12y agoThis is such a common problem there's a stackoverflow article on it. http://stackoverflow.com/questions/17908555/printing-with-sed-or-awk-a-line-following-a-matching-pattern http://stackoverflow.com/questions/17908555/printing-with-se... (Actually, there's probably more than one despite their really good duplication grooming, but this was the first hit.)
- pjungwir 12y ago`v` was the missing key for me. Looks like it even preserves my position in the file. Thanks!
- kragen 12y agoUsually I `ma|acat > newfile` in less, which saves by default a whole screenfull. There must be a better way to do this in less.
- alinspired 12y agoIf you're using screen/tmux as myself, tail -f remains a good option, as you can enter gaps or search, or do 1000 more things as compared to plain terminal session
- jmathai 12y agoOn OSX/iterm you can do command+k to clear the screen and less lets you navigate up if you need.
- warrenm 12y agoThat doesn't change the actual log file, however - it's only visual whilst in the screen buffer