Skip to content

Instantly share code, notes, and snippets.

@petdance
Created July 27, 2025 22:28
Show Gist options
  • Save petdance/6a538d03d9c72f803d6fbbfef5505b0d to your computer and use it in GitHub Desktop.
Save petdance/6a538d03d9c72f803d6fbbfef5505b0d to your computer and use it in GitHub Desktop.
Set up ls aliases in my bash startup
# Prefer using eza for my big five ls aliases. If it's not there, then check
# to see if we're on macOS which has different ls flags than Linux's ls.
# Finally, assume we're using Linux.
# From https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
if hash eza 2>/dev/null ; then
base='eza -F -B -g --smart-group --git --no-quotes'
alias ls="$base"
alias ll="$base -l"
alias la="$base -l -aa" # The -aa is intentional.
alias lt="$base -l --sort=newest"
alias ltr="$base -l --sort=oldest"
unset base
elif [[ $OSTYPE =~ ^darwin ]] ; then
base='ls -GF'
# Mac has -G for color.
alias ls="$base"
alias ll="$base -l"
alias la="$base -l -a"
alias lt="$base -l -t"
alias ltr="$base -l -t -r"
unset base
else
base='ls --color=auto -F'
alias ls="$base"
alias ll="$base -l"
alias la="$base -l -A"
alias lt="$base -l -t"
alias ltr="$base -l -t -r"
unset base
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment