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
    0
    ·
    5 days 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).

  • HakunaHafada@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    5 days ago

    redshift -O 5000: ‘redshift’ is a utility that adjusts the color temperature of your display, ‘-O’ allows you to set a specific temperature, and ‘5000’ is what I like.

    Edit: I also like xkill. xkill lets you click on a window or program and kills it. I need to do this frequently every time exit Kodi; the program stops, but the window is still there.

  • Ludrol@szmer.info
    link
    fedilink
    arrow-up
    0
    ·
    5 days ago

    pkill journalctl -b nvtop tail are great but I like: LANGUAGE=en_GB LC_ALL=en_GB.UTF-8 LANG=en_GB.UTF-8 <your GUI program> to run a GUI program in English for more universal compatibility for helping newbies and creating/reading non-terminal based documentation

  • Jhp9232nasd801@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    5 days ago

    List open files sudo lsof -i -P

    Network traffic by hardware sudo tcpdump -i en1 -nn -s0

    Current processes top -l 1

  • mr_right@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    0
    ·
    5 days ago

    i do not know if this counts as a command but you might want to check Atuin, what it does is help you find, manage and edit the commands you used in your shell history saves you a lot of time

  • jim3692@discuss.online
    link
    fedilink
    arrow-up
    0
    ·
    5 days ago

    docker run --rm -it --privileged --pid=host debian:12 nsenter -a -t1 "$(which bash)"

    If your user is in the docker group, and you are not running rootless Docker, this command opens a bash shell as root.

    How it works:

    • docker run --rm -it creates a temporary container and attaches it to the running terminal
    • --privileged disables some of the container’s protections
    • --pid=host attaches the container to the host’s PID namespace, allowing it to access all running processes
    • debian:12 uses the Debian 12 image
    • nsenter -a -t1 enters all the namespaces of the process with PID 1, which is the host’s init since we use --pid=host
    • "$(which bash)" finds the path of the host’s bash and runs it inside the namespaces (plain bash may not work on NixOS hosts)
  • Lettuce eat lettuce@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    The watch command is very useful, for those who don’t know, it starts an automated loop with a default of two seconds and executes whatever commands you place after it.

    It allows you to actively monitor systems without having to manually re-run your command.

    So for instance, if you wanted to see all storage block devices and monitor what a new storage device shows up as when you plug it in, you could do:

    watch lsblk
    

    And see in real time the drive mount. Technically not “real time” because the default refresh is 2 seconds, but you can specify shorter or longer intervals.

    Obviously my example is kind of silly, but you can combine this with other commands or even whole bash scripts to do some cool stuff.

    • Breadhax0r@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      5 days ago

      Ooooh cool, I think this explains how they have our raid monitor set up at work! I keep forgetting to poke through the script

      • Lettuce eat lettuce@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        5 days ago

        Yeah, it’s a neat little tool. I used it recently at my work. We had a big list of endpoints that we needed to make sure were powered down each night for a week during a patching window.

        A sysadmin on my team wrote a script that pinged all of the endpoints in the list and returned only the ones that still were getting a response, that way we could see how many were still powered on after a certain time. But he was just manually running the script every few minutes in his terminal.

        I suggested using the watch command to execute the script, and then piping the output into the sort command so the endpoints were nicely alphabetical. Worked like a charm!

  • AllHailTheSheep@sh.itjust.works
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    I’m a big enjoyer of pushd and popd

    so if youre in a working dir and need to go work in a different dir, you can pushd ./, cd to the new dir and do your thing, then popd to go back to the old dir without typing in the path again

    • donkeyass@lemmy.sdf.org
      link
      fedilink
      arrow-up
      0
      ·
      6 days ago

      Nice! I didn’t know that one.

      You can also cd to a directory and then do cd - to go to the last directory you were in.

  • harsh3466@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago
    find /path/to/starting/dir -type f -regextype egrep -regex 'some[[:space:]]*regex[[:space:]]*(goes|here)' -exec mv {} /path/to/new/directory/ \;
    

    I routinely have to find a bunch of files that match a particular pattern and then do something with those files, and as a result, find with -exec is one of my top commands.

    If you’re someone who doesn’t know wtf that above command does, here’s a breakdown piece by piece:

    • find - cli tool to find files based on lots of different parameters
    • /path/to/starting/dir - the directory at which find will start looking for files recursively moving down the file tree
    • -type f - specifies I only want find to find files.
    • -regextype egrep - In this example I’m using regex to pattern match filenames, and this tells find what flavor of regex to use
    • -regex 'regex.here' - The regex to be used to pattern match against the filenames
    • -exec - exec is a way to redirect output in bash and use that output as a parameter in the subsequent command.
    • mv {} /path/to/new/directory/ - mv is just an example, you can use almost any command here. The important bit is {}, which is the placeholder for the parameter coming from find, in this case, a full file path. So this would read when expanded, mv /full/path/of/file/that/matches/the/regex.file /path/to/new/directory/
    • \; - This terminates the command. The semi-colon is the actual termination, but it must be escaped so that the current shell doesn’t see it and try to use it as a command separator.
  • some_guy@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    6 days ago

    Search for github repos of dotfiles and read through people’s shell profiles, aliases, and functions. You’ll learn a lot.

  • Gary Ghost@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    ps -ef | grep <process_name

    Kill -9 proces id

    I googled that -15 is better, I forgot what -9 even did, been using it for years.

    • black0ut@pawb.social
      link
      fedilink
      arrow-up
      0
      ·
      6 days ago

      The number is the signal you send to the program. There’s a lot of signals you can send (not just 15 and 9).

      The difference between them is that 15 (called SIGTERM) tells the program to terminate by itself (so it can store its cached data, create a save without losing data or corrupting, drop all its open connections gracefully, etc). 9 (called SYGKILL) will forcefully kill a program, without waiting for it to properly close.

      You normally should send signal 15 to a program, to tell it to stop. If the program is frozen and it’s not responding or stopping, you then send signal 9 and forcefully kill it. No signal is “better” than the other, they just have different usecases.