this post was submitted on 23 Jun 2025
201 points (99.0% liked)

Linux

55678 readers
633 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
[–] phantomwise@lemmy.ml 2 points 3 days ago

alias nmtui="NEWT_COLORS='root=black,black;window=black,black;border=white,black;listbox=white,black;label=blue,black;checkbox=red,black;title=green,black;button=white,red;actsellistbox=white,red;actlistbox=white,gray;compactbutton=white,gray;actcheckbox=white,blue;entry=lightgray,black;textbox=blue,black' nmtui"

It's nmtui but pretty!

[–] twice_hatch@midwest.social 2 points 3 days ago

alias scr=screen -dRU

I don't know why Screen has any other flags. I do not want to bother learning the keyboard shortcuts for tmux even though its probably works better

[–] MTK@lemmy.world 2 points 3 days ago (1 children)
load more comments (1 replies)
[–] kittenroar@beehaw.org 5 points 3 days ago

here we go:

dedup:

#!/usr/bin/awk -f
!x[$0]++

this removes duplicate lines, preserving line order

iter:

#!/usr/bin/bash
if [[ "${@}" =~ /$ ]]; then
    xargs -rd '\n' -I {} "${@}"{}
else
    xargs -rd '\n' -I {} "${@}" {}
fi

This executes a command for each line. It can also be used to compare two directories, ie:

du -sh * > sizes; ls | iter du -sh ../kittens/ > sizes2

fadeout:

#!/bin/bash
# I use this to fade out layered brown noise that I play at a volume of 130%
# This takes about 2 minutes to run, and the volume is at zero several seconds before it's done.
# ################
# DBUS_SESSION_BUS_ADDRESS is needed so that playerctl can find the dbus to use MPRIS so it can control mpv
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
# ################
for i in {130..0}
do
    volume=$(echo "scale=3;$i/100" | bc)
    sleep 2.3
    playerctl --player=mpv volume $volume
done

lbn:

#!/bin/bash
#lbn_pid=$(cat ~/.local/state/lbn.pid)
if pgrep -fl layered_brown
then
	pkill -f layered_brown
else
	export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
	mpv -ao pulse ~/layered_brown_noise.mp3 >>lbn.log 2>&1 &
	sleep 3
	playerctl -p mpv volume 1.3 >>lbn.log 2>&1 &
fi

This plays "layered brown noise" by crysknife. It's a great sleep aid.

here are some aliases:

alias m='mpc random off; mpc clear'
alias mpcc='ncmpcpp'
alias thesaurus='dict -d moby-thesaurus'
alias wtf='dict -d vera'
alias tvplayer='mpv -fs --geometry=768x1366+1366+0'
[–] arcayne@lemmy.today 3 points 3 days ago

Well, my full functions.sh won't fit in a comment, so here's 2 of my more unique functions that makes life a little easier when contributing to busy OSS projects:

# Git fork sync functions
# Assumes standard convention: origin = your fork, upstream = original repo
## Sync fork with upstream before starting work
gss() {
        # Safety checks
        if ! git rev-parse --git-dir >/dev/null 2>&1; then
                echo "❌ Not in a git repository"
                return 1
        fi

        # Check if we're in a git operation state
        local git_dir=$(git rev-parse --git-dir)
        if [[ -f "$git_dir/rebase-merge/interactive" ]] || [[ -d "$git_dir/rebase-apply" ]] || [[ -f "$git_dir/MERGE_HEAD" ]]; then
                echo "❌ Git operation in progress. Complete or abort current rebase/merge first:"
                echo "   git rebase --continue  (after resolving conflicts)"
                echo "   git rebase --abort     (to cancel rebase)"
                echo "   git merge --abort      (to cancel merge)"
                return 1
        fi

        # Check for uncommitted changes
        if ! git diff-index --quiet HEAD -- 2>/dev/null; then
                echo "❌ You have uncommitted changes. Commit or stash them first:"
                git status --porcelain
                echo ""
                echo "💡 Quick fix: git add . && git commit -m 'WIP' or git stash"
                return 1
        fi

        # Check for required remotes
        if ! git remote get-url upstream >/dev/null 2>&1; then
                echo "❌ No 'upstream' remote found. Add it first:"
                echo "   git remote add upstream <upstream-repo-url>"
                return 1
        fi

        if ! git remote get-url origin >/dev/null 2>&1; then
                echo "❌ No 'origin' remote found. Add it first:"
                echo "   git remote add origin <your-fork-url>"
                return 1
        fi

        local current_branch=$(git branch --show-current)

        # Ensure we have a main branch locally
        if ! git show-ref --verify --quiet refs/heads/main; then
                echo "❌ No local 'main' branch found. Create it first:"
                echo "   git checkout -b main upstream/main"
                return 1
        fi

        echo "🔄 Syncing fork with upstream..."
        echo "   Current branch: $current_branch"

        # Fetch with error handling
        if ! git fetch upstream; then
                echo "❌ Failed to fetch from upstream. Check network connection and remote URL."
                return 1
        fi

        echo "📌 Updating local main..."
        if ! git checkout main; then
                echo "❌ Failed to checkout main branch"
                return 1
        fi

        if ! git reset --hard upstream/main; then
                echo "❌ Failed to reset main to upstream/main"
                return 1
        fi

        echo "⬆️  Pushing updated main to fork..."
        if ! git push origin main; then
                echo "❌ Failed to push main to origin. Check push permissions."
                return 1
        fi

        echo "🔀 Rebasing feature branch on updated main..."
        if ! git checkout "$current_branch"; then
                echo "❌ Failed to checkout $current_branch"
                return 1
        fi

        if ! git rebase main; then
                echo "❌ Rebase failed due to conflicts. Resolve them and continue:"
                echo "   1. Edit conflicted files"
                echo "   2. git add <resolved-files>"
                echo "   3. git rebase --continue"
                echo "   Or: git rebase --abort to cancel"
                return 1
        fi

        echo "✅ Ready to work on branch: $current_branch"
}

## Sync fork and push feature branch
gsp() {
        # Safety checks
        if ! git rev-parse --git-dir >/dev/null 2>&1; then
                echo "❌ Not in a git repository"
                return 1
        fi

        local git_dir=$(git rev-parse --git-dir)
        if [[ -f "$git_dir/rebase-merge/interactive" ]] || [[ -d "$git_dir/rebase-apply" ]] || [[ -f "$git_dir/MERGE_HEAD" ]]; then
                echo "❌ Git operation in progress. Complete or abort first."
                return 1
        fi

        if ! git diff-index --quiet HEAD -- 2>/dev/null; then
                echo "❌ You have uncommitted changes. Commit or stash them first:"
                git status --porcelain
                return 1
        fi

        if ! git remote get-url upstream >/dev/null 2>&1; then
                echo "❌ No 'upstream' remote found"
                return 1
        fi

        if ! git remote get-url origin >/dev/null 2>&1; then
                echo "❌ No 'origin' remote found"
                return 1
        fi

        local current_branch=$(git branch --show-current)

        # Prevent pushing from main
        if [[ "$current_branch" == "main" ]]; then
                echo "❌ Cannot push from main branch. Switch to your feature branch first:"
                echo "   git checkout <your-feature-branch>"
                return 1
        fi

        # Show what we're about to do
        echo "⚠️  About to sync and push branch: $current_branch"
        echo "   This will:"
        echo "   • Fetch latest changes from upstream"
        echo "   • Rebase your branch on updated main"
        echo "   • Force-push to your fork (updates PR)"
        echo ""

        read -p "Continue? [y/N]: " -n 1 -r
        echo

        if [[ ! $REPLY =~ ^[Yy]$ ]]; then
                echo "❌ Operation cancelled"
                return 0
        fi

        echo "🔄 Final sync with upstream..."
        if ! git fetch upstream; then
                echo "❌ Failed to fetch from upstream"
                return 1
        fi

        echo "📌 Updating local main..."
        if ! git checkout main; then
                echo "❌ Failed to checkout main"
                return 1
        fi

        if ! git reset --hard upstream/main; then
                echo "❌ Failed to reset main"
                return 1
        fi

        if ! git push origin main; then
                echo "❌ Failed to push main to origin"
                return 1
        fi

        echo "🔀 Rebasing feature branch..."
        if ! git checkout "$current_branch"; then
                echo "❌ Failed to checkout $current_branch"
                return 1
        fi

        if ! git rebase main; then
                echo "❌ Rebase failed. Resolve conflicts and try again:"
                echo "   git add <resolved-files> && git rebase --continue"
                echo "   Then run 'gsp' again"
                return 1
        fi

        echo "🚀 Pushing feature branch to fork..."
        if ! git push origin "$current_branch" --force-with-lease; then
                echo "❌ Failed to push to origin. The branch may have been updated."
                echo "   Run 'git pull origin $current_branch' and try again"
                return 1
        fi

        echo "✅ Feature branch $current_branch successfully pushed to fork"
}
[–] SuperiorOne@lemmy.ml 4 points 3 days ago

jmpd(jump directory): fuzzy finds and opens directory with fzf

# fish shell
function jmpd
    set _selection $(fzf --walker=dir);
    if test -n "$_selection"
        cd "$_selection";
    end
end
[–] Stubb@lemmy.sdf.org 6 points 3 days 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.

[–] MangoCats@feddit.it 4 points 3 days ago (1 children)

I have a collection of about 8 machines around the house (a lot of Raspberry Pi) that I ssh around to from various points.

I have setup scripts named: ssp1 ssp2 ssba ss2p etc. to ssh into the various machines, and of course shared public ssh keys among them to skip the password prompt. So, yes, once you are "in" one machine in my network, if you know this, you are "in" all of them, but... it's bloody convenient.

load more comments (1 replies)
[–] Flyswat@lemmy.dbzer0.com 2 points 3 days ago

To save videos from certain streaming sites that are not supported by yt-dlp, I catch the M3U playlist used by the page and with that I use this script that gets ffmpeg to put together the pieces into a single file.

#!/bin/bash
if [ "$1" == "-h" ] || [ $# -lt 2 ]; then
	echo Download a video from a playlist into a single file
	echo usage: $(basename $0) PLAYLIST OUTPUT_VID
	exit
fi

nbparts=$(grep ^[^#] $1 | wc -l)

echo -e "\e[38;5;202m Downloading" $(( nbparts - 1 )) "parts \e[00m"
time ffmpeg -hide_banner -allowed_extensions ALL -protocol_whitelist file,http,https,tcp,tls,crypto -i $1 -codec copy $2
[–] tho@lemmy.ml 1 points 2 days ago (2 children)
git() {
  if [ "$1" = clone ]; then
    shift
    set -- clone --recursive "$@"
  fi
  command git "$@"
}
load more comments (2 replies)
[–] stringere@sh.itjust.works 1 points 2 days ago

Currently using this to resize screenshots in a Word doc

#Requires AutoHotkey v2.0

^+1:: { Send "{RButton}z{Tab 3}4{Enter}" }

[–] mina86@lemmy.wtf 8 points 4 days 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
[–] brax@sh.itjust.works 1 points 2 days ago

I don't have anything too fancy. I use [theFuck(https://github.com/nvbn/thefuck) to handle typos, and I have some variables set to common directories that I use.

[–] vortexal@lemmy.ml 5 points 3 days ago (2 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"
[–] vithigar@lemmy.ca 5 points 3 days ago (1 children)

Nuget is a the .NET package manager. Like npm or pip, but for .NET projects.

If you needed it for a published application that strikes me as fairly strange.

[–] vortexal@lemmy.ml 4 points 3 days ago* (last edited 3 days ago) (1 children)

I looked through my bash history and it looks like I needed it to build an Xbox eeprom editor for Xemu. Xemu doesn't (or at least didn't, I haven't used newer versions yet) have a built in eeprom editor and editing the Xbox eeprom is required for enabling both wide screen and higher resolutions for the games that support them natively.

I just looked at Xemu's documentation, and it looks like they've added a link to an online eeprom editor, so the editor I used (which they do still link to) is no longer required.

load more comments (1 replies)
load more comments (1 replies)
[–] livingcoder@programming.dev 1 points 2 days ago* (last edited 2 days ago)
# grep search the current directory
function lg() {
  ls -alt | grep $1
}
[–] harsh3466@lemmy.ml 5 points 4 days ago* (last edited 3 days ago) (2 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.

[–] jwt@programming.dev 3 points 3 days ago (1 children)

You can also use ssh shorthands in ~/.ssh/config

[–] harsh3466@lemmy.ml 3 points 3 days ago (2 children)

I do have the servers in ~/.ssh/config. I just got tired of typing ssh server and wanted the be able to just type server to ssh in.

load more comments (2 replies)
[–] torgeir@lemmy.ml 4 points 3 days ago (1 children)
load more comments (1 replies)
[–] spv@lemmy.spv.sh 4 points 3 days ago
alias bat="batcat"
alias msc="ncmpcpp"
alias xcp="xclip -selection clipboard"
alias wgq="sudo wg-quick"

also a couple to easily power on/off my 4g modem

[–] danielquinn@lemmy.ca 5 points 4 days 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)
[–] data1701d@startrek.website 3 points 3 days ago (4 children)

I use Clevis to auto-unlock my encrypted root partition with my TPM; this means when my boot partition is updated (E.G a kernel update), I have to update the PCR register values in my TPM. I do it with my little script /usr/bin/update_pcr:

#!/bin/bash
clevis luks regen -d /dev/nvme1n1p3 -s 1 tpm2

I run it with sudo and this handles it for me. The only issue is I can't regenerate the binding immediately after the update; I have to reboot, manually enter my password to decrypt the drive, and then do it.

Now, if I were really fancy and could get it to correctly update the TPM binding immediately after the update, I would have something like an apt package shim with a hook that does it seamlessly. Honestly, I'm surprised that distributions haven't developed robust support for this; the technology is clearly available (I'm using it), but no one seems to have made a user-friendly way for the common user to have TPM encryption in the installer.

load more comments (4 replies)
[–] some_guy@lemmy.sdf.org 3 points 3 days ago* (last edited 3 days ago)

On MacOS, to open the current directory in Finder: alias f='open -a Finder .'

[–] INeedMana@lemmy.world 6 points 4 days 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
[–] JTskulk@lemmy.world 3 points 3 days ago (2 children)

Hey OP, consider using $XDG_RUNTIME_DIR instead of /tmp. It's now the more proper place for these kinds of things to avoid permission issues, although I'm sure you're on a single user system like most people. I have clipboard actions set to download with yt-dlp :)

My favorite aliases are:

alias dff='findmnt -D -t nosquashfs,notmpfs,nodevtmpfs,nofuse.portal,nocifs,nofuse.kio-fuse'

alias lt='ls -t | less'

load more comments (2 replies)
[–] jcs@lemmy.world 2 points 3 days ago

I wrote this suite of scripts a few years ago and still use them to:

  1. Boot into Ventoy and select a Debian Live environment
  2. Optional: connect a storage device (local partition, USB drive, etc) for persistent storage
  3. Modify cfg/cfg.sh if it's the first time using the tool
  4. Run setup.sh to configure the environment into a familiar/productive state

The tools are flexible on hardware (more directed toward x64 systems at this time), and I (almost) never have to worry about OS upgrades. Just boot into a newer live OS image once it's ready. They are still a work-in-progress and still have a few customizations that I should abstract for more general use, but it's FOSS in case anyone has merge requests, issues, suggestions, etc.

[–] thingsiplay@beehaw.org 3 points 3 days ago

Here is on that I actually don't use, but want to use it in scripts. It is meant to be used by piping it. It's simple branch with user interaction. I don't even know if there is a standard program doing exactly that already.

# usage: yesno [prompt]
# example:
#   yesno && echo yes
#   yesno Continue? && echo yes || echo no
yesno() {
    local prompt
    local answer
    if [[ "${#}" -gt 0 ]]; then
        prompt="${*} "
    fi
    read -rp "${prompt}[y/n]: " answer
    case "${answer}" in
    [Yy0]*) return 0 ;;
    [Nn1]*) return 1 ;;
    *) return 2 ;;
    esac
}
[–] irotsoma@lemmy.blahaj.zone 2 points 3 days ago (1 children)

I alias traditional stuff to better, usually drop-in versions of that thing on computers that have the better thing. I often forget which systems have the better thing, so this helps me get the better experience if I was able to install it at some point. For example I alias cat to bat, or top to htop, or dig to drill, etc.

load more comments (1 replies)
load more comments
view more: ‹ prev next ›