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’.

  • Ŝan • 𐑖ƨɤ@piefed.zip
    link
    fedilink
    English
    arrow-up
    0
    ·
    3 months ago

    ripgrep has mostly replaced grep for me, and I am extremely conservative about replacing core POSIX utilities - muscle memory is critical. I also tend to use fd, mainly because of its forking -x, but its advantages over find are less stark þan rg’s improvements over grep.

    nnn is really handy; I use it for everything but the most trivial renames, copies, and moves - anyþing involving more þan one file. It’s especially handy when moving files between servers because of þe built-in remote mounting.

    • emb@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      rg and fd have been so much easier to use than the classics to me. Great replacements!

      bat is another one that I think can be worth switching to, though not as essential.

    • marighost@piefed.socialOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      3 months ago

      Would you recommend nnn for transfering ~5Tb of media between two local servers? Seems like a weird question but it’s something I’ll have to do soon.

      • Ŝan • 𐑖ƨɤ@piefed.zip
        link
        fedilink
        English
        arrow-up
        0
        ·
        3 months ago

        No. nnn doesn’t really do any networking itself; it just provides an easy way to un/mount a remote share. nnn is just a TUI file manager.

        For transfering 5TB of media, I’d acquire a 5TB USB 3.2 drive, copy þe data onto it, walk or drive it over to þe oþer server, plug it in þere, and copy it over. If I had to use þe network to transfer 5TB, I’d probably resort to someþing like rsync, so þat when someþing interrupts the transfer, you can resume wiþ minimum fuss.

        • marighost@piefed.socialOP
          link
          fedilink
          English
          arrow-up
          0
          ·
          3 months ago

          I could very easily, I’ve just only use rsync a handful of times for one-off files or small directories. Thinking of using it for several Tbs scares me 😅

          • ranzispa@mander.xyz
            link
            fedilink
            arrow-up
            0
            ·
            3 months ago

            When transfering large amounts of data I’d most definitely advise using rsync. Something fails, connection falls and everything is okay as it’ll pick up where it left off.

  • roran@sh.itjust.works
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago
    cd `pwd`
    

    for when you want to stay in a dìr that gets deleted and recreated.

    cat /proc/foo/exe > program
    cat /proc/foo/fd/bar > file
    

    to undelete still-running programs and files still opened in running programs

  • AllHailTheSheep@sh.itjust.works
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    3 months 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
      ·
      3 months 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.

  • Lettuce eat lettuce@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    3 months 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
      ·
      3 months 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
        ·
        3 months 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!

  • demonsword@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    Something that really improved my life was learn to properly use find, grep, xargs and sed. Besides that, there are these two little ‘hacks’ that are really handy at times…

    1- find out which process is using some local port (i.e. the modern netstat replacement):

    $ ss -ltnp 'sport = :<port-number>'

    2- find out which process is consuming your bandwidth:

    $ sudo nethogs

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      0
      ·
      3 months ago

      I always just do ss -ltnp | grep <port-number>, which filters well enough for my purposes and is a bit easier to remember…

    • eli@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      You can do “ss -aepni” and that will dump literally everything ss can get its hands on.

      Also, ss can’t find everything, it does have some limitations. I believe ss can only see what the kernel can see(host connections), but tcpdump can see the actual network flow on the network layer side. So incoming, outgoing, hex(?) data in transit, etc.

      I usually try to use ss first for everything since I don’t think it requires sudo access for the majority of its functionality, and if it can’t find something then I bring out sudo tcpdump.

  • Oinks@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    3 months ago

    I’m not much of a one-liner collector but I like this one:

    vim +copen -q <(grep -r -n <search> .) 
    

    which searches for some string and opens all instances in vim’s quickfix list (and opens the quickfix window too). Navigate the list with :cn and :cn. Complex-ish edits are the obvious use case, but I use this for browsing logs too.

    Neovim improves on this with nvim -q - and [q/]q, and plenty of fuzzy finder plugins can do a better version using ripgrep, but this basic one works on any system that has gnu grep and vim.

    Edit:

    This isn’t exactly a command, but I can’t imagine not knowing about this anymore:

    $ man grep
    /  -n       # double space before the dash!
    

    brings you directly to the documentation of the -n option. Not the useless synopsis or any other paragraphs that mention -n in passing, but the actual doc for this option (OK, very occasionally it fails due to word wrap, but assuming the option is documented then it works 99% of the time).

  • @marighost I dont use Prox, but for various random linux commands… ive got a wealth. :D in the journalctl vein.

    journalctl -xeu \<service name\>

    ex: journalctl -xeu httpd

    Gives you the specific journal output for the given service. In this example. httpd.

    Also, journalctl is more than boot logs, its all of your logs from anything controlled by systemd. Mounts, services, timers, even sockets.

    For example. On my system, i have /var/home as a mount. systemctl and journalctl can give me info on it with:

    systemctl status var-home.mount
    journalctl -xeu var-home.mount

    You can see all of the mounts with.
    systemctl list-units --type=mount

    Or, see all of your services with
    systemctl list-units --type=service

    Or all of your timers with
    systemctl list-timers

    We do a weekly show on getting into linux terminals, commands, tricks, and share our experience… It’s called Into the Terminal. on the Red Hat Enterprise Linux youtube channel. I’ll send you a link if you’re interested.

  • HakunaHafada@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    3 months 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.

  • netvor@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    3 months 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).

  • Auster@thebrainbin.org
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    (Fixed the bolding issue)

    From a file I keep since I started using Linux near 5 years ago:

    Display the RAM usage:
    watch -n 5 free -m
    Useful if you open way too much stuff and/or you’re running on budget processing power, and don’t want your computer freezing from 3 hours.
    Also useful if you use KDE’s Konsole integrated into the Dolphin file manager and you must for some reason not close the Dolphin window. You’d just need to open Dolphin’s integrated Konsole (F4), run the command and without closing it, press F4 again to hide the Konsole.

    Terminal-based file browser that sorts by total size:
    ncdu
    why is the cache folder 50 GB big?

    Mass-check MD5 hashes for all files in the path, including subfolders:
    find -type f \( -not -name "md5sum.txt" \) -exec md5sum '{}' \; > md5sum.txt
    Change md5sum (and optionally the output file’s name) for your favorite/needed hash calculator command.

    For mounting ISOs and similar formats:
    sudo mount -o loop path/to/iso/file/YOUR_ISO_FILE.ISO /mnt/iso

    And unmounting the file:
    sudo umount /mnt/iso
    Beware there’s no N in the umount command

    For creating an ISO from a mounted disc:
    dd if=/dev/cdrom of=image_name.iso

    And for a folder and its files and subfolders:
    mkisofs -o /path/to/output/disc.iso /path/from/input/folder

    Compress and split files:
    7z -v100m a output_base_file.7z input_file_or_folder

    Changes the capslock key into shiftlock on Linux Mint (not tested in other distros):
    setxkbmap -option caps:shiftlock
    Was useful when the shift key from a previous computer broke and I didn’t have a spare keyboard.

    If you want to run Japanese programs on Wine, you can use:
    LC_ALL=ja_JP wine /path/to/the/executable.exe
    There are other options but this is one that worked the better for me so I kinda forgor to take note of them.

    List all files in a given path and its subfolders:
    find path_to_check -type f
    Tip: add > output.txt or >> output.txt if you’d rather have the list in a TXT file.

    Running a program in Wine in a virtual desktop:
    wine explorer /desktop=session_name,screen_size /path/to/the/executable.exe

    E.g.:
    wine explorer /desktop=MyDesktop,1920x1080 Game.exe

    Useful if you don’t want to use the whole screen, there are integration issues between Linux, Wine and the program, or the program itself has issues when alt-tabbing or similar (looking at you, 2000’s Windows games)

    Download package installers from with all their dependencies:
    apt download package_name
    Asks for sudo password even when not running as sudo. Downloaded files come with normal user permissions thankfully. Also comes with an installation script but if you want to run it offline, iirc you need to change apt install in the script for dpkg -i.

    If you use a program you’d rather not connect to the internet but without killing the whole system’s connection, try:
    firejail --net=none the_command_you_want_to_run

    Or if you want to run an appimage:
    firejail --net=none --appimage the_command_you_want_to_run

    If you want to make aliases (similar to commands from Windows’ PATH) and your system uses bash, edit the file $HOME/.bashrc (e.g. with Nano) and make the system use the updated file by either logging out and in, or running . ~/.bashrc

    Python/Pip have some nifty tools, like Cutlet (outputs Japanese text as Romaji), gogrepoc (for downloading stuff from your account using GOG’s API), itch-dl (same as gogrepoc but for Itch.io), etc. If you lack the coding skills and doesn’t mind using LLMs, you could even ask one to make some simpler Python scripts (key word though: simpler).

    If you want to run a video whose codec isn’t supported by your system (e.g. Raspberrian which only supports H.264, up to 1080p):
    ffmpeg -i input_video.mkv -map 0 -c:v libx264 -preset medium -crf 23 -vf scale=1920:1080 -c:a copy -c:s copy output_video.mkv