4 ms·
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 ser
by divbzero 5y ago
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
- lytedev 5y agoI'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!!
- mihaitodor 5y agoSpeaking of logs, angle-grinder is amazing: https://github.com/rcoh/angle-grinder https://github.com/rcoh/angle-grinder
- francislavoie 5y agoThat 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.
- tstack 5y agoThe Logfile Navigator (https://lnav.org 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 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 https://github.com/tstack/lnav/discussions
- sundarurfriend 5y agoCould you (or anyone who understands) explain what these do?
- Alekhine 5y agoIt 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.
- _bohm 5y ago`tail -f` follows the logfile, so the command allows you to search over the logfile as logs are being added to it
- fulafel 5y agotail -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.
- bofh23 5y agoAlternatively, 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.)
- philsnow 5y agoAlso 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.
- hddqsb 5y agoGood tips. Small correction: `&` only filters by the most recent pattern.
- philsnow 5y agoSeems 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
- 5y ago
- yewenjie 5y agoThis 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?
- stirfish 5y agoMaybe 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 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.
- faho 5y ago> 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.
- efreak 5y agoMore 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. ```
- superasn 5y agoThat's a pretty neat trick. I was using `watch -n1` with grep for this occasionally but this is so much better!
- AmpsterMan 5y agofzf is a wonderful little tool. I use this script so much: git branch | fzf | xargs git checkout
- omair_inam 5y agoExcuse my ignorance, but what does this command do?
- _bohm 5y agoIt 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
- omair_inam 5y ago_ ._ _ , _ ._ (_ ' ( ` )_ .__) ( ( ( ) `) ) _) (__ (_ (_ . _) _) ,__) `~~`\ ' . /`~~` ; ; / \ _____________/_ __ \_____________
- deleted 5y ago[deleted]
- bloopernova 5y agoRelated 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 :)
- akavel 5y agoAs an alternative allowing the use of any shell command/pipeline on the results interactively, see also: https://github.com/akavel/up https://github.com/akavel/up
- julius_deane 5y ago#.zshrc alias -g F=" | fzf --multi"