ctrlaltvikas/Awesome-Bash-Aliases
๐ฅ Curated collection of powerful Bash aliases to boost terminal productivity. - ctrlaltvikas/Awesome-Bash-Aliases
255 stars ยท 38 forks ยท 4 watchers
README
๐ Awesome Bash Aliases A carefully curated collection of safe, practical, and modern shell aliases and functions for developers, DevOps engineers, platform engineers, system administrators, solution architects, and Linux/macOS power users. The project focuses on:
Everyday terminal productivity Git and software-development workflows Docker and container management Kubernetes operations Networking and troubleshooting Linux and macOS system administration Infrastructure as Code Cloud-native development Safe and predictable command behaviour
Principle: Save keystrokes without hiding important behaviour or making destructive operations dangerously easy.
Website: https://vikaskyadav.github.io/awesome-bash-alias/
โจ Why This Project? Shell aliases are easy to create but difficult to maintain well. A reliable collection should:
Avoid duplicate or conflicting aliases. Work across Linux and macOS wherever possible. Use functions when arguments or validation are required. Avoid silently destructive commands. Detect optional tools before configuring them. Preserve tab completion. Clearly separate safe shortcuts from advanced administrative operations. Remain understandable even months after installation.
๐ฅ๏ธ Supported Shells The primary target is:
Bash 4+ Bash 5+ Zsh, where syntax is compatible
Some completion settings are shell-specific and are stored separately.
๐ Repository Structure awesome-bash-alias/ โโโ README.md โโโ aliases.sh โโโ install.sh โโโ uninstall.sh โโโ completions/ โ โโโ bash.sh โ โโโ zsh.sh โโโ modules/ โ โโโ core.sh โ โโโ navigation.sh โ โโโ files.sh โ โโโ git.sh โ โโโ docker.sh โ โโโ kubernetes.sh โ โโโ networking.sh โ โโโ system.sh โ โโโ packages.sh โ โโโ development.sh โ โโโ infrastructure.sh โ โโโ cloud.sh โ โโโ macos.sh โโโ optional/ โ โโโ modern-cli.sh โ โโโ dangerous.sh โโโ tests/ โโโ aliases.bats
This modular structure allows users to enable only the sections they need.
โก Installation Quick Installation git clone https://github.com/vikaskyadav/awesome-bash-alias.git \ "${HOME}/.awesome-bash-alias"
printf '\n# Awesome Bash Aliases\n' >> "${HOME}/.bashrc" printf 'source "$HOME/.awesome-bash-alias/aliases.sh"\n' >> "${HOME}/.bashrc"
source "${HOME}/.bashrc" For Zsh: printf '\n# Awesome Bash Aliases\n' >> "${HOME}/.zshrc" printf 'source "$HOME/.awesome-bash-alias/aliases.sh"\n' >> "${HOME}/.zshrc"
source "${HOME}/.zshrc" Before installing, users should review the aliases and remove any that conflict with their existing configuration.
โ๏ธ Configuration Principles Aliases versus Functions Use an alias for straightforward command substitution: alias gs='git status --short --branch' Use a function when:
Arguments are accepted. Validation is required. Multiple commands are executed. Quoting is important. Behaviour depends on the operating system.
Example: mkcd() { if [ "$#" -ne 1 ]; then printf 'Usage: mkcd <directory>\n' >&2 return 2 fi
mkdir -p -- "$1" && cd -- "$1" }
๐งฐ Core Configuration Helpers
Return success when a command is installed.
has() { command -v "$1" >/dev/null 2>&1 }Operating-system detection.
case "$(uname -s)" in Darwin) export AWESOME_ALIAS_OS="macos" ;; Linux) export AWESOME_ALIAS_OS="linux" ;; *) export AWESOME_ALIAS_OS="other" ;; esacTerminal and Shell alias c='clear' alias cls='clear; ls' alias reload='source "${HOME}/.${SHELL##*/}rc"' alias path='printf "%s\n" "${PATH//:/$'\''\n'\''}"' alias now='date "+%Y-%m-%d %H:%M:%S"' alias week='date "+%V"' alias shellinfo='printf "Shell: %s\nVersion: %s\n" "$SHELL" "$BASH_VERSION"' The reload alias works for common Bash and Zsh configurations, provided the corresponding configuration file exists. A safer function is: reload-shell() { local config
case "${SHELL##*/}" in bash) config="${HOME}/.bashrc" ;; zsh) config="${HOME}/.zshrc" ;; *) printf 'Unsupported shell: %s\n' "$SHELL" >&2 return 1 ;; esac
if [ ! -f "$config" ]; then printf 'Configuration file not found: %s\n' "$config" >&2 return 1 fi
# shellcheck disable=SC1090 source "$config" }
๐ Navigation Use one consistent hierarchy rather than defining several conflicting alternatives. alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..'
alias -- -='cd -' alias home='cd "${HOME}"' alias root='cd /' Useful directory functions: mkcd() { if [ "$#" -ne 1 ]; then printf 'Usage: mkcd <directory>\n' >&2 return 2 fi
mkdir -p -- "$1" && cd -- "$1" }
croot() { local root
root="$(git rev-parse --show-toplevel 2>/dev/null)" || { printf 'Not inside a Git repository.\n' >&2 return 1 }
cd -- "$root" }
up() { local levels="${1:-1}" local destination=""
case "$levels" in ''|[!0-9]) printf 'Usage: up [positive-integer]\n' >&2 return 2 ;; esac
while [ "$levels" -gt 0 ]; do destination="../${destination}" levels=$((levels - 1)) done
cd -- "$destination" } Examples: mkcd new-project up 3 croot
๐ File Listing Linux and macOS ship different implementations of several core utilities. Configure them separately. if [ "$AWESOME_ALIAS_OS" = "macos" ]; then alias ls='ls -G' alias l='ls -lahG' alias ll='ls -lhG' alias la='ls -AG' else alias ls='ls --color=auto' alias l='ls -lah --color=auto' alias ll='ls -lh --color=auto' alias la='ls -A --color=auto' fi Additional listing commands: alias ld='ls -ld -- */ 2>/dev/null' alias tree2='tree -L 2' alias tree3='tree -L 3' Do not configure ls='ls -a'; doing so unexpectedly changes the behaviour of every ls invocation and makes scripts or copied commands harder to reason about.
๐ก๏ธ Safe File Operations Overriding standard commands can sometimes break scripts or surprise experienced users. Therefore, explicit safe variants are preferable. alias cpi='cp -i' alias mvi='mv -i' alias rmi='rm -i' alias rmI='rm -I' alias lni='ln -i' alias mkdirp='mkdir -p' Avoid globally aliasing rm, cp, or mv unless users deliberately opt in. Optional interactive protection:
Enable only after reviewing the implications.
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -I'
Linux-specific root protection: if [ "$AWESOME_ALIAS_OS" = "linux" ]; then alias rm-safe='rm -I --preserve-root' alias chmod-safe='chmod --preserve-root' alias chown-safe='chown --preserve-root' alias chgrp-safe='chgrp --preserve-root' fi๐ File Search and Inspection alias grep='grep --color=auto' alias egrep='grep -E --color=auto' alias fgrep='grep -F --color=auto'
alias countfiles='find . -type f | wc -l' alias countdirs='find . -type d | wc -l' alias emptydirs='find . -type d -empty' alias emptyfiles='find . -type f -empty' Functions: ff() { if [ "$#" -ne 1 ]; then printf 'Usage: ff <filename-pattern>\n' >&2 return 2 fi
find . -type f -iname "$1" }
fdirectory() { if [ "$#" -ne 1 ]; then printf 'Usage: fdirectory <directory-pattern>\n' >&2 return 2 fi
find . -type d -iname "$1" }
extract() { if [ "$#" -ne 1 ]; then printf 'Usage: extract <archive>\n' >&2 return 2 fi
local archive="$1"
if [ ! -f "$archive" ]; then printf 'File not found: %s\n' "$archive" >&2 return 1 fi
case "$archive" in .tar.bz2|.tbz2) tar -xjf "$archive" ;; .tar.gz|.tgz) tar -xzf "$archive" ;; .tar.xz|.txz) tar -xJf "$archive" ;; *.tar.zst) tar --zstd -xf "$archive" ;; *.tar) tar -xf "$archive" ;; *.bz2) bunzip2 "$archive" ;; *.gz) gunzip "$archive" ;; *.xz) unxz "$archive" ;; *.zip) unzip "$archive" ;; *.7z) 7z x "$archive" ;; *.rar) unrar x "$archive" ;; *) printf 'Unsupported archive format: %s\n' "$archive" >&2 return 1 ;; esac }
๐พ Disk Usage GNU and BSD du use different depth options. alias dfh='df -h' alias dfi='df -i' alias usage='du -sh .' alias biggest='du -sh ./* 2>/dev/null | sort -h | tail -20'
if [ "$AWESOME_ALIAS_OS" = "macos" ]; then alias du1='du -h -d 1' else alias du1='du -h --max-depth=1' alias partitions='df -hT -x tmpfs -x devtmpfs' fi When available: if has ncdu; then alias disk='ncdu' fi
๐งฎ Calculator and Encoding alias calc='bc -l' alias sha256='sha256sum' alias b64e='base64' alias urlencode='python3 -c "import sys,urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip()))"' Cross-platform SHA-256 function: sha256file() { if [ "$#" -ne 1 ]; then printf 'Usage: sha256file <file>\n' >&2 return 2 fi
if has sha256sum; then sha256sum -- "$1" elif has shasum; then shasum -a 256 -- "$1" else printf 'Neither sha256sum nor shasum is installed.\n' >&2 return 1 fi }
๐ History alias h='history' alias h10='history 10' alias h20='history 20' alias h50='history 50' alias hg='history | grep' More reliable history search: hgrep() { if [ "$#" -lt 1 ]; then printf 'Usage: hgrep <pattern>\n' >&2 return 2 fi
history | grep -i -- "$*" } Recommended shell settings: export HISTCONTROL="ignoreboth:erasedups" export HISTSIZE=50000 export HISTFILESIZE=100000
shopt -s histappend 2>/dev/null || true Avoid storing secrets directly in shell commands because they may be retained in shell history, terminal logs, audit systems, or process information.
๐ฟ Git ๐ Everyday Git alias g='git' alias gs='git status --short --branch' alias gst='git status' alias ga='git add' alias gaa='git add --all' alias gap='git add --patch'
alias gd='git diff' alias gds='git diff --staged' alias gdw='git diff --word-diff'
alias gb='git branch' alias gba='git branch --all' alias gbd='git branch --delete' alias gbD='git branch --delete --force'
alias gc='git commit' alias gcm='git commit -m' alias gca='git commit --amend' alias gcan='git commit --amend --no-edit'
alias gsw='git switch' alias gswc='git switch --create' alias grs='git restore' alias grss='git restore --staged'
alias gco='git checkout' alias gcb='git checkout -b'
alias gf='git fetch' alias gfa='git fetch --all --prune' alias gp='git push' alias gpu='git push --set-upstream origin HEAD' alias gpf='git push --force-with-lease' alias gl='git pull' alias glr='git pull --rebase'
alias gm='git merge' alias gma='git merge --abort' alias grb='git rebase' alias grba='git rebase --abort' alias grbc='git rebase --continue'
alias gstash='git stash push' alias gstashp='git stash pop' alias gstashl='git stash list'
alias gtags='git tag --sort=-creatordate' alias gremotes='git remote --verbose' alias gcontributors='git shortlog --summary --numbered --email' ๐ Git Logs alias glog='git log --oneline --decorate --graph' alias gloga='git log --oneline --decorate --graph --all' alias glast='git log -1 HEAD --stat' alias gwho='git shortlog -sn' ๐ง Git Functions gclone() { if [ "$#" -ne 1 ]; then printf 'Usage: gclone <repository-url>\n' >&2 return 2 fi
git clone -- "$1" }
groot() { git rev-parse --show-toplevel }
gclean-preview() { git clean -ndx }
gclean-ignored-preview() { git clean -ndX }
gundo() { git reset --soft HEAD~1 }
gpristine() { printf 'This will discard tracked changes and remove untracked files.\n' git status --short printf 'Type PRISTINE to continue: '
local confirmation read -r confirmation
[ "$confirmation" = "PRISTINE" ] || { printf 'Cancelled.\n' return 1 }
git reset --hard HEAD && git clean -fd } Do not provide aliases such as nah, gclean, or other one-word commands that silently destroy work.
GitHub CLI Enabled only when GitHub CLI is installed: if has gh; then alias ghpr='gh pr view --web' alias ghprs='gh pr list' alias ghissues='gh issue list' alias ghrepo='gh repo view --web' alias ghruns='gh run list' alias ghwatch='gh run watch' fi
๐ณ Docker Docker commands should normally run without sudo. Users should configure Docker according to their operating system and security model. ๐ฆ Container and Image Commands if has docker; then alias d='docker' alias dps='docker ps' alias dpsa='docker ps --all' alias di='docker images' alias dimg='docker image ls' alias dvol='docker volume ls' alias dnet='docker network ls' alias dinfo='docker info' alias dver='docker version'
alias dlog='docker logs' alias dlogf='docker logs --follow --tail 200' alias dstats='docker stats' alias dtop='docker top' alias dinspect='docker inspect'
alias dbuild='docker build' alias dbuildx='docker buildx build' alias dpull='docker pull' alias dpush='docker push'
alias dprune-preview='docker system df' fi ๐ Docker Functions dsh() { if [ "$#" -lt 1 ]; then printf 'Usage: dsh <container> [command]\n' >&2 return 2 fi
local container="$1" shift
if [ "$#" -gt 0 ]; then docker exec -it "$container" "$@" elif docker exec "$container" test -x /bin/bash 2>/dev/null; then docker exec -it "$container" /bin/bash else docker exec -it "$container" /bin/sh fi }
drun() { if [ "$#" -lt 1 ]; then printf 'Usage: drun <image> [command]\n' >&2 return 2 fi
docker run --rm -it "$@" }
dip() { if [ "$#" -ne 1 ]; then printf 'Usage: dip <container>\n' >&2 return 2 fi
docker inspect \ --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \ "$1" }
dstop-all() { local containers containers="$(docker ps -q)"
if [ -z "$containers" ]; then printf 'No running containers.\n' return 0 fi
printf '%s\n' "$containers" printf 'Stop all running containers? [y/N] '
local answer read -r answer
case "$answer" in y|Y|yes|YES) # Intentional word splitting of container IDs. # shellcheck disable=SC2086 docker stop $containers ;; *) printf 'Cancelled.\n' ;; esac }
dprune() { docker system df printf 'Run Docker system prune? [y/N] '
local answer read -r answer
case "$answer" in y|Y|yes|YES) docker system prune ;; *) printf 'Cancelled.\n' ;; esac } Avoid making docker system prune -af, deletion of every container, or deletion of every image available through an unguarded short alias.
๐ Docker Compose Modern Docker installations use the Compose CLI plugin: if has docker && docker compose version >/dev/null 2>&1; then alias dc='docker compose' alias dcu='docker compose up' alias dcud='docker compose up --detach' alias dcub='docker compose up --detach --build' alias dcd='docker compose down' alias dcdv='docker compose down --volumes' alias dcps='docker compose ps' alias dcl='docker compose logs' alias dclf='docker compose logs --follow --tail 200' alias dcb='docker compose build' alias dcpull='docker compose pull' alias dcconfig='docker compose config' alias dcrestart='docker compose restart' fi dcdv removes project volumes and should therefore be used deliberately.
โธ๏ธ Kubernetes ๐ฏ Core Commands if has kubectl; then alias k='kubectl'
alias kg='kubectl get' alias kd='kubectl describe' alias ka='kubectl apply -f' alias kdel='kubectl delete' alias ke='kubectl edit'
alias kgp='kubectl get pods' alias kgpa='kubectl get pods --all-namespaces' alias kgpw='kubectl get pods --watch' alias kgd='kubectl get deployments' alias kgs='kubectl get services' alias kgi='kubectl get ingress' alias kgn='kubectl get nodes' alias kgns='kubectl get namespaces' alias kgcm='kubectl get configmaps' alias kgsec='kubectl get secrets' alias kgpv='kubectl get persistentvolumes' alias kgpvc='kubectl get persistentvolumeclaims'
alias kdp='kubectl describe pod' alias kdd='kubectl describe deployment' alias kdn='kubectl describe node'
alias kl='kubectl logs' alias klf='kubectl logs --follow --tail=200' alias kexec='kubectl exec -it' alias ktop='kubectl top' alias ktopn='kubectl top nodes' alias ktopp='kubectl top pods'
alias kctx='kubectl config current-context' alias kctxs='kubectl config get-contexts' alias kns='kubectl config view --minify --output "jsonpath={..namespace}"'
alias kev='kubectl get events --sort-by=.metadata.creationTimestamp' alias kroll='kubectl rollout status' alias krestart='kubectl rollout restart' alias khistory='kubectl rollout history' alias kundoroll='kubectl rollout undo'
alias kapi='kubectl api-resources' alias kexplain='kubectl explain' alias kdiff='kubectl diff -f' fi ๐ง Kubernetes Functions kuse() { if [ "$#" -ne 1 ]; then printf 'Usage: kuse <context>\n' >&2 return 2 fi
kubectl config use-context "$1" }
knamespace() { if [ "$#" -ne 1 ]; then printf 'Usage: knamespace <namespace>\n' >&2 return 2 fi
kubectl config set-context \ --current \ --namespace="$1" }
kpf() { if [ "$#" -lt 2 ]; then printf 'Usage: kpf <resource> <local-port:remote-port> [additional-options]\n' >&2 return 2 fi
kubectl port-forward "$@" }
kdebug() { if [ "$#" -lt 1 ]; then printf 'Usage: kdebug <pod> [debug-image]\n' >&2 return 2 fi
local pod="$1" local image="${2:-busybox:1.36}"
kubectl debug -it "$pod" --image="$image" } Do not create an alias that deletes every Kubernetes resource or namespace. Cluster context and namespace should remain visible and deliberate.
โต Helm if has helm; then alias h='helm' alias hls='helm list' alias hlsa='helm list --all-namespaces' alias hrepo='helm repo list' alias hrepou='helm repo update' alias hsearch='helm search repo' alias hstatus='helm status' alias hhistory='helm history' alias hrollback='helm rollback' alias htemplate='helm template' alias hlint='helm lint' fi Because h is commonly used for shell history, projects should choose either: alias h='history' or: alias h='helm' Do not define both. A less ambiguous Helm prefix is recommended: alias hm='helm' alias hmls='helm list' alias hmlsa='helm list --all-namespaces'
๐๏ธ Terraform and OpenTofu if has terraform; then alias tf='terraform' alias tfi='terraform init' alias tff='terraform fmt' alias tffr='terraform fmt -recursive' alias tfv='terraform validate' alias tfp='terraform plan' alias tfa='terraform apply' alias tfo='terraform output' alias tfs='terraform show' alias tfw='terraform workspace' alias tfwl='terraform workspace list' alias tfstate='terraform state list' fi
if has tofu; then alias tofu-init='tofu init' alias tofu-fmt='tofu fmt -recursive' alias tofu-validate='tofu validate' alias tofu-plan='tofu plan' alias tofu-apply='tofu apply' fi Do not alias terraform destroy or tofu destroy to a short, easily mistyped command.
๐ค Ansible if has ansible; then alias av='ansible --version' alias ai='ansible-inventory' alias aigr='ansible-inventory --graph' alias ap='ansible-playbook' alias apcheck='ansible-playbook --check --diff' alias alint='ansible-lint' fi
๐ Networking ๐ก General Commands alias ping5='ping -c 5' alias pingdns='ping -c 5 1.1.1.1' alias routeinfo='ip route 2>/dev/null || netstat -rn' alias dnsinfo='cat /etc/