Boost Your Linux Productivity with Essential Bash Aliases and Functions
This article presents a curated collection of practical Bash aliases and functions that streamline repetitive command‑line tasks, improve navigation, automate common operations, and provide quick system‑information shortcuts, helping Linux users save seconds on every command they run.
Why Use Aliases and Functions?
Frequent command‑line users often repeat the same commands, SSH into the same host, or run programs with identical parameters. By defining short aliases or shell functions, you can replace long command strings with a single word, saving valuable seconds and reducing typing fatigue.
Basic Alias Syntax
An alias maps a new name to an existing command. For example, to make ls output in colour: alias ls="ls --color=auto" Aliases cannot accept arguments, so for more complex tasks you can define a shell function.
Productivity Aliases and Functions
alias ll="ls --color -al"– detailed coloured listing. alias grep='grep --color=auto' – colour‑highlighted search results. mcd() { mkdir -p "$1"; cd "$1"; } – create a directory and immediately enter it. cls() { cd "$1"; ls; } – change to a directory and list its contents. backup() { cp "$1"{,.bak}; } – create a .bak copy of a file. md5check() { md5sum "$1" | grep "$2"; } – compute and compare an MD5 checksum. alias makescript="fc -rnl | head -1 >" – pipe the last executed command into a new script file.
alias genpasswd="strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '
'; echo"– generate a strong random password. alias c="clear" – clear the terminal screen. alias histg="history | grep" – search command history for a keyword. alias ..='cd ..' and alias ...='cd ../..' – quick navigation up the directory tree.
File Extraction Helper
A single function that extracts many common archive formats:
extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}System‑Information Shortcuts
alias cmount="mount | column -t"– display mounted filesystems in columns.
alias tree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"– show directory tree.
sbs() { du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30?($1/2**30,"G"):$1>=2**20?($1/2**20,"M"):$1>=2**10?($1/2**10,"K"):($1,"")}e'; }– list files sorted by size.
alias intercept="sudo strace -ff -e trace=write -e write=1,2 -p"– attach strace to a process to monitor writes. alias meminfo='free -m -l -t' – show memory usage in megabytes. alias ps?="ps aux | grep" – quickly find a process by name.
alias volume="amixer get Master | sed '1,4 d' | cut -d [ -f 2 | cut -d ] -f 1"– display current audio volume.
Network‑Related Aliases
alias websiteget="wget --random-wait -r -p -e robots=off -U mozilla"– download an entire website. alias listen="lsof -P -i -n" – list processes with open network connections. alias port='netstat -tulanp' – show active listening ports.
gmail() { curl -u "$1" --silent "https://mail.google.com/mail/feed/atom" | sed -e 's/<\/fullcount.*/
/' -e 's/.*fullcount>//'; }– fetch unread Gmail count. alias ipinfo="curl ifconfig.me && curl ifconfig.me/host" – display public IP and hostname.
getlocation() { lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1 | grep address | egrep 'city|state|country' | awk '{print $3,$4,$5,$6,$7,$8}' | sed 's\ip address flag \\' | sed 's\My\\'; }– retrieve geographic location of an IP.
Fun / Miscellaneous Aliases
kernelgraph() { lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"
" for split/,/,$_[3]}print "}"' | dot -Tpng | display -; }– generate a graph of kernel module dependencies. alias busy="cat /dev/urandom | hexdump -C | grep 'ca fe'" – produce seemingly busy output for fun.
All the above aliases and functions can be copied into your ~/.bashrc to make them available in every terminal session. They are gathered from personal usage and community resources such as alias.sh and commandlinefu.com , offering a quick way to boost command‑line efficiency.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
