Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A simple trick I only figured recently is following logs with fuzzy search:

  tail -f /var/log/foo.log | fzf +s
Or something similar for output from a dev server:

  make serve | fzf --ansi +s


Alternatively, you can use less(1) in tail mode to search growing logs.

  less +F -p pattern /path/to/log
(Ctrl-C to break out of tail mode. /pattern to interactively set search pattern.)


Also while inside less: & shows you only lines which match a pattern. You can hit & multiple times and less will show you only those lines which match every input pattern. A ^N right after & negates the pattern. & respects the -I switch (case insensitive pattern matching).

I use this all the time, especially when I'm on a machine that I don't want to bother installing something like fzf on.


Good tips. Small correction: `&` only filters by the most recent pattern.


Seems to depend on your particular less, see the last sentence of this paragraph from `man less` on my machine:

       &pattern
              Display only lines which match the pattern; lines which do not
              match the pattern are not displayed.  If pattern is empty (if
              you type & immediately followed by ENTER), any filtering is
              turned off, and all lines are displayed.  While filtering is in
              effect, an ampersand is displayed at the beginning of the
              prompt, as a reminder that some lines in the file may be
              hidden.  Multiple & commands may be entered, in which case only
              lines which match all of the patterns will be displayed.
Indeed, I thought it would behave like you describe.. when I was refreshing my memory of how the negative pattern filtering worked, I first did &/pattern and then &/^Npattern, and was surprised to see that it displayed zero matching lines.

this is my version of less:

  % less --version
  less 581.2 (POSIX regular expressions)
  Copyright (C) 1984-2021  Mark Nudelman


Oh wow, that's a pretty new feature! It was added in v569, 2020[1].

[1]: https://github.com/gwsw/less/commit/6a070fc53799fb86e0fe3880...


Speaking of logs, angle-grinder is amazing: https://github.com/rcoh/angle-grinder


That looks awesome. Something I'd love help with, I use pdsh to tail logs from multiple servers at once, but the ways I can manipulate the logs feel really limited because of how pdsh works. Does anyone know of a better solution for that? Like, from a head node, aggregate/tail the contents of the same log file on multiple servers. Bonus points if it uses 'genders' too to get the list of servers.


The Logfile Navigator (https://lnav.org), a TUI for viewing log files, has support for opening logs on remote hosts via SSH in its latest version. See the following post for more information: https://lnav.org/2021/05/03/tailing-remote-files.html

As for integrating with a “genders” host DB, there’s no direct support for it. But, lnav is scriptable, so I’m pretty sure it’s possible to write a script that does what you want. I can help with that if post in the github discussion: https://github.com/tstack/lnav/discussions


As an alternative allowing the use of any shell command/pipeline on the results interactively, see also: https://github.com/akavel/up


I've been using tmux for finding, but I think this might be brilliant and stupid simple. Thank you for this! Never thought of piping "live" output or streaming to fzf!!


Could you (or anyone who understands) explain what these do?


tail -f will hang around and output new lines that appear in the file.

fzf will receive that input and in this case accumulate the new lines that have come in from tail -f. It will then stay around, present an interactive full screen text ui, and let you interactively filter the set of received lines based on substrings you enter at the fzf prompt. This while continuously incorporating new log lines coming from the pipe, from tail -f. The +s just says not to sort the lines, keeping the matches in the same order they appeared in the logs.


It just takes the last ten lines of a log file, then passes that input to a program that basically lets you search each line. I don't really see the usefulness.

Edit: Ah, I see. According to another comment you see the output of the file as it changes.


`tail -f` follows the logfile, so the command allows you to search over the logfile as logs are being added to it


This is amazing! Is it possible to do the following somehow?

- automatically have this for any command that outputs more than 10 lines?

- automatically exit when the main command (for example a dev server) exits?

- print the output of the main command to stdout after this is done?


> automatically have this for any command that outputs more than 10 lines?

Probably not. The output of a command typically goes directly to the terminal and does not pass through the shell, so the shell has no idea how many lines there are.

You could write a shell where that's not the case, but that would have issues with interactive things - what happens if you run e.g. vim or htop in that context?

You can pipe to `less -F` (`--quit-if-one-screen`), but note that the version of `less` shipped with macOS has a bug and might just swallow the output instead.


More likely is a feature to skip processing on short outputs, like `less -F`

``` -F ........ --quit-if-one-screen Quit if entire file fits on first screen. ```


Maybe with some clever use of zsh hooks? Here's a gist for zbell; it uses `preexec` and `precmd` to run something right before a command is executed (`preexec`) and right before the prompt is shown again (`precmd`)

https://gist.github.com/jpouellet/5278239

Mine blinks a little light if a command finishes after 30 seconds, and sends me an email if something takes over a minute.


fzf is a wonderful little tool. I use this script so much:

git branch | fzf | xargs git checkout


Related git+fzf:

    [alias]
      fza = "!git ls-files -m -o --exclude-standard | fzf -m --print0 | xargs -0 git add"
Then if you run "git fza" you'll get a list of changed files in your repo, which you can use TAB to select/deselect. Hit enter and the selected files will be staged, ready for a commit. Extra cool is that it works from any subdirectory of your repo because it always lists files from the root of the repository. It's really useful for selectively adding lots of files from the command line.

I then alias "ga" to "git fza" for even less typing :)


Excuse my ignorance, but what does this command do?


It pipes a list of available git branches into fzf, which lets you filter them by fuzzy string match. When you hit enter, it will take the best matching one and switch to that branch


            _ ._  _ , _ ._
          (_ ' ( `  )_  .__)
        ( (  (    )   `)  ) _)
       (__ (_   (_ . _) _) ,__)
           `~~`\ ' . /`~~`
                ;   ;
                /   \
  _____________/_ __ \_____________


That's a pretty neat trick. I was using `watch -n1` with grep for this occasionally but this is so much better!


    #.zshrc
    alias -g F=" | fzf --multi"




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: