this post was submitted on 23 Jun 2025
147 points (99.3% liked)

Linux

55568 readers
1332 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS
 

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)"
}
(page 2) 50 comments
sorted by: hot top controversial new old
[–] Stubb@lemmy.sdf.org 5 points 17 hours ago
function seesv
    column -s, -t < $argv[1] | less -#2 -N -S
end

I used this a lot when I had to deal with CSV files — it simply shows the data in a nice format. It's an alias for the fish shell by the way.

[–] Bo7a@lemmy.ca 9 points 20 hours ago (2 children)
#Create a dir and cd into it
mkcd() { mkdir -p "$@" && cd "$@"; }
[–] hallettj@leminal.space 3 points 16 hours ago

That's a helpful one! I also add a function that creates a tmp directory, and cds to it which I frequently use to open a scratch space. I use it a lot for unpacking tar files, but for other stuff too.

(These are nushell functions)

# Create a directory, and immediately cd into it.
# The --env flag propagates the PWD environment variable to the caller, which is
# necessary to make the directory change stick.
def --env dir [dirname: string] {
  mkdir $dirname
  cd $dirname
}

# Create a temporary directory, and cd into it.
def --env tmp [
  dirname?: string # the name of the directory - if omitted the directory is named randomly
] {
  if ($dirname != null) {
    dir $"/tmp/($dirname)"
  } else {
    cd (mktemp -d)
  }
}
load more comments (1 replies)
[–] gonzo-rand19@moist.catsweat.com 17 points 23 hours ago

Here are probably the most useful ones. I prefer for rm to be interactive so I don't accidentally delete something important and for mkdir to 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
}
[–] vortexal@lemmy.ml 4 points 17 hours ago (4 children)

I've only used aliases twice so far. The first was to replace yt-dlp with a newer version because the version that comes pre-installed in Linux Mint is too outdated to download videos from YouTube. The second was because I needed something called "Nuget". I don't remember exactly what Nuget is but I think it was a dependency for some application I tried several months ago.

alias yt-dlp='/home/j/yt-dlp/yt-dlp'
alias nuget="mono /usr/local/bin/nuget.exe"
[–] thingsiplay@beehaw.org 2 points 16 hours ago

For the newer version of program, that's why we have the $PATH. You put your program into one of the directories that is in your $PATH variable, then you can access your script or program from any of these like a regular program. Check the directories with echo "$PATH" | tr ':' '\n'

My custom scripts and programs directory is "~/.local/bin", but it has to be in the $PATH variable too. Every program and script i put there can be run like any other program. You don't even need an alias for this specific program in example.

load more comments (3 replies)
[–] harsh3466@lemmy.ml 4 points 18 hours ago* (last edited 15 hours ago) (5 children)
alias gl='git log'
alias server-name-here='ssh server-name-here'

I have a bunch of the server aliases. I use those and gl the most.

[–] torgeir@lemmy.ml 4 points 17 hours ago (1 children)
[–] harsh3466@lemmy.ml 2 points 15 hours ago

Hahaha. Fucking autocorrect. Git log.

load more comments (4 replies)
[–] danielquinn@lemmy.ca 5 points 19 hours ago (2 children)

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.

load more comments (2 replies)
[–] DarkSirrush@lemmy.ca 1 points 15 hours ago* (last edited 15 hours ago)

I have a few:

loginserver
  • 3 of these, 1 for each of my headless vm's/computers that's just an SSH command
dcompose(d/pull) - docker compose (down/pull)

3 scripts that are just docker compose up/down/pull, as scripts (remind me in 6 hours and I will post the scripts) so that it will CD to my compose folder, execute the command (with option for naming specific containers or blank for all) and then CD back to the directory I started in.

[–] qpsLCV5@lemmy.ml 4 points 20 hours ago* (last edited 20 hours ago)

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....

[–] XXIC3CXSTL3Z@lemmy.ml 3 points 19 hours ago

Ooooou I got a couple :3

This one is just a basic mirror fixing thing cuz sometimes I go a while without updating pacman:

alias fixpkg='rate-mirrors --protocol https arch | sudo tee /etc/pacman.d/mirrorlist && sudo pacman -Syy'

This function I made to create virtual audio sinks so I can route audios via qpw and play earrape into discord calls if I want XD

