this post was submitted on 11 Feb 2024
48 points (96.2% liked)

Linux

7801 readers
109 users here now

Welcome to c/linux!

Welcome to our thriving Linux community! Whether you're a seasoned Linux enthusiast or just starting your journey, we're excited to have you here. Explore, learn, and collaborate with like-minded individuals who share a passion for open-source software and the endless possibilities it offers. Together, let's dive into the world of Linux and embrace the power of freedom, customization, and innovation. Enjoy your stay and feel free to join the vibrant discussions that await you!

Rules:

  1. Stay on topic: Posts and discussions should be related to Linux, open source software, and related technologies.

  2. Be respectful: Treat fellow community members with respect and courtesy.

  3. Quality over quantity: Share informative and thought-provoking content.

  4. No spam or self-promotion: Avoid excessive self-promotion or spamming.

  5. No NSFW adult content

  6. Follow general lemmy guidelines.

founded 1 year ago
MODERATORS
48
Do you use aliases? (lemmy.world)
submitted 7 months ago* (last edited 7 months ago) by laverabe@lemmy.world 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 42 comments
sorted by: hot top controversial new old
[–] kometes@lemmy.world 29 points 7 months 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

[–] model_tar_gz@lemmy.world 13 points 7 months ago* (last edited 7 months 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.

[–] reallyzen@hachyderm.io 4 points 7 months ago* (last edited 7 months ago) (1 children)

@model_tar_gz @kometes "yay fuck" sounds better I believe

Does it *work*? IRL?

[–] model_tar_gz@lemmy.world 2 points 7 months ago

Yes it’s for real. I type fuck, it fixes my prompt, I accept and move on.

[–] rekabis@lemmy.ca 3 points 7 months ago

The what, now?

googles hastily

Oohhhhh mmmmmyyyyyyy…

[–] laverabe@lemmy.world 9 points 7 months ago (1 children)
[–] reallyzen@lemmy.ml 6 points 7 months ago (1 children)

Have tou heard of the sl command?

[–] laverabe@lemmy.world 3 points 7 months ago
[–] justin@lemmy.kde.social 1 points 7 months ago

alias g=grep -i

[–] fr_mg@lemmy.world 9 points 7 months ago (1 children)

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

[–] MaxHardwood@lemmy.ca 9 points 7 months ago (1 children)

CTRL+L works on most I've used

[–] user224@lemmy.sdf.org 2 points 7 months ago

But c and ENTER is even quicker. No need to reach out for ^L.

This kinda feels like Vim vs Emacs now.

[–] JASN_DE@lemmy.world 6 points 7 months ago

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

[–] justin@lemmy.kde.social 5 points 7 months ago

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

[–] whats_all_this_then@lemmy.world 5 points 7 months ago* (last edited 7 months 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'
[–] recapitated@lemmy.world 5 points 7 months ago

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

[–] surewhynotlem@lemmy.world 4 points 7 months ago (1 children)

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 2 points 7 months ago (1 children)

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

[–] surewhynotlem@lemmy.world 1 points 7 months ago

That sounds fantastic. Thanks!

[–] Quazatron@lemmy.world 4 points 7 months ago* (last edited 7 months ago)

alias ll = 'ls -l'

alias kk = 'ls -l'

alias jj = 'ls -l'

Dyslexia sometimes hits hard.

[–] treadful@lemmy.zip 4 points 7 months ago

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

[–] victorz@lemmy.world 4 points 7 months ago* (last edited 7 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.)

[–] packetloss@lemmy.world 4 points 7 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.

[–] FlapKap@feddit.dk 3 points 7 months ago* (last edited 7 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

[–] lurch@sh.itjust.works 3 points 7 months ago

no, i make shell scripts for everything in /usr/local/bin/ . i find it more easy to manage and transfer. one liners can become bigger real quick, so i start with a script right away. also, since they have the shell in the hash bang line, they work in multiple shells.

[–] jws_shadotak@sh.itjust.works 2 points 7 months ago

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

"bash update" will run apt update and upgrade

[–] transientpunk@sh.itjust.works 2 points 7 months ago

I use aliases to streamline some of my git workflows

[–] squid_slime@lemmy.world 2 points 7 months ago* (last edited 7 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

[–] ohlaph@lemmy.world 2 points 7 months ago
[–] verstra@programming.dev 2 points 7 months 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";
[–] gmhh@lemmy.world 2 points 7 months ago* (last edited 7 months 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"
[–] s4if@lemmy.world 1 points 7 months ago* (last edited 7 months 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

[–] jelloeater85@lemmy.world 1 points 6 months ago

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

[–] dwemthy@lemdro.id 1 points 7 months ago

Only for typos alias bim="vim"

[–] user224@lemmy.sdf.org 1 points 7 months ago* (last edited 7 months 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'
[–] macattack@lemmy.world 1 points 7 months ago* (last edited 7 months 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)
[–] Evkob@lemmy.ca 0 points 7 months ago (1 children)

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?

[–] laverabe@lemmy.world 2 points 7 months ago

CAD programs that have command line utilities, old text based games in the 90s had aliases and they were used a lot. I had just never thought to use them in BASH for some reason.