SyntaxStudy
Sign Up
Linux / Bash Aliases, Shell Options, and Dotfiles
Linux / Bash Beginner 1 min read

Aliases, Shell Options, and Dotfiles

Aliases create short names for longer commands or common option combinations. They are defined with `alias name=command` and are expanded before the command is executed. Useful aliases can dramatically speed up daily work — aliasing `ll` to `ls -lahF`, `update` to a full apt upgrade sequence, or `gs` to `git status`. Aliases are session-local unless added to a startup file. Shell options configured with `shopt` (Bash-specific) and `set` control shell behaviour. `shopt -s globstar` enables the `**` recursive glob. `shopt -s autocd` lets you change directory by just typing the path. `set -o vi` enables vi-style command line editing. `set -o noclobber` prevents `>` from overwriting existing files, requiring `>|` to force. Dotfiles are the hidden configuration files in your home directory (`.bashrc`, `.bash_profile`, `.vimrc`, `.gitconfig`, etc.). Maintaining these in a version-controlled repository and symlinking them into place is a common practice that allows you to replicate your environment across machines. Tools like `stow` automate the symlinking process.
Example
# ---- Aliases ----

# Define an alias
alias ll='ls -lahF --color=auto'
alias la='ls -A'
alias ..='cd ..'
alias ...='cd ../..'

# Git shortcuts
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline --graph --decorate'

# Safety aliases
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# System shortcuts
alias update='sudo apt update && sudo apt upgrade -y'
alias ports='ss -tulnp'
alias myip='curl -s ifconfig.me'

# List defined aliases
alias

# Remove an alias
unalias gs

# Add aliases permanently
echo "alias ll='ls -lahF'" >> ~/.bashrc
source ~/.bashrc

# ---- shopt options ----
shopt -s globstar      # Enable ** for recursive globbing
shopt -s autocd        # cd by just typing directory name
shopt -s cdspell       # Auto-correct minor cd typos
shopt -s histappend    # Append to history file, don't overwrite
shopt                  # List all options and their status

# ---- Useful bash settings in ~/.bashrc ----
# HISTSIZE=10000
# HISTFILESIZE=20000
# HISTCONTROL=ignoredups:erasedups
# export EDITOR=vim
# export VISUAL=vim
# export PAGER=less