create_vsink() {
    local sink_name=${1:-vsink}  # Default sink name is 'vsink' if no input is provided
    local description=${2:-"Virtual Sink"}  # Default description
    pactl load-module module-null-sink sink_name="$sink_name" sink_properties=device.des>
    echo "Virtual sink '$sink_name' created with description '$description'."
}

Simple parser function I made that makes a whole repo using my git key so it's not just locally created I kinda forgot why I made it tbh:

git_clone() {
    local url="${1#https://}"  # Remove "https://" if present
    git clone "https://$git_key@$url"
}

Awesome mpv function I made that allows for real time pitch+speed shifting via hotkeys and is flexible with extra parameters and shit:

mpv_pitch() {
    if [[ -z "$1" ]]; then
        echo "Usage: mpv_pitch <file> [mpv-options]"
        return 1
    fi
    local file="$1"
    shift
    mpv --input-conf=/dev/stdin "$file" "$@" <<EOF
SHIFT+RIGHT add audio-pitch-correction 0; add pitch 0.01; add speed 0.01  # Decrease pit>
SHIFT+LEFT add audio-pitch-correction 0; add pitch -0.01; add speed -0.01 # Increase pit>
EOF
}

Automatic audio router for firefox audio streams that uses the aforementioned create_sink function to make a specific sink that I can use carla on to mix and make cool shit out of haha

firefox_crush() {
    create_vsink CrunchSink "CrunchSink" 
    firefox --name firefox-vc &

    (while true; do
        SINK_INPUT_ID=$(pactl list sink-inputs short | grep "firefox" | awk '{print $1}')
        if [[ -n "$SINK_INPUT_ID" ]]; then
            pactl move-sink-input "$SINK_INPUT_ID" CrunchSink
            break
        fi
        sleep 0.25
    done) &
}
[–] mina86@lemmy.wtf 7 points 1 day ago

For doing stuff in a directory, I use a replacement for cd command.

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:

  • a for package management (think apt but has simplified arguments which makes it faster to use in usual cases),
  • e for opening file in Emacs,
  • g for git,
  • s for sudo.

And here’s ,:

$ cat ~/.local/bin/,
#!/bin/sh

if [ $# -eq 0 ]; then
	paste -sd,
else
	printf '%s\n' "$@" | paste -sd,
fi
[–] odc@lemmy.sdf.org 4 points 22 hours ago (1 children)

I'll share 3:

alias chx='chmod +x'
alias rr='rm -rf'
alias shrug="echo '¯\_(ツ)_/¯'"
[–] thingsiplay@beehaw.org 1 points 22 hours ago

i also have the chmod one, but mine is named just x:

alias x='chmod +x'

I also have the yt-dlp "$(wl-paste)" one, but its build around a custom script. So sharing it here makes no sense. Its funny how often we do same thing in different ways (extracting or creating archives in example). Often aliases get development into function and then they turn into scripts. For some of the more simple aliases, here a selection:

alias f='fastfetch -l none'
alias vim='nvim'
alias baloo='balooctl6'
[–] utopiah@lemmy.ml 3 points 21 hours ago* (last edited 21 hours ago) (1 children)

To answer your question realistically I did history | sed "s/.* //" | sort | uniq -c | sort -n

which returned as first non standard command lr which from my grep lr ~/.bashrc is alias lr="ls -lrth"

[–] thingsiplay@beehaw.org 3 points 21 hours ago (1 children)

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) | sort
[–] utopiah@lemmy.ml 2 points 20 hours ago

Thanks for sharing, always nice to learn alternative ways to do so!

[–] balsoft@lemmy.ml 2 points 20 hours ago

I've stolen a bunch of Git aliases from somewhere (I don't remember where), here are the ones I ended up using the most:

g=git
ga='git add'
gau='git add --update'
gcfu='git commit --fixup'
gc='git commit --verbose'
'gc!'='git commit --verbose --amend'
gcmsg='git commit --message'
gca='git com
gd='git diff'
gf='git fetch'
gl='git pull'
gst='git status'
gstall='git stash --all'
gstaa='git stash apply'
gp='git push'
'gpf!'='git push --force-with-lease'
grb='git rebase'
grba='git rebase --abort'
grbc='git rebase --continue'

I also often use

