alias
Define or display aliases.[1]
Documentation
- alias [EN] @ GNU Bash Reference Manual
- bash -c 'help alias'
- man 1 'bash' [EN]
Syntax
alias -p
alias [NAME[=COMMAND] ...]
Parameters
- -p
- Prints the list of all aliases.
Examples
- Define aliases for directory listing
if type -P 'eza' >'/dev/null' 2>&1; then # eza
alias ls="eza --classify --time-style='long-iso'"
alias ll='ls --git --group --header --long'
alias l='ll --all --all'
else
if ls --context >'/dev/null' 2>&1; then # GNU ls version
alias ls="ls --classify --color --time-style='long-iso'"
if type -P 'dircolors' >'/dev/null' 2>&1; then
eval "$(dircolors -b)"
fi
else # other ls versions
alias ls="ls -D '%F %T' -F -G"
fi
alias ll='ls -h -l'
alias l='ll -a'
fi
alias lr='l -R'
alias lt="l -r -s 'time'"
alias lt="l -r -s 'time'"
if df -T >'/dev/null' 2>&1; then # GNU df version
alias df='df -h -T'
else # other df versions
alias df='df -h'
fi
alias du='du -h'
my::_cd() {
# Provide a 'cd' command replacement using 'pushd'.
#
# Arguments:
# $1: Path (optional)
#
# Returns:
# 0: Success
# >0: Error
if [[ "$#" -eq 0 ]]; then
set -- "${HOME}"
fi
if [[ ! -d "$1" ]]; then
echo "Error finding directory: $1!"
return 1
fi
if ! pushd "$1" >'/dev/null' 2>&1; then
echo "Error changing directory: $1!"
return 1
fi
return 0
}
alias -- -='popd >"/dev/null" 2>&1'
if declare -F my::_cd >'/dev/null' 2>&1; then
alias cd='my::_cd'
fi
- Get env sorted
alias env='env | sort -f'
References
- ↑ bash -c 'help alias'