Do you use aliases? (lemmy.world)
submitted 2 years ago* (last edited 2 years ago) by to c/linux@lemmy.world
 

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?

all 43 comments

sorted by: hot top controversial new old
[–] 30 points 2 years ago (3 children)

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

  • source
  • hideshow 6 child comments
  • [–] 14 points 2 years ago* (last edited 2 years ago) (3 children)

    In a big fan of the ‘fuck’ package for this. Try it out. Sudo apt install thefuck.

    edit: oops got the name wrong; been a while since I installed it. Fuck.

  • source
  • parent
  • hideshow 6 child comments
  • [+] 1 point 2 years ago* (1 child)
  • [–] 2 points 2 years ago (1 child)

    Funny. I never even thought of using thefuck in any remotely production-esque kind of way. Only for its intended use case: to save me a few keystrokes retyping some command I fucked up typing.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 years ago

    Yeah I imagine that was just a simple focus issue, like typing in the wrong tmux pane or sending terminal commands while his editor was focused. I’ve done that plenty of times.

    I think it’s a fun and useful package too. If there’s a moral to that story, it’s just to treat others with respect and avoid isolating yourself by discouraging feedback. Thefuck just made the anecdote colorful enough to share lol

    (Sorry for delete btw, realized after I woke up that a few of those coworkers switched to lemmy and I never told anyone I let that bug go)

  • source
  • parent
  • [–] 11 points 2 years ago (1 child)

    A humble and simple "c" for "clear" in the terminal.

  • source
  • hideshow 2 child comments
  • [–] 7 points 2 years ago

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

  • source
  • [–] 7 points 2 years 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'
    
    
  • source
  • [–] 5 points 2 years ago

    Don't overlook functions, they're more versatile.

  • source
  • [–] 5 points 2 years ago

    There's not enough storage space on the Internet to list all my aliases.

  • source
  • [–] 5 points 2 years ago* (last edited 2 years ago)

    Oh boy, my time to shine:

    • mkd - Create directory and immediately cd into it
    • dei - docker exec -i
    • dps - docker ps
    • mdocker - Switch to minikube's docker context
    • n - nvim
    • n. - nvim .

    Node package managers

    Exampes use pnpm but I have them for yarn, npm, and bun too

    • pi - pnpm install
    • pd - pnpm run dev

    fzf stuff

    • sdh - Search home directory (directories, recursive)

    Meme

    • fuckyou - git push --force
    • nano - nvim

    Misc

    createpgdb - Create a postgres db on the given container with the given name

    Usage: createpgdb "postgres container" "db name"

    I have similar ones for dropdb and pg_dump. Here's the command:

    f() { local __user; if [ -z $3 ]; then __user=postgres; else __user=$3; fi; docker exec -i $1 createdb -U $__user $2; unset -f f; }; f'
    
  • source
  • [–] 4 points 2 years ago* (last edited 2 years 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.)

  • source
  • [–] 4 points 2 years ago

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

  • source
  • [–] 4 points 2 years ago (1 child)

    hgrep

    history | grep

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

  • source
  • hideshow 2 child comments
  • [–] 4 points 2 years 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.

  • source
  • [–] 4 points 2 years ago*

    alias ll = 'ls -l'

    alias kk = 'ls -l'

    alias jj = 'ls -l'

    Dyslexia sometimes hits hard.

  • source
  • [–] 3 points 2 years 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

  • source
  • [+] 3 points 2 years ago
    [–] 2 points 2 years ago

    I use aliases to streamline some of my git workflows

  • source
  • [–] 2 points 2 years ago*

    Yes, when I type $installed

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

  • source
  • [–] 2 points 2 years ago

    I don't use aliases but I use bash to do common things.

    "bash update" will run apt update and upgrade

  • source
  • [–] 2 points 2 years ago
    [–] 2 points 2 years ago

    I use a few, but this one is the best and most used:

    gg = "git log --branches --remotes --tags --graph --pretty='%C(yellow)%h %C(cyan)%cd %Cblue%aN%C(auto)%d %Creset%s' --date=relative";
    
  • source
  • [–] 2 points 2 years ago*

    Some of these demand that the terminal you use them with is kitty:

    alias ipc='curl icanhazip.com'
    # btop is *pretty* bloat!
    alias htop='btop'
    # I'm kinda proud of this oneliner. It's pointless, but it was fun. It displays a random square image when you run
    # neofetch rather than the default ansi art
    alias neofetch='filarr=(~/Media/Images/1x1/*.*) && fil=${filarr[$RANDOM % ${#filarr[@]}]} && neofetch --kitty $fil' 
    # comics are an important part of my life
    alias gd='cd ~ ; gallery-dl'
    alias gde="cd ~ ; gallery-dl --chapter-filter 'lang == (\"en\")'"
    alias yd='yt-dlp --sub-langs all --embed-subs --embed-chapters --progress --paths home:~/Downloads'
    alias subl="/opt/sublime_text/sublime_text"
    #exa is currently unmaintained. eza is a maintained fork. It installs a link to exa, but...
    alias ls="eza --icons --hyperlink --group-directories-first --git"
    alias lsblkv="lsblk -o \"NAME,KNAME,SIZE,TYPE,VENDOR,MODEL,MOUNTPOINT\""
    alias icat="kitty +kitten icat"
    alias mem="grep -e Dirty: /proc/meminfo; grep -e Writeback: /proc/meminfo"
    alias flush="sync"
    alias links="links https://www.duckduckgo.com"
    alias q="qalc"
    alias hf="history 1 | fzf"
    # tile the first two kitty windows and resize all kitty windows to 915x945, redirecting any errors to /dev/null
    alias tk="xdotool search --class kitty windowmove %1 30 105 windowmove %2 975 105 windowsize %@ 915 945 2>/dev/null"
    # only ask for password once on long updates
    alias yay="yay --sudoloop"
    
  • source
  • [–] 1 point 2 years ago* (last edited 2 years ago)

    Slightly.

    These are the aliases I set manually:

    alias :q='exit'
    alias kgpg='gpgconf --kill gpg-agent'
    alias battery='upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep -wE "percentage:|time to empty:|state:|energy:|energy-rate:|voltage:"'
    alias park='sudo hdparm --idle-unload'
    
  • source
  • [–] 1 point 2 years ago

    Only for typos alias bim="vim"

  • source
  • [+] 1 point 2 years ago* (last edited 2 months ago)
    [–] 1 point 2 years ago*

    I've got a ton, most are already listed or along the same vein.

    The two suggestions I have are not actual aliases but worth remembering:

    • Ctrl + Alt + E - turn your alias into its original command
    • \ - Place before your alias to run the original command's meaning. Useful if you overwrite a default command (overwriting default commands is not recommended though... often the alias will ignore any options passed through and so let's say you overwrite rm with another app that deletes files, then you forget that, and then try to delete some files using rm-i to get a prompt for each removed file. Often the alias will just operate as normal w/o a prompt saying that it ignored -i completely)
  • source
  • [–] 1 point 2 years ago

    OMZsh has some powerful auto complete if you care to look around. Their plugins are amazing for saving time.

  • source
  • [–] 1 point 2 years ago*

    me:
    wgup="sudo wg-quick up wg0"
    wgdown="sudo wg-quick down wg0"
    and some pacman cleaning command..
    edit: forgot that it is markdown

  • source
  • [–] 0 points 2 years ago (1 child)

    My aliases all involve updating Docker containers or managing VPN and SSH connections to the laptop that hosts them.

    I'm a bit confused as to what you mean by "I’ve used them in the past and on specific programs but never on command line utilities". What's an example of an alias you used outside CLIs?

  • source
  • hideshow 2 child comments