this post was submitted on 23 Jun 2025
62 points (97.0% liked)

Linux

8038 readers
814 users here now

A community for everything relating to the GNU/Linux operating system

Also check out:

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 2 years ago
MODERATORS
 

OC by @als@lemmy.blahaj.zone

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)"
}
top 30 comments
sorted by: hot top controversial new old
[–] DesolateMood@lemmy.zip 11 points 1 day ago (2 children)

This is dumb lol but

update = "sudo apt update && sudo apt upgrade"

Exchange apt for whatever package manager you use, optionally add "&& flatpak upgrade". If you really want to live on the edge throw a -y in there as well

[–] mcmodknower@programming.dev 7 points 20 hours ago (1 children)

Mine is a bit longer and includes automatically removing unused dependencies: alias update='sudo apt update && sudo apt upgrade && flatpak update && sudo apt autoremove --purge && flatpak remove --unused --delete-data && notify-send '\''update done'\'''

[–] DesolateMood@lemmy.zip 1 points 20 hours ago

I just end mine with "&& exit"

[–] kmirl@lemmy.world 3 points 12 hours ago

I have a similar one as well for debian-based operating systems...

dist-upgrade() {
    sudo apt update && sudo apt dist-upgrade && sudo apt autoremove
}

To get this to work without a password, i dropped a file in /etc/sudoers.d that allows anyone in the sudo group to sudo apt without a password.

root@tux:~# cat /etc/sudoers.d/apt

# Cmnd alias specification
Cmnd_Alias COMMANDS = /usr/bin/apt, /usr/bin/apt-get, /usr/bin/dpkg

# Use apt commands without a password
%sudo ALL=(root) NOPASSWD: COMMANDS
[–] truthfultemporarily@feddit.org 10 points 1 day ago (2 children)

It already comes with many distros and I can't live without ll="ls -la"

[–] A_norny_mousse@feddit.org 7 points 1 day ago* (last edited 1 day ago)

alias ll='ls --group-directories-first --color=auto -lahF'

[–] spartanatreyu@programming.dev 3 points 14 hours ago (1 children)
[–] Redjard@lemmy.dbzer0.com 1 points 9 hours ago

alias l='ls -lahv --time-style +%Y-%m-%d\ %H:%M:%S'

[–] A_norny_mousse@feddit.org 9 points 1 day ago (2 children)
alias zipcat='gunzip -c'
alias untar='tar -xzvf'
alias ping='ping -c3'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
[–] rutrum@programming.dev 5 points 20 hours ago (1 children)

I use a tool called ouch so I never have to remember the tar flags ever again.

[–] arcayne@lemmy.today 2 points 7 hours ago

Oooh, ouch looks really neat! May actually cause me to retire my extract function. It suddenly feels a little incomplete by comparison, lol.

# Extract any archive
extract() {
        if [ -f "$1" ]; then
                case $1 in
                *.tar.bz2) tar xjf "$1" ;;
                *.tar.gz) tar xzf "$1" ;;
                *.bz2) bunzip2 "$1" ;;
                *.rar) unrar x "$1" ;;
                *.gz) gunzip "$1" ;;
                *.tar) tar xf "$1" ;;
                *.tbz2) tar xjf "$1" ;;
                *.tgz) tar xzf "$1" ;;
                *.zip) unzip "$1" ;;
                *.Z) uncompress "$1" ;;
                *.7z) 7z x "$1" ;;
                *) echo "'$1' cannot be extracted via extract()" ;;
                esac
        else
                echo "'$1' is not a valid file"
        fi
}
[–] Havatra@lemmy.zip 2 points 1 day ago (1 children)

Do you often (if at all) run into conflicts with the .. alias? I can't think of any case on top of my head, but it feels a bit sketchy. The more than 2 dots however I imagine is pretty safe.

[–] A_norny_mousse@feddit.org 3 points 1 day ago* (last edited 1 day ago)

No, never. I rarely use the 4 dots, but 2 and 3, all the time.

Tab completion shows this:

$ ..<Tab><Tab>
../   ...   ....
[–] TwilightKiddy@programming.dev 6 points 1 day ago* (last edited 1 day ago)

Wouldn't say I use it often, but this thing resolves a domain name to an IP address:

function resolve() {
  case $1 in
    -4)
      getent ahostsv4 $2 | grep STREAM | head -n 1 | cut -d ' ' -f 1
      ;;
    -6)
      getent ahostsv6 $2 | grep STREAM | head -n 1 | cut -d ' ' -f 1
      ;;
    -p)
      getent hosts $2 | head -n 1 | cut -d ' ' -f 1
      ;;
    *)
      getent ahosts $1 | grep STREAM | cut -d ' ' -f 1 | sort -u      
      ;;
  esac
}

All my aliases are just default arguments for programs or shorthands for my other scripts, most of which are specific for my setup.

This is a very good argument for ffmpeg and ffprobe, by the way:

alias ffmpeg="ffmpeg -hide_banner"
alias ffprobe="ffprobe -hide_banner"
[–] beeng@discuss.tchncs.de 5 points 19 hours ago (1 children)

mkcd

mkdir and cd into it.

[–] guynamedzero@sh.itjust.works 2 points 5 hours ago (1 children)

I have a similar one, mkmv, it makes a directory and then moves files into it

[–] beeng@discuss.tchncs.de 2 points 5 hours ago (1 children)

Dir name first and then files?

[–] guynamedzero@sh.itjust.works 2 points 5 hours ago

Yep! It just uses the first argument for mkdir, then all of the following args get put into mv with the first argument again, or something like that, it’s been a few months since I made it

[–] gkaklas@lemmy.zip 4 points 1 day ago* (last edited 1 day ago)

https://gkak.la/shell-aliases

Not an alias, but expanding -h to --help has been very useful in cases where the program just prints "see --help for options" when you just use -h

I use glola from oh-my-zsh every day to see an overview of my projects

Ans ns/nss is very convenient to run one-off commands with software I don't already have installed!

Oh and cdt = cd $(mktemp -d) is nice to have when you just need a temporary clean directory to do something quick

[–] basiclemmon98@lemmy.dbzer0.com 4 points 21 hours ago

alias ser='pacman -Ss'
alias ins='sudo pacman -S'
alias rem='sudo pacman -Rncs'
alias upd='sudo pacman -Syu'

alias q='quit'
alias cl='clear'

alias p='systemctl poweroff'
alias r='systemctl reboot'

[–] Jesus_666@lemmy.world 4 points 1 day ago

It's not terribly exciting but I find myself using this a lot:

#!/bin/sh

echo "$*" | sed -e "s/x/*/g" | bc -l

Just a little shorthand for bc that allows me to write "x" instead of "*" to avoid shell expansion nonsense. I put it in ~/.local/bin/= so I can e.g. just write = 17+4x5. Combined with a Quake-style terminal this is much faster than launching a calculator app. It's a script instead of an alias so it works regardless of the shell I'm currently using.

The call to bc -l could be replaced with one to qalc -t if you know qalc to be present on the system .

[–] A_norny_mousse@feddit.org 3 points 17 hours ago

OP, if you want to watch the video once then scrap it, why not just mpv "$(wl-paste)"

Here's one used daily:

connect '192.168.15.20:23 /nossh /T=1'
timeout=30
wait 'username:'
sendln 'admin'
wait 'password:'
sendln 'hunter2'
wait 'DSPXmini>'
sendln 'set dspx.enum.0 digital_audio'
wait 'digital_audio'
if result=0 goto Error
if result=1 goto Success

:Error
messagebox 'Something went wrong. Please call Xxxxx on xxxxxxxxxx for help.' 'Bugger.'
goto End

:Success
messagebox 'Done :-) Studio B is now ISOLATED from the transmitter. You can now play around in Studio B without affecting what is going to air.' 'Studio B Isolated.'
messagebox 'Please keep your speaker volume low if someone is broacasting from Studio A at the moment. The walls are thin.' 'Thin Wall Reminder...'

:End
disconnect 0

