this post was submitted on 20 Sep 2023
132 points (97.8% liked)

Linux

48454 readers
867 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 5 years ago
MODERATORS
 

From bash to zsh and everywhere in between, show me yours and I'll show you mines. Inspire others or get some feedback.

Simply copy & paste the output of alias in your terminal or add some comments to explain things for others.

Edit: Kbin users, click 'More' on a comment and use the fediverse link to read responses that have funky formatting

(page 2) 50 comments
sorted by: hot top controversial new old
[–] rutrum@lm.paradisus.day 2 points 1 year ago* (last edited 1 year ago)

I don't like having to renavigate to my project directory in a new terminal:

alias clone='(pwd | urxvt & disown $!)'

Takes my current directory and opens it in my terminal. Then it disowns that new terminal process, so if I close the current terminal the new one doesnt disappear with it.

[–] mojo@lemm.ee 2 points 1 year ago

alias upgrade="sudo dnf upgrade --yes && flatpak update && flatpak remove --unused"

Or something like that, also a dnf remove unused command in there. Writing this from my phone so might be written wrong.

[–] Klaymore@sh.itjust.works 2 points 1 year ago
[–] macallik@kbin.social 2 points 1 year ago* (last edited 1 year ago)

Some random ones I created over the last week or so:

alias clipboard='xclip -selection clipboard' # Allows me to pipe output directly to my keyboard. good for pwd for example.

Function allows me to get tldr and cheat responses to commands quickly
function cht() {
curl cheat.sh/$1
}

Easy calculator so that I can do math w/o launching a specific app
function calc() {
echo "scale=3; $@" | bc
}

[–] I_Am_Jacks_____@lemmings.world 2 points 1 year ago* (last edited 1 year ago) (3 children)

For system updates:

[ -r /etc/os-release ] && . /etc/os-release
case "$ID" in
  arch|archarm)
    if which paru > /dev/null 2>&1; then
      alias updates='echo Using paru; paru'
    else
      alias updates='echo Using pacman; sudo pacman -Syu --noconfirm'
    fi
    ;;
  debian|ubuntu)
    alias updates='echo Using apt dist-upgrade; sudo apt update && sudo apt dist-upgrade -y'
    ;;
esac
load more comments (3 replies)
[–] megane_kun@lemm.ee 2 points 1 year ago* (last edited 1 year ago)

This is a separate reply since I didn't know that you can include shell functions here.

I made this little function read_latest_log() because I just want to "read the latest log file" in a directory full of timestamped log files. I made a helper function separator_line_with_text() to help with the output, basically setting off the file-info portion (just the filename for now) from the file contents.

# # separator_line_with_text
# # Centers text in a separator line
# #
# # Usage:
# # separator_line_with_text «separator_char» «text»
separator_line_with_text() {
local separator_char="$1"
local contents_str="$2"

# Calculate separator_length
local separator_length=$(( $(tput cols) - 2 - ${#contents_str} ))

# Calculate the width of the left and right parts of the separator line
local half_line_width=$(( (${separator_length}) / 2 ))

# Construct the separator line using the $separator_char and $contents_str
for ((i = 0; i « half_line_width; i++))
do
echo -n ${separator_char}
done

echo -n ${contents_str}

for ((i = 0; i < half_line_width; i++))
do
echo -n ${separator_char}
done

echo ""
}

# # read_latest_log
# # Reads the latest log file with a timestamp in the filename.
# #
# # Usage:
# # read_latest_log [[«name_filter»] «extension»] «separator» «timestamp_field_number»
read_latest_log () {
  # Check if the function has sufficient parameters
  if [[ $# -lt 2 ]]; then
    echo "Error: insufficient parameters."
    echo "Usage: read_latest_log [[«name_filter» = *] [«extension» = log] «separator» «timestamp_field_number»"
    return 1
  fi

  # Supposing only two parameters are provided
  # «name_filter» parameter is "*"
  # «extension» parameter is "log"
  if [[ $# -eq 2 ]]; then
    local name_filter="*"
    local extension="log"
    local separator="$1"
    local field="$2"
  fi

  # Supposing only three parameters are provided,
  # assume that the «name_filter» parameter is "*"
  if [[ $# -eq 3 ]]; then
    local name_filter="*"
    local extension="$1"
    local separator="$2"
    local field="$3"
  fi

  # If all parameters are provided, assign them accordingly
  if [[ $# -eq 4 ]]; then
    local name_filter="$1"
    local extension="$2"
    local separator="$3"
    local field="$4"
  fi

  # Find all log files with the specified extension, sort them based on the separator and field
  local log_files=$(find . -type f -name "${name_filter}.${extension}" | sort -n -t "${separator}" -k "${field}")

  # If no log files are found, display a message and return
  if [[ -z "$log_files" ]]; then
    echo "No log files found."
    return 0
  fi

  # Get the latest log file and its full path
  local latest_log_file=$(echo "$log_files" | tail -1)
  local full_path=$(realpath "$latest_log_file")

  # Define the strings for the separator line and
  # calculate the appropriate length of the separator line
  local contents_str=" Contents "
  local separator_char="—"

  separator_line_with_text ${separator_char} ""
  separator_line_with_text " " ${full_path}
  separator_line_with_text ${separator_char} ${contents_str}
  cat "$(echo "$log_files" | tail -1)"
}

Sorry for all the edits, for some reason anything that looks like an HTML tag gets erased.

[–] gamma@programming.dev 2 points 1 year ago* (last edited 1 year ago)

(NOTE: A lot of my more interesting "aliases" are actually short functions, but I'm keeping myself to alias.)

Some of mine that I haven't seen yet:

# Simple python calculator
alias pycalc='python3 -ic "
from math import *\nimport cmath as C
try:
    import numpy as np
except:
    pass
i, j = 1j, 1j
"'

# Defaults
alias cp='cp --interactive --reflink=auto'
alias gcc='gcc -fdiagnostics-color=auto'
# Lemmy doesn't handle ampersands in codeblocks correctly
alias rg='rg --max-columns=$((COLUMNS > 60 && ! ZSH_SUBSHELL ? COLUMNS - 30 : 0))'
alias rj='rg --json'
alias rm='rm -s'
alias rscp='rsync -azP --human-readable --info=flist0,progress2,stats1'
alias rust-c='rustc --out-dir build -O'

# Shorter forms
alias g=git
alias v=$VISUAL
alias py=python
alias jfeu='journalctl --user -xfeu'
alias sys='systemctl --user'
alias Jfeu='journalctl -xfeu'
alias Sys=systemctl

# Desktop stuff
alias trash='gio trash'
alias ud=udisksctl
alias y=wl-copy
alias Y='wl-copy -p'
alias p=wl-paste
alias P='wl-paste -p'

# Colorize with acolor/grc
alias GRC='grc -es'
alias LA='acol ls -lFAhb --color'
alias LS='acol ls -lFhb --color'
alias df='GRC df -hT'
alias dig='GRC dig'
alias docker='GRC docker'
alias docker-machine='GRC docker-machine'
alias env='acol env'
alias lsblk='acol lsblk'
alias lsmount='command mount | rg --color=never "^/" | acol -i -o mount'
alias lspci='acol lspci'
alias mount='acol mount'
alias nmap='acol nmap'
alias ping='GRC ping'
alias ps='GRC ps --columns $COLUMNS'
alias traceroute='GRC traceroute'
[–] clemdemort@lemmy.world 2 points 1 year ago (1 children)

I've got aliases for every faltpak app I launch in the terminal for instance I've got code for vscodium or steam for well steam for example, I also alias some system commands so I have an update-grub, update, etc...

I also alias LSD to LS for obvious reasons.

load more comments (1 replies)
[–] flying_wotsit@feddit.uk 2 points 1 year ago (3 children)

here we go, in no particular order:

claer=clear
gvim='nvim +Gclog +Git'
vim=nvim
vi=/usr/bin/vim
v=/usr/bin/vi
glog='git log --oneline --graph --all'
rcp='rsync -r --info=progress2 --partial'
d0='du -h --max-depth 0'
d1='du -h --max-depth 1'
ls='ls --time-style=long-iso --color=tty'
icat=chafa
ssh='TERM=xterm-256color ssh' # (kitty messes with TERM)
load more comments (3 replies)
[–] doomkernel@sopuli.xyz 2 points 1 year ago (2 children)

I've got the standard ones (l, ll, ls) to be forms of ls -flags

df = df -h
mv = mv -i
rm = rm -i
nix-switch = sudo nix-rebuild --switch flake .
nix-upd = nix flake update
systat = systemctl status
sysena = sudo systemctl enable
systop = sudo systemctl stop

[–] macallik@kbin.social 1 points 1 year ago* (last edited 1 year ago)

Digging the systemctl ones. I added myself to the group so that I wouldn't have to write sudo each time, but I might as well alias the entire prompt for restart and status to make it even shorter

load more comments (1 replies)
[–] SomeBoyo@feddit.de 2 points 1 year ago (3 children)

I mainly use an alias to ssh into my server and another to stream lofi girl audio with mpv

[–] ryannathans@aussie.zone 1 points 1 year ago (1 children)
load more comments (1 replies)
load more comments (2 replies)
[–] bennieandthez@lemmygrad.ml 1 points 1 year ago

These are some pacman+fzf implementations from the arch wiki + a flatpak implementation i did with fzf(still needs some polish but it works).

alias pacq=$'pacman -Q | fzf'

alias pacs=$'pacman -Slq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S'

alias pacr=$'pacman -Qq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -Rns'

alias flatr=$'flatpak list | fzf --preview 'flatpak info {2} ' | grep -Eo '[a-ZA-Z]+.[^ ]+' |awk '{print $1}' | xargs -ro flatpak remove --delete-data'

[–] chrishazfun@lemmy.world 1 points 1 year ago
alias getmp4="yt-dlp -f 'bestvideo+bestaudio[ext=m4a]/best[ext=mp4]' --recode-video mp4"
alias getmp3="yt-dlp -x --audio-format mp3"
alias downloadwebsite="wget -mkEpnp"

flushall () {
	sudo pacman -Scc
	sudo pacman -Rns $(pacman -Qdtq)
	flatpak uninstall --unused
}

updateall () {
	yay
	flatpak update
	while
		read -p "Clear cache and uninstall orphans? (y/N)" answer
	do
		case $answer in
			([yY][eE][sS] | [yY]) flushall;;
			(*) break;;
		esac
	done
}
[–] Scio@kbin.social 1 points 1 year ago (1 children)

I'm going to assume all these syntax highlighted HTML embeds are from Lemmy users. Sadly, illegible on Kbin.

[–] macallik@kbin.social 1 points 1 year ago* (last edited 1 year ago)

Ahhh I was wondering what that was as a fellow kbin-er. I was pleasantly surprised when I found out I could create threads across the fediverse today as a consolation.

Edit: Click the 'more' button on the comment and get the fediverse link to view the formatted post

load more comments
view more: ‹ prev next ›