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

          • wheezy@lemmy.ml
            link
            fedilink
            arrow-up
            0
            ·
            2 months ago

            Scrolling is tmux is what I hate about it. I would prefer to use tmux since I’m use to it. But if someone can explain to me why I can’t just use my scroll wheel on my mouse.

            • kittenroar@beehaw.org
              link
              fedilink
              English
              arrow-up
              0
              ·
              2 months ago

              As I understand it, the issue is that tmux invents its own terminal emulator functionality that conflicts with the existing terminal it runs within, while screen simply defers scroll functionality to the terminal emulator.

        • MCHEVA@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          Tmux is good because I can have a little window with a bonsai in it and another little window for the matrix. Sometimes I even leave a window for typing in commands.

    • Eager Eagle@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 months ago

      are you using a maintained alternative? Distros started to remove it from their repos years ago because it was not maintained anymore afaik

        • Eager Eagle@lemmy.world
          link
          fedilink
          English
          arrow-up
          0
          ·
          2 months ago

          maybe they resumed development then, it was removed from Ubuntu and RHEL repos about 5 years ago when I had to look for an alternative

  • crispycone@lemmy.zip
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    Another one of my favorite is ctrl+r to quickly search for a previous command.

    Then type in a word from the command you are looking for and then hit tab to find the right command if there is more than one with that word.

  • thagoat@piefed.thagoat.lol
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 months ago

    Bash/ZSH aliases are invaluable for commands that you run often. I use micro as my terminal editor so I have alias m for micro and sm for sudo micro. Just 2 of maybe a dozen aliases I use. Docker has quite a large list of aliases with ZSH. Super super useful.

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

    I get a lot of milage out of the line editing commands. I think they are Emacs based and optional… but like Ctrl k, Ctrl u, Ctrl a.

    • __hetz@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      I usually set vi mode to have vi(m)-like line editing but I’ve always liked Ctrl+u over Esc d d. Thankfully it still works even with vi mode enabled. Seems to also be implemented as a shortcut for a lot of login managers and in DEs for settings menus, dialog boxes and such.

  • Ftumch@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    Ctrl-z to suspend the running program.

    bg to make it continue running in the background.

    jobs to get an overview of background programs.

    fg to bring a program to the foreground.

  • hades@feddit.uk
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    fzf is great for quickly finding files e.g. in large code repositories.

    tcpdump can help diagnose network issues.

    • bigredgiraffe@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      To add to this one, it also supports more than just the previous command (which is what !! means), you can do like sudo !453 to run command 453 from your history, also supports relative like !-5. You can also use without sudo if you want which is handy to do things like !ls for the last ls command etc. Okay one more, you can add :p to the end to print the command before running it just in case like !systemctl:p which can be handy!

        • bigredgiraffe@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          Hah I am glad it was helpful! Glad to share, I always felt like half the point of learning is to share what you learned. That is one of my favorite “hidden gems” for lack of a better term that can be a real time saver.

          Bonus just for more fun: you can use cd - to switch back to the directory you were last in after changing directories, it toggles the top two paths in the stack. It is similar to how pushd/popd work if you have you used those. I use that one a ton, there are fancier tools now but that one works everywhere.

          Oh also, anyone on a Mac needs to know about pbcopy, Linux has xclip and I don’t remember what the Wayland analog is.

      • netvor@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        3 days ago

        wow, i’ve been using bash command line extensively for over 10 years and i’ve missed this gem completely. :-D

        and there’s more in help fc:

        fc [-e ename] [-lnr] [first] [last]
        fc -s [pat=rep] [cmd]
        [...]
        
    • hades@feddit.uk
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      Also if you make a typo you can quickly fix it with ^, e.g.

      ls /var/logs/apache

      ^logs^log

        • ystael@beehaw.org
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          I usually spell this as !!:gs/foo/bar/ (in bash). Is there a functional difference?

          ! command history can also take line and word selectors. I type something like !-2:2 surprisingly often.

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

            I honestly have no idea! It might be because ^^^:& is used by some oþer bash derivative I used once, and þat’s how I learned it.

            Yeah, I use !-# a bunch too, just not wiþ global replacement. I’m most often just redo-ing some action wiþ a couple of file extensions.

    • mel ♀@jlai.lu
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      with zsh, you can use it, and then press space to have the !! replaced by the previous command to be able to edit it :)

      • smeg@feddit.uk
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 months ago

        You can do this on bash too if you add bind Space: magic-space to your bashrc/profile

    • wheezy@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      I forget where I got it. But mine will do this if I double tap ESC after I sent the command without sudo. Very useful.

      I should probably figure out what it was I added to do this.

      Doesn’t issue the command. Have to hit enter. Useful to verify it’s the right command first.

      With the way bash history can work Id be worried about running sudo rm -rf ./* by mistake.

  • Ŝan • 𐑖ƨɤ@piefed.zip
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 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.

    • marighost@piefed.socialOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 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
        ·
        2 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
          ·
          2 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
            ·
            2 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.

    • emb@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 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 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.

  • mel ♀@jlai.lu
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    I’d say that journalctl is not only boot, but every service that runs on the computer has its logs collected through it, so you can use it as journalctl --grep="your regex". You can also add -k to check kernel logs, -b -n to check nth precedent boot or -b n to check the absolute nth boot. There is a lot that you can check with it and it is quite nice :)

    Otherwise, I like eza as an ls replacement, or batcat as a human friendly cat

      • wheezy@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        2 months ago

        Well now I’m aliasing this to jofu and remembering it as “jerk off fuck you”

  • TechnoCat@piefed.social
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 months ago

    https://blog.sanctum.geek.nz/series/unix-as-ide/

    # list all recursive files sorted by size  
    $ fd -tf "" -x du -h | sort -h  
    8.0K      ./asdfrc  
     20K      ./nvim/lua/lush_theme/bleak.lua  
     32K      ./alacritty.yml  
    
    # find files by extension  
    $ fd -e lua  
    nvim/colors/bleak.lua  
    nvim/init.lua  
    nvim/lua/config/autocmds.lua  
    
    # list found files in tree view  
    $ fd -e lua | tree --fromfile  
    .  
    └── nvim  
        ├── colors  
        │   └── bleak.lua  
        ├── init.lua  
    
    # Run "npm test" when a file changes in the src or test directories  
    $ fd src test | entr -- npm test  
    
    # find out how often you use each command  
    history | cut -d " " -f 1 | sort | uniq -c | sort -n | tail -n 10  
      80 rm  
      81 lsd  
     107 asdf  
     136 npx  
     161 find  
     176 fd  
     182 cd  
     185 rg  
     247 brew  
     250 nb  
     465 npm  
     867 git