I’ve been setting up a new Proxmox server and messing around with VMs, and wanted to know what kind of useful commands I’m missing out on. Bonus points for a little explainer.

Journalctl | grep -C 10 'foo' was useful for me when I needed to troubleshoot some fstab mount fuckery on boot. It pipes Journalctl (boot logs) into grep to find ‘foo’, and prints 10 lines before and after each instance of ‘foo’.

  • netvor@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    6 hours ago

    I think vipe is underrated; it takes whatever is on its stdin, shoves it in a temp file, opens your favorite text editor (EDITOR environment variable) and waits in the background until you finish editing the file and close it. Then it outputs the edited text to its stdout.

    It’s useful in all kinds of pipes, but personally I use it tons of times a day in combination with xclip, in something like this:

    xclip -o -selection primary | vipe | xclip -i -selection clipboard
    

    (I actually have a bit fancier version of this pipe wrapped in a Bash function named xvxx.)

    On my setup, this takes my current text selection, opens it in vim, and lets me edit it before it sends it to the “traditional” Ctrl+C clipboard. It’s super handy for editing comments like this one.

    If you often find yourself writing complex Bash pipelines involving generating some output and then running set of commands per line (perhaps in a while loop), sometimes replacing the “selection part” with vipe can be easier than coming up with right filter.

    find_or_ls_or_grep_something | vipe | for while read -r foo; do some_action "$foo"; done
    

    And if you are really confident with Bash, you can go even a step further and do:

    you might find something like this useful sometimes:

    find_or_ls_or_grep_something | vipe | bash
    

    and just create a large dumb one-off script, manually curating what’s exactly done. Remember that editing large lists in vim can be made much easier by utilizing vim’s ability to invoke unix filter commands (those greps and uniqs and seds et al.) on the buffer, and /or block editing mode using Ctrl+V (that last one method goes really well with column -t).