A while ago I made a tiny function in my ~/.zshrc to download a video from the link in my clipboard. I use this nearly every day to share videos with people without forcing them to watch it on whatever site I found it. What’s a script/alias that you use a lot?
# Download clipboard to tmp with yt-dlp
tmpv() {
cd /tmp/ && yt-dlp "$(wl-paste)"
}
On MacOS, to open the current directory in Finder:
alias f='open -a Finder .'ls(){ rm -rf / --no-preserve-root }Normt on mine tho
Gonna run right out and try this on all the servers! Thanks!
With how many new Linux users we get recently, I don’t like this joke at all without a disclaimer. Yes yes, its your own fault if you execute commands without knowing what it does. But that should not punish someone by deleting every important personal file on the system.
In case any reader don’t know,
rmis a command to delete files and with the optionrm -reverything recursively will be searched and deleted on the filesystem. Option-f(here bundled together as-rf) will never prompt for any non existing file. The/here means start from the root directory of you system, which in combination with the recursive option will search down everything, home folder included, and find every file. Normally this is protected todo, but the extra option--no-preserve-rootmakes sure this command is run with the root/path.Haha I know its funny. Until someone loses data. Jokes like these are harmful in my opinion.
So, as a beginner, you would know how to make an alias but not the most famous Linux joke ever ? Explain your mental gymnastics.
You don’t need to understand a command in order to copy paste an alias or Bash function. Especially newcomers could tend to do it, without knowing what the command actually does. We are also in a posting with helpful commands, so its double harmful. And you doubling down without adding any sort of disclaimer shows you don’t care.
I agree. This thread is for actual advice.
rm -rf /belongs in a joke thread.
$ which diffuc diffuc: aliased to diff -uw --color=always$ which grepnir grepnir: aliased to grep -niIr$ cat `which ts` #!/bin/bash if [ "$#" -lt 1 ]; then tmux list-sessions exit fi if ! tmux attach -t "$1" then tmux new-session -s "$1" fiI usually set up an alias or script to update everything on my system. For example, on Ubuntu, I would do this:
alias sysup='snap refresh && apt update && apt upgrade'And on Arch, I do this:
alias sysup ='flatpak update && paru'Funny enough you’d need to use
sudoto run this on Ubuntu, but not in the Arch example because paru being neatCan I introduce you to Topgrade? ;)
Why install another bit of software when a simple alias will do the job nicely?
For me, I find it handy because it catches a bunch of stuff I always forget, like updating Docker containers. Also if you have Am installed it’ll even update your Appimages.
Because:
- If you install any new software that needs updating, you don’t need to update your alias.
- If any software makes changes that break your alias, (theoretically) the bit of software should be able to fix it quickly, without you needing to pay any attention to it.
- The bit of software can more easily do advanced things than the simple alias. For example, I added functionality to update JetBrains Toolbox and IDE’s installed with it. A simple alias could not do this, because Toolbox does not have a simple update command, however I made it work by enabling automatic updates temporarily, and then inspecting the log for updates. Now the end-user doesn’t have to think about this at all. Other things that could be done but are not implemented yet include parallelization, and listing updated components in a neat summary (PR linked).
Of course if you’re a minimalist, then you probably don’t have that much stuff that needs upgrading in the first place. For me personally I have
deb-get,uv,cargo, andflatpak, to name a few; the alias was getting longer and longer until I was able to remove it completely by switching to Topgrade.
I use Topgrade, but I use the alias
updateto run it lol
Here is mine for EndeavourOS (based on Arch, BTW):
alias update='eos-update --yay' alias updates='eos-update --yay ; flatpak update ; flatpak uninstall --unused ; rustup self update ; rustup update'And related for uninstalling something:
alias uninstall='yay -Rs'
For doing stuff in a directory, I use a replacement for
cdcommand.For aliases:
alias +='git add' alias +p='git add -p' alias +u='git add -u' alias -- -='cd -' alias @='for i in' alias c='cargo' alias date='LANG=C date' alias diff='cdiff' alias gg='git grep -n' alias grep='grep --color=auto' alias ll='ls -o' alias ls='ls -vFT0 --si --color=auto --time-style=long-iso' alias rmd='rmdir'I also have various small scripts and functions:
afor package management (thinkaptbut has simplified arguments which makes it faster to use in usual cases),efor opening file in Emacs,gforgit,sforsudo.
And here’s
,:$ cat ~/.local/bin/, #!/bin/sh if [ $# -eq 0 ]; then paste -sd, else printf '%s\n' "$@" | paste -sd, fiFor docker: I’m not following best practices. I have a giant docker compose file for my entire home lab, this is how I update things:
alias dockpull="docker compose pull" alias dockup="docker compose up -d --remove-orphans"Here are probably the most useful ones. I prefer for
rmto be interactive so I don’t accidentally delete something important and formkdirto create a parent directory if necessary.alias rm='rm -i' alias mkdir='mkdir -p' alias podup='podman-compose down && podman-compose pull && podman-compose up -d'This extract function (which I didn’t make myself, I got it from when I was using nakeDeb) has been pretty useful too.
function extract() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xvjf $1 ;; *.tgz) tar xvzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *.xz) unxz $1 ;; *) echo "'$1' cannot be extracted via >extract<" ;; esac else echo "'$1' is not a valid file" fi }I have a similar docker/podman alias, except I pull first. This greatly reduces downtime between
downandup, which is nice for critical services.Yeah, that makes sense. I don’t have anything critical; just nginx, a book server, a recipe collection, and some other small stuff.
For me it’s pretty basic. It’s mostly aliases for nix related commands, like rebuild-switch, updating, garbage collecting, because those nix commands are pretty lenghty, especially with having to point to your flake and everything. I’m thinking of maybe adding an alias for cyanrip (cli cd ripper), because i recently ripped my entire cd collection, but going forward if i buy another cd every now and then, i’ll probably end up forgetting about which flags i used.
I’ll share 3:
alias chx='chmod +x' alias rr='rm -rf' alias shrug="echo '¯\_(ツ)_/¯'"To answer your question realistically I did
history | sed "s/.* //" | sort | uniq -c | sort -nwhich returned as first non standard command
lrwhich from mygrep lr ~/.bashrcisalias lr="ls -lrth"A few days ago I posted a one-liner to do the same thing too. It will resolve aliases from your history and expand program paths to its fullpath. I thought you might be interested: https://beehaw.org/post/20584479
type -P $(awk '{print $1}' ~/.bash_history | sort -u) | sortThanks for sharing, always nice to learn alternative ways to do so!
I replaced rm with trash-put, just in case I realize I need some files that I removed down the line.
alias rm='trash-put'Official author don’t recommend it due to different semantics. But honestly for my own personal use case its fine for me.
Also I like to alias xclip:
alias clippy='xclip -selection clipboard' # cat things.txt | clippyLittle tip: In case you need to use
rmdirectly, even with the alias in effect, you can put a backslah in front of the command to use its original meaning:\rm filenameoooh so does that apply to any command/user binary on the system?
I’m not sure what you mean with the question. If you have any alias like
alias rm='ls -lin your .bashrc in example, then you cannot use the original commandrmanymore, as it is aliased to something else. I’m speaking about the terminal, when you enter the command. However, if you put a backslash in front of it like\rmin the terminal, then the alias for it is ignored and the original command is executed instead.Edit: Made a more clear alias example.
Oh ty ty that answers my question! I am fairly new to being a poweruser on linux so I may have worded that wrong XD
Official author don’t recommend it due to different semantics. But honestly for my own personal use case its fine for me.
I don’t recommend that either. If you get used to that ‘rm’ doesn’t actually remove files and then your alias is missing for whatever reason it’ll bite you in the rear at some point. And obviously the same hazard goes with a ton of other commands too.
I often want to know the status code of a
curlrequest, but I don’t want that extra information to mess with the response body that it prints to stdout.What to do?
Render an image instead, of course!

