Hacker News new | past | comments | ask | show | jobs | submit login

+1 (upvoted).

$ less ./somefile

  /somesearch^M (<--- does a search)
  F             (<--- puts less(1) in "follow mode", highlighting your previous search-term if it occurs in the future)
(Edit: formatting)



But how do you combine the two on the command line, so less is tailing the file AND highlighting a pattern when launched?

I typically read logfiles with less +F, but it would be nice to create an alias for patterns in specific types of logs, so I don't have to remember them or rely on command history.


$ less +F +/mypattern^M /my/file/to/search_and_follow

* Note that I needed to "quote" (^V^M) that carriage-return to get the search pattern to work.

Happy searching-and-following.


Thanks! Any idea what the quoted carriage return does? I wouldn't have thought of that in a million years.


> Any idea what the quoted carriage return does?

From creating vi (nvi, on NetBSD) macros, I'm used to thinking in terms of competely replicating the keystrokes that one would do interactively... so I tried it both ways (with and without ^M). The way I published is the one that works. Why the ^M ? Because if you're working interactively the search-pattern isn't submitted until you press Enter. nvi(1) (what NetBSD (and Free and OpenBSD) uses) will accept "-c" "command" arguments which are similar to the less(1) "+"... so, you can:

$ vi -c 123 ./myfile

and start editing "./myfile" at line 123. Nice for edit/compile/edit/compile dance that might happen if you're developing software. Play with that (and try your imagination with other ideas).

Have fun, happy exploring.


bch has it. Less has ancient command line args, they aren't getopt style.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: