40
submitted 2 days ago by thingsiplay@lemmy.ml to c/linux@lemmy.ml

It can't hurt to share some of you current helpers. Either someone else might get inspired by or in some cases you get suggestions how to make it better. Bash, Zsh, Fish or whatever shell script, command or alias (or abbreviation) you have, share here. Always fun to do so! I share mine in the comments, just like everybody else.

top 27 comments
sorted by: hot top new old
[-] kai_ekael@lemmy.today 1 points 23 minutes ago

I forget whom to blame for getting stuck with these. I want to say Slackware...in 1994.

alias d='ls -aF --color=auto'
alias v='d -l'

And of course the ones I always recommend heartily:

alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[-] mactan@lemmy.ml 3 points 19 hours ago

alias ls sl

[-] Kajika@lemmy.ml 5 points 23 hours ago* (last edited 23 hours ago)

From most useful to very specific

alias ..="cd .."

# Hunt for space (show folder sizes, sorted)
alias duc="du -hxd1 | sort -h"

# Remove unnecessary archlinux packages (simple but has to be run as long as some remains because it is not recursive)
alias arch-prune="sudo pacman -Qdtq | sudo pacman -Rn -"

# Just because I can tab-complete commands so it is slightly faster/easier to type
alias arch-update="sudo pacman -Syu"
alias arch-clean="sudo pacman -Scc"

# Check for errors in logs for the current boot (nice to check from time to time, trying to clean up invisible bloat)
alias journal-errors="sudo journalctl -b -p err..alert"

# Start/stop CPU boost (huge power/temperature difference, boost is mostly not needed, those kind of commands are always CPU specific sadly)
alias disable-boost="sudo sh -c \"echo 0 >> /sys/devices/system/cpu/cpufreq/boost\""
alias enable-boost="sudo sh -c \"echo 1 >> /sys/devices/system/cpu/cpufreq/boost\""

# Unmount all mounted tmpfs used when I code (hence the /data/work) as I don't like compiling/bundling stuff on my SSD (avoid unnecessary read/write, RAM is better suited)
alias unmount-worktmpfs="df -lt tmpfs --output=target | tail -n +2 | grep --color=never \"/data/work\" | xargs sudo umount"
[-] thingsiplay@lemmy.ml 3 points 17 hours ago

Showing the biggest directories is indeed useful. I took this simple idea and made it complicated: https://github.com/thingsiplay/biggest which also works for files. It's useful to find the biggest directories or files matching a certain glob pattern. And works on stdin too (in example find ~/Music/Songs/Film/ -iname "*Mario*" | biggest)

I'm stealing your journal command. Really need to lookup more instead guessing around.

[-] n0p1lls@piefed.zip 3 points 1 day ago

Here are some of my aliases:

alias rg='rgrep'  
alias fdf='fdfind'  
alias viman='/usr/bin/vim +"call library#manual_argv()"'  
alias matrix-msg='element-desktop --password-store="gnome-libsecret"'  
alias run-nvidia-graphics='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia'  

I use Debian BTW

[-] GaumBeist@lemmy.ml 4 points 23 hours ago

Would you please explain that vim one?

[-] n0p1lls@piefed.zip 3 points 22 hours ago* (last edited 22 hours ago)

It's for manual pages. You can navigate them as if you were in vim. IIRC, you should add this line to your vimrc and it should work:

runtime! ftplugin/man.vim

Plus, you need to pass a command as an arg to 'viman'. Example: viman ls

Edit: Sorry, I forgot an important detail. I also have a file in my autoload vim folder with this code:

fun! library#manual_argv ()
        let argv = argv()
        let arguments = join(argv, ' ')
        exe 'Man' arguments
        only
endfun

I think I got the idea from someone on Github, or maybe Distrotube (the youtuber).

[-] DrunkAnRoot@sh.itjust.works 3 points 1 day ago

Alias compose='docker compose'

[-] non_burglar@lemmy.world 3 points 1 day ago

Aliases are great.... On your own machine. Working with Solaris and hpux forced me to use vi and whatever shell is default, so I just use what's there.

[-] tenebrisnox@feddit.uk 4 points 1 day ago

What a fabulous thread! I've learned SO much from reading the comments. Thank you for sharing.

[-] WillieShen@lemmy.world 3 points 1 day ago* (last edited 1 day ago)

https://github.com/Willie169/bashrc My bashrc, with tons of exports, functions and aliases including multimedia processing, (de)compression, shorthands, proot, etc.

wc -c:
   4280 bashrc.d/10-shared-exports.sh
  76690 bashrc.d/30-shared-functions.sh
   9547 bashrc.d/31-amd-functions.sh
   4891 bashrc.d/31-proot-functions.sh
   8977 bashrc.d/31-termux-functions.sh
  11607 bashrc.d/32-termux-extra.py
  69882 bashrc.d/32-termux-extra.sh
   6523 bashrc.d/41-amd-aliases.sh
   7520 bashrc.d/41-proot-aliases.sh
   3062 bashrc.d/50-interactive.sh
   1685 bashrc.d/60-external.sh
    349 bashrc.d/bashrc
[-] Ordoviz@lemmy.ml 18 points 2 days ago

These are my favorite Bash functions:

#!/bin/bash

alias ..="cd .."

r() {
    # cd to git root
    cd "$(git rev-parse --show-toplevel 2>/dev/null)"
}

mkcd() { 
    mkdir -p "$1" && cd "$1"
}

pwc() {
    # copy $PWD into Wayland clipboard with shell quoting
    printf '%q' "$PWD" | wl-copy
}

tmpdiff() {
    old="$(wl-paste)"
    read -n1 -srp "Copy new content into your clipboard, then press any key to diff it"
    diff <(echo "$old") <(wl-paste)
}

m() {
    # Opens man page and searches for an option.
    # Example: m cat -v
    MANPAGER="less -p '^\s+(?-i)$2'" man "$1"
}

grep_browser() {
    # Search file contents with ripgrep, then narrow it down using fzf with bat preview
    filename=$(rg --smart-case \
            --line-number \
            --with-filename \
            --color=always \
            --field-match-separator $'\u00a0' \
            -- "$@" |
        fzf --delimiter $'\u00a0' \
            --ansi \
            --preview "bat --color=always {1} --highlight-line {2}" \
            --preview-window 'up,~8,+{2}-5' |
        rg --only-matching '(.+)\u00a0(\d+)' --replace '$1:$2' --color=never)

    [ -n "$filename" ] && "$VISUAL" "$filename"
}
[-] thingsiplay@lemmy.ml 7 points 2 days ago

There is a bit to unpack here. I particularly like the m() function here, to search for specific options in a man page. The grep_browser() is quiet involved and need to test it out myself. Meanwhile here is an "old" function of mine related to man pages, just searching all available pages, not their content:

woman

#!/bin/env bash

# Lookup section meaning in `man man`.
sections='1,8,6,5,7'

show_manual () {
    man -- "${1%% *}" 2> /dev/null
}
export -f show_manual

if selection=$(man -k . --sections="${sections}" \
               | sort -t ' ' -k 2,2 -k 1,1 \
               | fzf -q "${*}" \
                     --cycle \
                     --border=none \
                     --bind change:first \
                     --bind tab:down \
                     --bind shift-tab:up \
                     --bind esc:cancel+clear-selection \
                     --tiebreak=begin,chunk,length \
                     --reverse \
                     --preview='show_manual {}' \
                     --preview-window=down:70%:wrap:border-rounded)
then
    show_manual "${selection}"
fi
[-] HouseWolf@pawb.social 11 points 2 days ago

Aliases are great if you don't want to break a habit after years.

alias yay='paru'

[-] thingsiplay@lemmy.ml 13 points 2 days ago

I stopped using search tools with file indexing, and needed an alternative. The classic find command does a decent job and it has lot of options. But the regular usage is always a little bit awkward to me. So an alias is needed. However I like the abbreviations from Fish more, and installed zsh-abbr for Zsh for two reasons: a) I can edit the line before executing the abbr command, unlike with aliases or scripts, as it expands on typing, b) I can specify where the cursor lands after expansion.

abbr "search"="find . -type d,f,l -iname '*#*'"

The # symbol is where the cursor lands and is used as search term. This command will simply search the current working directory. search expands to find . -type d,f,l -iname '**' .

The zsh-abbr plugin: https://zsh-abbr.olets.dev/ and my settings for it:

# zsh-abbr settings
export ABBR_SET_EXPANSION_CURSOR=1
export ABBR_EXPANSION_CURSOR_MARKER='#'
export ABBR_EXPERIMENTAL_COMMAND_POSITION_REGULAR_ABBREVIATIONS=2

Thanks fot the # "trick", I've totally missed it

[-] thingsiplay@lemmy.ml 3 points 1 day ago

Your welcome. Note that the # is my personal configuration. The default character for this is different. This functionality is disabled by default too. So make sure to set the options.

Thank you! So kind of you to point this out ❤️

[-] eldavi@lemmy.ml 4 points 1 day ago* (last edited 1 day ago)

i use these 2 several times a day to back and forth between my work and personal laptop/workstation. (i can't get the formatting right here on lemmy):

start_inputleap_tunnel() {
    mkdir -p ~/.inputleap
 
    AUTOSSH_GATETIME=0 nohup autossh -M 0 -N -R 24800:127.0.0.1:24800 \
    -o TCPKeepAlive=yes \
    -o ServerAliveInterval=15 \
    -o ServerAliveCountMax=3 \
    -o ExitOnForwardFailure=yes \
    -o Compression=no \
    -o IPQoS=throughput \
    moi@azulita.local > ~/.inputleap/autossh.log 2>&1 &
    disown
 
    nohup sh -c 'while true; do pkill -x input-leaps; /Applications/InputLeap.app/Contents/MacOS/input-leaps -f --config ~/.inputleap/synergy.conf --debug INFO --disable-crypto --name TS-eas-davcasta --address 127.0.0.1 >> ~/.inputleap/inputleaps.log 2>&1; sleep 2; done' >/dev/null 2>&1 &
    disown
}
 
start_inputleap_tunnel_reverse() {
    mkdir -p ~/.inputleap
 
    # 1. Start AutoSSH (AUTOSSH_GATETIME=0 prevents backoff delays on quick restarts)
    AUTOSSH_GATETIME=0 nohup autossh -M 0 -N -R 24800:127.0.0.1:24800 \
    -o TCPKeepAlive=yes \
    -o ServerAliveInterval=15 \
    -o ServerAliveCountMax=3 \
    -o ExitOnForwardFailure=yes \
    -o Compression=no \
    -o IPQoS=throughput \
    moi@azulita.local > ~/.inputleap/autossh.log 2>&1 &
    disown
 
    # 2. Start InputLeap server loop
    nohup sh -c 'while true; do pkill -x input-leaps; /Applications/InputLeap.app/Contents/MacOS/input-leaps -f --config ~/.inputleap/reverse-synergy.conf --debug INFO --disable-crypto --name TS-eas-davcasta --address 127.0.0.1 >> ~/.inputleap/inputleaps.log 2>&1; sleep 2; done' >/dev/null 2>&1 &
    disown
}

alias startleap=start_inputleap_tunnel
alias startleapreverse=start_inputleap_tunnel_reverse
[-] pjusk@lemmy.dbzer0.com 4 points 1 day ago

Woukd you mind elaborating on these functions?

[-] eldavi@lemmy.ml 2 points 22 hours ago

they wrap autossh and input-leap around nohup for both and a while loop for the latter so that it'll auto restart if it crashes -- i don't know what else doesn't instantly explain itself, but wouldn't mind clarifying further if needed.

[-] thingsiplay@lemmy.ml 4 points 1 day ago* (last edited 1 day ago)

Interesting. I can't comment much about the commands itself, but want to quickly explain how to format. To start a code block, put 3 ticks in row like ``` in one line. Everything after is a code block until 3 ticks end it. You can also set what type of (programming) language it is, for the coloring. Just add bash after the 3 ticks in the opening block like ```bash . That's all to it. I don't know hat languages are supported, but it works for Bash and Python in example. A full code block would be typed like this:

```bash
hello() {
    echo "Hello World!"
}
```

which is then rendered as

hello() {
    echo "Hello World!"
}
[-] eldavi@lemmy.ml 3 points 1 day ago

the ticks work and now you can see my badly formatted bash in all of it's ugly glory. lol

thanks.

[-] mlfh@lm.mlfh.org 7 points 2 days ago

Running set -o vi or adding it to your bashrc gives your shell vi key bindings, which is one of my favorites.

A good writeup: https://dev.to/brandonwallace/how-to-use-vim-mode-on-the-command-line-in-bash-fnn

[-] thingsiplay@lemmy.ml 4 points 2 days ago

I used to use Vi mode of Bash. But on Zsh I use an extension that goes beyond these bindings: https://github.com/jeffreytse/zsh-vi-mode

[-] skunk@lemmy.zip 5 points 2 days ago

This is probably know to most but I found out in the most hilarious way that Ctrl-R in bash lets you search through past commands.

Someone was complaining about Ctrl-S not working in term-mode on emacs and Ctrl-R behaving weird in term-mode in emacs. So I looked at it myself and indeed it does! Well term-mode can be set in char-mode (every key-stroke except C-c is sent to the terminal immediately) vs line-mode (input is sent to the terminal only after hitting Enter, allowing for emacsy input editing before submission). Now in line-mode C-s and C-r work as they do in emacs, but then it hit me that the "weird" C-r search in char-mode must therefore be part of bash and sure enough it does the exact same thing in gnome-terminal as well lol.

[-] thingsiplay@lemmy.ml 5 points 2 days ago* (last edited 2 days ago)

I always forget about Ctrl-r and redescover it accidentally every time I press the key combo. I seem to like this combo a lot for some reason (Edit: maybe that's because of my habits from using too much Vim, where Ctrl-r is used to redo something I undo). After typing a word you search for, pressing Ctrl-r will search for next occurrence BTW (at least in my setup).

this post was submitted on 02 Dec 2026
40 points (97.6% liked)

Linux

69006 readers
747 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 7 years ago
MODERATORS