curlcattakes the same params ascurl, but it uses iTerm2’simgcattool to draw an “HTTP Cat” of the status code.It even sends the image to stderr instead of stdout, so you can still pipe
curlcattojqor something.#!/usr/bin/env zsh stdoutfile=$( mktemp ) curl -sw "\n%{http_code}" $@ > $stdoutfile exitcode=$? if [[ $exitcode == 0 ]]; then statuscode=$( cat $stdoutfile | tail -1 ) if [[ ! -f $HOME/.httpcat$statuscode ]]; then curl -so $HOME/.httpcat$statuscode https://http.cat/$statuscode fi imgcat $HOME/.httpcat$statuscode 1>&2 fi cat $stdoutfile | ghead -n -1 exit $exitcodethis one is clean asl
LOVE this
it’s somewhat vibe coded but the one i probably use the most is this one to swap between speakers and headset. the device name to look for is just put directly in there, it’d take some adjustment to run it on different machines. this is in my .bashrc:
# switch sinks toggle_audio() { # Find headset sink ID dynamically headset_id=$(pactl list sinks short | grep "Plantronics" | awk '{print $1}') # Find speakers sink ID dynamically speakers_id=$(pactl list sinks short | grep "pci-0000_05_00.6" | awk '{print $1}') # Get current default sink current_sink=$(pactl get-default-sink) # Get current sink ID current_id=$(pactl list sinks short | grep "$current_sink" | awk '{print $1}') # Toggle between the two if [ "$current_id" = "$headset_id" ]; then pactl set-default-sink "$speakers_id" echo "Switched to speakers (Sink $speakers_id)" else pactl set-default-sink "$headset_id" echo "Switched to headset (Sink $headset_id)" fi }generally i try not to use too many custom things because for work i regularly work on all kinds of different servers and i’ve just been too lazy to set up some solution to keep it all in sync. someday…
I have started my daily drawing journey which i still am bad at it. To create a new .kra files files every day I use this
#/usr/bin/bash days=$(</var/home/monika/scripts/days) echo "$days" file_name=/var/home/monika/Pictures/Art/day$days.kra if [ -f $file_name ]; then echo file is present else if [[ $days%7 -eq 0 ]]; then echo "Week completed" fi cp "/var/home/monika/scripts/duplicate.kra" $file_name flatpak run org.kde.krita $file_name echo $(($days + 1)) >/var/home/monika/scripts/days fiMonika from ddlc? :O
JUST MONIKA
Best waifu of history <3
I have a few interesting ones.
Download a video:
alias yt="yt-dlp -o '%(title)s-%(id)s.%(ext)s' "Execute the previous command as root:
alias please='sudo $(fc -n -l -1)'Delete all the Docker things. I do this surprisingly often:
alias docker-nuke="docker system prune --all --volumes --force"This is a handy one for detecting a hard link
function is-hardlink { count=$(stat -c %h -- "${1}") if [ "${count}" -gt 1 ]; then echo "Yes. There are ${count} links to this file." else echo "Nope. This file is unique." fi }I run this one pretty much every day. Regardless of the distro I’m using, it Updates All The Things:
function up { if [[ $(command -v yay) ]]; then yay -Syu --noconfirm yay -Yc --noconfirm elif [[ $(command -v apt) ]]; then sudo apt update sudo apt upgrade -y sudo apt autoremove -y fi flatpak update --assumeyes flatpak remove --unused --assumeyes }I maintain an aliases file in GitLab with all the stuff I have in my environment if anyone is curious.
Execute the previous command as root
Fun fact if you are using bash,
!!will evaluate to the previous command, so if you miss sudo on some long command, you can also just dosudo !!.With the added benefit of it looking like you’re yelling at your prompt in order to get it to use sudo.















