What's your most-used terminal alias or function?

We all have that one alias or shell function we’ve quietly copy-pasted into every new machine for years. The little quality-of-life trick that makes you irrationally happy every time it saves you three keystrokes.

Drop your favorite alias, one-liner, or shell function below and tell us what it does, bonus points if it’s something you cooked up yourself and didn’t just steal from a dotfiles repo (we won’t judge if you did though). :slight_smile:

2 Likes
alias ls="lsd -lah --header"
2 Likes
alias ll="ls -lAhF --group-directories-first"

Nothing groundbreaking but having directories sorted to the top and hidden files visible by default just makes navigating so much smoother. I tried switching to eza at one point but honestly kept coming back to this.

4 Likes

Here are my favorites ones:
alias update=“sudo apt update && sudo apt upgrade”

alias ls=“ls -alF”

1 Like

believe it or not c is one of my most common alias commands.
alias c=‘clear;pwd’
I have various ls aliases that are also very frequently used, on Endeavour OS where I happen to be at the moment, here’s how I implemented them on this system.
alias l=‘ls -al’
alias ll=‘ls -l’

I vary those, depending on what I’m doing.
alias u is another VERY common alias that I use; again I alter this one depending on which distribution I’m using. On antiX, I use it with apt commands; here on Endeavour OS, the following:
alias u=‘yay -Syu’

3 Likes

alias cls=clear
alias ltr=‘ls -latr’
alias hello=‘cd; clear; fastfetch’
update=‘apt clean all; apt update; apt -y upgrade’

2 Likes

i have many alias for my favorite directorys like

vm
dock
data
dev
learn

alias ..=‘cd ..’
alias …=‘cd ../..’
alias …=‘cd ../../..’
alias home=‘cd ~’
alias root=‘cd /’
alias logs=‘cd /var/log’
alias topu=‘top -u $USER’
alias psa=‘ps aux’

6 Likes

@Blue_bird I love your alias commands. I may add a few of them to my collection.

3 Likes

Indeed, these are great guys. Thanks for sharing.

Will be referencing you guys in an article tomorrow:

From the Community

The LinuxCommunity.io forum thread on favorite aliases and functions collected some solid contributions worth adding to your own setup. Here are the highlights.

toadie swaps ls for lsd, a modern ls replacement with icons and color output:

alias ls="lsd -lah --header"

toadie also uses short named aliases for frequently visited directories, one per project or location:

alias vm='cd ~/vm' 
alias dock='cd ~/docker' 
alias dev='cd ~/dev' 
alias learn='cd ~/learn'

Once you have more than a handful of project directories, this pattern beats cd-ing through long paths every time.

I used a version of ll that sorts directories to the top:

alias ll="ls -lAhF --group-directories-first"

Small change from the standard ll, but having directories sorted above files makes scanning large directories noticeably faster.

Gopinath Pigili adds a few location shortcuts and a per-user top view:

alias home='cd ~' 
alias root='cd /' 
alias logs='cd /var/log' 
alias topu='top -u $USER' 
alias psa='ps aux'

topu is a neat one. It filters top to show only your own processes, useful on shared systems where other users’ processes clutter the output.

Brian Masinick keeps a simple c alias that clears the screen and prints the current directory in one shot:

alias c='clear;pwd'

He also uses a short u alias mapped to the update command for whichever distro he’s on at the time, swapping it out per machine. Same principle as the distro-specific update aliases covered above, just taken further.

J J Sloan has a hello alias that makes for a satisfying login sequence:

alias cls=clear 
alias ltr='ls -latr' 
alias hello='cd; clear; fastfetch'`

hello drops you to home, clears the screen, and fires fastfetch for a system info summary. Good for a fresh terminal orientation. ltr sorts files by modification time with the most recently changed at the bottom, useful when you want to see what changed and when.

2 Likes

I will go for that --group-directories-first option from now on! I am though using lt and lr for time-sorted listing.

What’s with everybody using a command to clear the screen? Don’t you have CTRL-L?

Video player of choice (legacy alias from when I used OMXPlayer):

alias o='mpv --fullscreen'

I guess this one gets used frequently without noticing it:

alias grep='grep --color=auto'

If I want to truncate a file but keep it around, so I know I had it:

alias zero='truncate -s 0'

To truncate a file and move it to a folder at the same time (I love this technique to do multi-line aliases):

alias zm='f(){ zero "$1"; mv "$1" "$2";  unset -f f; }; f'

Finally, go edit the aliases:

alias ba='sudo nano ~/.bash_aliases'

… and enable the updates made:

alias re_source='source ~/.bashrc'
4 Likes

It’s pretty obvious that the alias commands we use depend on the distributions we choose and the frequency of the commands that we utilize. I like many of the aliases that various people chose, but if I added them to my system I probably would not use them very much. Even among the aliases (and functions) that I wrote in my .bashrc I’ll admit that I probably use the top five or six of them every week, though I probably use most of them during the year.

2 Likes

I for one do NOT like intermingling of hidden and non-hidden files. Similarly, I don’t like mingling letters and special characters when sorting.

I am very particular with my sorting of files and directories at command line, so I use a couple of different things.


[1] This first is a function used by other alias definitions (to ensure uniform presentation of information, regardless of the displayed content encountered):

alias ndate='awk '\''{ pos=index( $0, $9 ) ; rem=substr( $0, pos ) ; printf("%s %3d %10s %10s %10d  %3s %2d %5s  %s\n", $1, $2, $3, $4, $5, $6, $7, $8, rem ) ; } '\'' '

[2] Then, to list only directories, I have

alias ldir='find . -maxdepth 1      -type d    -print | cut -c3- | sort -V | xargs -I here ls -ld --color=always "here" | ndate '

[3] Similarly, for non-directory files, I have

alias lf='find . -maxdepth 1 \( ! -type d \) -print | cut -c3- | sort -V | xargs -I here ls -ld --color=always "here" | ndate '

[4] To report only shell scripts in the current directory:

alias lsh='find . -maxdepth 1 \( -name "*.sh" -o -name "*.bash" \) -print | cut -c3- | sort -V | xargs -I here ls -ld --color=always "here" | ndate '

[5] And again, for only symbolic links:

alias lsk='find . -maxdepth 1      -type l    -print | cut -c3- | sort -V | xargs -I here ls -ld --color=always "here" | ndate '

[6] To list everything, using that same formatting and ordering, I have:

alias lf='find . -maxdepth 1 \( ! -type d \) -print | cut -c3- | sort -V | xargs -I here ls -ld --color=always "here" | ndate '


On the more complicated side, I have this script [Priority__Report.sh]:

#!/bin/sh

BASE=`basename "$0" ".sh" `
TMP=/tmp/${BASE}.proclist

rm -f ${TMP}
ps -eo pid,user:15,%cpu,ni,args >${TMP}

header="`head -1 ${TMP} `"
echo "${header}"

if [ "$1" = "--all" ]
then
	tail -n +2 ${TMP}
else
	tail -n +2 ${TMP} | awk '{ if( $4 != "-20" && index($5,"[kworker/") != 1  &&  index($5,"[ksoftirqd/") != 1  &&   index($5,"[jbd2/") != 1  &&  index($5,"[scsi_eh") != 1  &&  index($5,"[idle_inject") != 1  &&  index($5,"[migration") != 1  &&  index($5,"[cpuhp") != 1 ){ print $0 } ; }'
fi | sort -n --key=3.1,4.0 | sort --key=2.1,3.0

rm -f ${TMP}

[7] for which I use the following alias:

alias prio='/Oasis/bin/Priority__Report.sh'

[Edit:] While sharing the above, I noticed that I had a gap in my “reporting” aliases, one giving only the hidden files at current directory level. I just added this [8] to my environment:

alias ldot='find . -maxdepth 1 -print | cut -c3- | grep ^[.] | sort -V | xargs -I here ls -ld --color=always "here" | ndate '
2 Likes

Probably this one:

alias alsamixer='alsamixer -c 1'
1 Like