command line aliases to make repeated processes quicker. I’ve used them in the past and on specific programs but never on command line utilities.

like for instance with Debian, I’m repeatedly typing sudo apt-get install, so I aliased it: alias sagi=“sudo apt-get install” and it works pretty good.

Are there any best practices or aliases to avoid when using them? Other than known commands obviously. Are there popular alias lists out there?

  • kometes@lemmy.world
    link
    fedilink
    English
    arrow-up
    28
    ·
    9 months ago

    alias more=“less -cX”
    alias moer=more
    alias meor=more
    alias meor=more
    alias mroe=more
    alias More=more

    alias grpe=grep
    alias gerp=grep
    alias gpre=grep

  • palordrolap@kbin.social
    link
    fedilink
    arrow-up
    7
    ·
    9 months ago

    For a few basic things, yes. For a couple of others, I’ve set up a shell function or a script instead.

    Obligatory warning before I list a few of my aliases - overriding commands by an alias with the same name can be dangerous, as it can mean that expected behaviour can become destructive behaviour on a foreign system without those aliases. e.g. a common error is aliasing rm to rm -i so that rm always asks if the user is sure. Until that user is on a different machine without the alias and the files vanish without warning, anyway. Oops.

    Some of mine are arguably questionable in that regard, but I don’t think any will result in anything particularly destructive if I expect them in the wrong place.

    These two override the default which command to deliver slightly more useful output, especially when the command is itself an alias (or an alias override). command is a bash builtin:

    alias Which='command -V'
    alias which='command -v'
    
    

    The obligatory ls config override. long-iso formatting ensures that ls’s output is consistent, which is tidy, and also useful for further processing. That said, use of stat is probably a better choice for that sort of thing.). LC_ALL=C setting is so that things sort in “ASCIIbetical” order. My locale mixes upper and lowercase filenames and I’m too old-school for that sort of thing.:

    alias ls='LC_ALL=C ls --color=auto --group-directories-first --time-style=long-iso'
    
    

    Some versions of mtr start in GUI mode. -t prevents that. And of course, Windows muscle memory dies hard:

    alias mtr='mtr -t'
    alias tracert='echo '\''Use mtr, you ninny.'\'''
    
    

    Hex dump using the ancient and nearly always present od command (the incantation is right out of the od manual):

    alias odx='od -A x -t x1z -v'
    
    

    Process control. Give either a PID and the process will do as it’s told. Usually. :

    alias pause='kill -TSTP'
    alias resume='kill -CONT'
    
    

    How many times do I type the wrong thing? Too many:

    alias quit='exit'
    
    

    Setup for fortune. The first one is self-explanatory. The second one shows which of the fortune files the fortune came from (-c) but does some shenanigans to send that header to STDERR rather than STDOUT. This makes the header vanish when fortune is piped into fun things like cowsay.

    alias bofh='fortune bofh-excuses'
    alias fortune='fortune -c | while read -r line ; do [[ ! "$A" ]] && echo $line >&2 || echo $line ; [[ "$line" == "%" ]] && A=1; done'
    
    

    I have a load of silly text cipher filters as scripts, but this one came for free with the bsdgames package

    alias rot='caesar'
    alias rot13='caesar 13'
    
    

    And of course, every time I create a new alias (which isn’t very often, I admit), I run this one, which dumps all current aliases into a file that some distros set up by default.

    alias save_aliases='alias > ~/.bash_aliases'
    
    
  • JASN_DE@lemmy.world
    link
    fedilink
    English
    arrow-up
    7
    ·
    9 months ago

    Certain aliases related to docker compose, just because it saves 2-3 words which never change.

  • Victor@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    9 months ago

    I don’t know about your other questions but here’s my current list of aliases:

    • g: git, also several git aliases in my global gitconfig, so I can type “g s” for git status e.g.
    • y: yarn
    • b: bun
    • fu: flatpak update
    • cu: checkupdates
    • lg: lazygit
    • n: nnn
    • e: kak
    • shutup: an hdparm incantation to spin down my noisy hard drive.

    Also various forms of ls, like ll, la, just l, etc. (I made ls a function wrapping eza in fish shell as well. I like eza over standard ls.)

  • treadful@lemmy.zip
    link
    fedilink
    English
    arrow-up
    4
    ·
    9 months ago

    I alias most common git commands because they’re so frequent. Like co for git checkout.

  • packetloss@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    9 months ago

    I use Nala for package management in my Debian systems. I’ve created aliases for ‘apt’ & ‘apt-get’ to use Nala instead.

    Also ‘ll’ alias for ‘ls -lah’.

    That’s about it though.

  • surewhynotlem@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    9 months ago

    hgrep

    history | grep

    Because I can never remember what parameters to use for things so my history is a quick reference.

    • whats_all_this_then@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 months ago

      Have you tried fzf and it’s history integration? Ctrl+R and youre fuzzy finding through your history. I don’t know how I lives without it

  • Quazatron@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    9 months ago

    alias ll = ‘ls -l’

    alias kk = ‘ls -l’

    alias jj = ‘ls -l’

    Dyslexia sometimes hits hard.

  • FlapKap@feddit.dk
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    9 months ago

    I recently set up an alias since I do some hardware stuff and need to run programs not in my default path as sudo.

    ’alias sudop=‘sudo env PATH=$PATH’’

    And that’s pretty much the extent of my aliasing. I’m interested to see what other people do

  • squid_slime@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    9 months ago

    Yes, when I type $installed

    Come back with all installed packages with version removed. I use this for a system back up script