I thought it’d be a pain but installing programs through the terminal is actually so nice, I never would have expected it

  • kibiz0r@midwest.social
    link
    fedilink
    English
    arrow-up
    102
    ·
    2 days ago
    • tab completion works in more places than you might expect
    • ctrl-a/ctrl-e for start/end of line
    • ctrl-u to clear the command you’ve typed so far but store it into a temporary pastebuffer
    • ctrl-y to paste the ctrl-u’d command
    • ctrl-w to delete by word (I prefer binding to alt-backspace though)
    • ctrl-r to search your command history
    • alt-b/alt-f to move cursor back/forwards by word
    • !! is shorthand for the previous run command; handy for sudo !!
    • !$ is the last argument of the previous command; useful more often than you’d think
    • which foo tells you where the foo program is located
    • ls -la
    • cd without any args takes you to your home dir
    • cd - takes you to your previous dir
    • ~ is a shorthand for your home dir
    • hamsda@lemm.ee
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      6 hours ago

      Saved! Thank you so much.

      I’ve used Linux full-time since late 2020 and I never knew about ctrl+y and ctrl+u.

      I’d also like to contribute some knowledge.

      aliases

      You can put these into your ~/.bashrc or ~/.zshrc or whatever shell you use.

      ###
      ### ls aliases
      ###
      # ls = colors
      alias ls='ls --color=auto'
      
      # ll = ls + human readable file sizes
      alias ll='ls -lh --color=auto'
      
      # lla = ll + show hidden files and folders
      alias lla='ls -lah --color=auto'
      
      ###
      ### other aliases
      ###
      # set color for different commands
      alias diff='diff --color=auto'
      alias grep='grep --color=auto'
      alias ip='ip --color=auto'
      
      # my favourite way of navigating to a far-off folder
      # this scans my home folder and presents me with a list of
      #    fuzzy-searchable folders
      #    you need fzf and fd installed for this alias to work
      alias cdd='cd "$(sudo fd -t d . ${HOME} | fzf)"'
      

      recommendations

      ncdu - a shell-based tool to analyze disk usage, think GNOME’s baobab or KDE’s filelight but in the terminal

      zellij - tmux but easy and with nice colors

      atuin - shell history but good, fuzzy-searchable. If you still have the basic shell history (when pressing ctrl+r), I cannot recommend this enough.

      ranger - a terminal file-browser (does everything I need and way more)

      • fibojoly@sh.itjust.works
        link
        fedilink
        arrow-up
        1
        ·
        1 hour ago

        +1 for Atuin. I constantly use it on my machine and SSH-ing on remote machines who don’t have it is an absolute pain.

        I’m gonna have to save this thread and check some of those!

    • Lovable Sidekick@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      5 hours ago

      For me the Home/End keys also go to the start/end of a line like ctrl-a/ctrl-e, and ctrl-tab/ctrl-Tab move the cursor fwd/back a word at a time.

    • MonkeMischief@lemmy.today
      link
      fedilink
      arrow-up
      6
      ·
      23 hours ago

      Saving this! Absolutely gold, thanks for writing it up. You’re what makes the Linux community cool. ❤️

      tab completion works in more places than you might expect

      I’ve found tab to be such a nice “please give me a hint” button.

      • Bonus tip : Sometimes you won’t get auto complete because there’s too many possibilities and the computer can’t be certain which one you want. Hitting tab multiple times will show the possibilities, so you can type in enough characters to remove ambiguity, hit tab again, and boom auto complete!

      …That was a terribly convoluted explanation I’m sorry. Just try hitting tab multiple times for fun if you’re stuck it’s kinda handy. Lol

    • ayyy@sh.itjust.works
      link
      fedilink
      arrow-up
      6
      ·
      1 day ago

      If you’re looking for a full list of these kind of navigation shortcuts, they all come from readline so read the man page for that. Or just look up the basic navigation of emacs which is what readline is mimicking.

      • kattfisk@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        4
        ·
        edit-2
        7 hours ago

        A neat thing is that a lot of command line programs use readline. So learning and configuring it will also be useful in for example the Python REPL and calc.

        Here are some neat configuration options you can put in ~/.inputrc

        set completion-ignore-case on
        set show-all-if-ambiguous on
        set completion-prefix-display-length 9
        set blink-matching-paren on
        set mark-symlinked-directories on
        

        And if you are a sensible person who is used to vim

        set editing-mode vi
        set show-mode-in-prompt on
        
      • Dumhuvud@programming.dev
        link
        fedilink
        English
        arrow-up
        9
        ·
        1 day ago

        I believe, these are Emacs shortcuts. There’s also set -o vi in bash, but I’ve never used it, so can’t vouch for it.

        • Hawke@lemmy.world
          link
          fedilink
          arrow-up
          4
          ·
          1 day ago

          That’s good to know. It’s interesting that the other commenter thinks emacs shortcuts are illogical. I’ll make my best guesses at the logic

          • ctrl-a/ctrl-e for start/end of line

          a is the beginning of the alphabet; e for end (of line)

          • ctrl-u to clear the command you’ve typed so far but store it into a temporary pastebuffer
          • ctrl-y to paste the ctrl-u’d command

          No idea here. Seems similar to nano with k-“cut” and u-”uncut”.

          • ctrl-w to delete by word

          w for word obviously.

          • ctrl-r to search your command history
          • alt-b/alt-f to move cursor back/forwards by word

          r reverse, b back, f forward. Not sure why alt vs control though; presumably ctrl+b and ctrl+f do different things although I know emacs likes to use Alt (“Meta”) a lot.

          • MedicsOfAnarchy@lemmy.world
            link
            fedilink
            arrow-up
            6
            ·
            1 day ago

            In the 1980s, Digital Equipment Corporation had a word processor, WPS. Ctrl-u cleared the line you were typing and put it into the paste buffer. Maybe legacy usage?

        • apelsin12@lemm.ee
          link
          fedilink
          arrow-up
          6
          ·
          1 day ago

          Explains why they are so illogical! Unfortunately i think its better to just learn the defaults since i remote into lots of servers where i dont carry my config

    • exocortex@discuss.tchncs.de
      link
      fedilink
      arrow-up
      12
      ·
      edit-2
      1 day ago

      I’ve been using the commandline for so long but was always too lazy to look up the rest of these commands after ctrl+a/e and ctrl+r THANK YOU!!!

      post this commend again and again! There’s always lazy idiots like me who will be helped that way!

    • myotheraccount@lemmy.world
      link
      fedilink
      arrow-up
      11
      ·
      1 day ago
      • alt-. also pastes the last argument of the previous command (useful if you need to modify it a bit)
      • instead of any shortcuts starting with “alt” you can also press “esc” followed by the second key, e.g. pressing “esc”, releasing it and then “a” is the same as pressing “alt-a” (useful if you have only one hand available, or if alt is not availalble)
      • if you put a space before a command, it will not be saved in history (useful sometimes, e.g. if you pass a password directly as an argument)
    • Dumhuvud@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      ·
      1 day ago

      Nice list, TIL about Ctrl+U and Ctrl+Y.

      If I may add, Ctrl+X into Ctrl+E opens $EDITOR to edit the current line.