[–] kbal@fedia.io 3 points 1 day ago

#!/bin/bash # Recursively rename everything in the current directory as necessary # to make it match the case of filenames in Skyrim's "Data" directory,

from=`pwd -P`
to="${HOME}/.steam/debian-installation/steamapps/common/Skyrim_1.5.97/Data"
tmp="/tmp/skydata_index"
filez="/tmp/skydata_from"

IFS='
'

match_case() {
    cd "$2"
    find . | grep -v '^[.]$' > "$tmp"
    cd "$1"
    find . -maxdepth 1 | grep -v '^[.]$' > "$filez"
    for j in `cat $filez`; do
        if ( grep -i "^${j}$" $tmp ); then
            name=`grep -i "^${j}$" $tmp | head -1`
            if [ "${name}xx" != "${j}xx" ] ; then
                mv "$j" "$name"
            fi
        fi
    done

    # going recursiv
    find . -maxdepth 1 -type d | grep -v '^[.]$' > "$filez"
    for j in `cat $filez`; do
        if ( test -d "${2}/${j}" ) ; then
            match_case "${1}/${j}" "${2}/${j}"
        fi
    done
}
match_case $from $to
rm $tmp $filez
[–] mcmodknower@programming.dev 2 points 20 hours ago

in my .gitconfig i have

[alias]
	glg = log --oneline --decorate --all --graph

This allows me to get a quick overview over all branches with pushes that are recent enough for most cases.

[–] christopher@programming.dev 2 points 17 hours ago

I am using Music Player Daemon, and I use the following script to turn gPodder into a client. My music is in ~/Music and I put the podcasts in ~/Music/Podcasts. The script works for both streaming or downloaded podcasts.

[~]$ cat bin/mpcut.sh
#!/bin/bash
if [ "$(echo "$1" | cut -b-4)" = "http" ]; then
    /usr/bin/mpc pause
    /usr/bin/mpc insert "$1"
    /usr/bin/mpc toggle
    /usr/bin/notify-send -i gpodder "$1 inserted to next spot in playlist."
else
    /usr/bin/mpc pause
    /usr/bin/mpc add "Podcasts/$(echo "$1" | cut -d"/" -f6-)"
    /usr/bin/mpc toggle
    /usr/bin/notify-send -i gpodder "$(echo "$1" | cut -d"/" -f7-)" "added to end of playlist."
fi

Audio Player in gPodder preferences is set to this: /home/christopher/bin/mpcut.sh %F

I have an application shortcut Super-G set to this in xfce4-keyboard-settings: env GTK_THEME=Adwaita-dark GPODDER_HOME=/home/christopher/.config/gPodder/ GPODDER_DOWNLOAD_DIR=/home/christopher/Music/Podcasts/ /usr/bin/gpodder

or you could use an alias: alias gpodder='GTK_THEME=Adwaita-dark GPODDER_HOME=/home/christopher/.config/gPodder/ GPODDER_DOWNLOAD_DIR=/home/christopher/Music/Podcasts/ /usr/bin/gpodder --verbose'

[–] Object@sh.itjust.works 1 points 1 day ago* (last edited 1 day ago)

($@ > /dev/null 2>&1 &)

Simple bash function that runs something fully detached even if its parent closes, and is not dependent on any software feature such as bash's disown

alias sp='sudo systemctl stop'
alias sr='sudo systemctl restart'
alias ss='sudo systemctl status'
alias sup='systemctl --user stop'
alias sur='systemctl --user restart'
alias sus='systemctl --user status'

Bunch or systemctl related aliases

[–] martijndevrieze@europe.pub 1 points 7 hours ago

Extremely simple, but I still do not get why this is not implemented by default. alias open='xdg-open'

[–] qaz@lemmy.world 1 points 16 hours ago

fmux. Create a tmux session using the fish shell

[–] glitchy@programming.dev 0 points 19 hours ago
alias ban_me_discord_i_dare_you 'sh -c "$(curl -sS https://raw.githubusercontent.com/Vendicated/VencordInstaller/main/install.sh)"'

for when discord pushes a new update