ls='eza'
md='mkdir -p'
mcd() { mkdir -p "$1" && cd "$1" }

And finally some Nix things:

b='nix build'
bf='nix build -f'
bb=nix build -f .'
s='nix shell'
sf='nix shell -f'
snp='nix shell np#'
d='nix develop'
df='nix develop -f'
[–] Ritsu4Life@lemmy.world 2 points 20 hours ago (1 children)

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
fi

[–] XXIC3CXSTL3Z@lemmy.ml 2 points 19 hours ago (1 children)
[–] Ritsu4Life@lemmy.world 2 points 15 hours ago (1 children)
[–] XXIC3CXSTL3Z@lemmy.ml 2 points 15 hours ago

Best waifu of history <3

[–] INeedMana@lemmy.world 6 points 1 day ago
$ 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"
fi
[–] monovergent@lemmy.ml 2 points 20 hours ago

My desktop text editor has an autosave feature, but it only works after you've manually saved the file. All I wanted is something like the notes app on my phone, where I can jot down random thoughts without worrying about naming a new file. So here's the script behind my text editor shortcut, which creates a new text file in ~/.drafts, names it with the current date, adds a suffix if the file already exists, and finally opens the editor:

#!/bin/bash

name=/home/defacto/.drafts/"`date +"%Y%m%d"`"_text
if [[ -e "$name" || -L "$name" ]] ; then
    i=1
    while [[ -e "$name"_$i || -L "$name"_$i ]] ; do
        let i++
    done
    name="$name"_$i
fi
touch -- "$name"
pluma "$name" #replace pluma with your editor of choice
[–] Sneptaur@pawb.social 5 points 1 day ago (3 children)

I 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 sudo to run this on Ubuntu, but not in the Arch example because paru being neat

[–] thingsiplay@beehaw.org 3 points 22 hours ago

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'
[–] GideonBear@lemmy.ml 2 points 23 hours ago (2 children)
[–] MyNameIsRichard@lemmy.ml 5 points 22 hours ago (1 children)

Why install another bit of software when a simple alias will do the job nicely?

[–] CrabAndBroom@lemmy.ml 1 points 19 hours ago (1 children)

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.

load more comments (1 replies)
[–] CrabAndBroom@lemmy.ml 1 points 19 hours ago

I use Topgrade, but I use the alias update to run it lol

[–] TechnoCat@lemmy.ml 1 points 20 hours ago
[–] KR1Z2k@lemm.ee 3 points 1 day ago

For 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"
[–] Nugscree@lemmy.world 1 points 20 hours ago* (last edited 20 hours ago)

Because using docker can sometimes cause ownership issues if not properly configured in your docker-compose.yml, I just added an alias to ~/.zshrc to rectify that.

-edit- Only run this script in your user owned directories, e.g. anything from ~/ (or /home/<your_username>) you might otherwise cause ownership issues for your system.

## Set ownership of files/folders recursively to current user
alias iownyou="sudo chown -R $USER:$GROUP"
[–] meekah@lemmy.world 1 points 20 hours ago (1 children)

Ooooh tmpv is a smart name for your little tool. I may steal it lol

[–] als@lemmy.blahaj.zone 2 points 15 hours ago
[–] WQMan@lemmy.ml 1 points 21 hours ago (2 children)

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 | clippy
[–] thingsiplay@beehaw.org 5 points 21 hours ago (1 children)

Little tip: In case you need to use rm directly, even with the alias in effect, you can put a backslah in front of the command to use its original meaning: \rm filename

[–] XXIC3CXSTL3Z@lemmy.ml 1 points 19 hours ago (1 children)

oooh so does that apply to any command/user binary on the system?

[–] thingsiplay@beehaw.org 2 points 19 hours ago* (last edited 18 hours ago) (1 children)

I'm not sure what you mean with the question. If you have any alias like alias rm='ls -l' in your .bashrc in example, then you cannot use the original command rm anymore, 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 \rm in the terminal, then the alias for it is ignored and the original command is executed instead.

Edit: Made a more clear alias example.

[–] XXIC3CXSTL3Z@lemmy.ml 2 points 18 hours ago* (last edited 18 hours ago)

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

[–] IsoKiero@sopuli.xyz 3 points 20 hours ago

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.

load more comments
view more: ‹ prev next ›