100 Useful Command-Line Utilities
by Oliver; 201453. alias, unalias
As mentioned in An Introduction to the Command-Line (on Unix-like systems) - Aliases, Functions, aliasing is a way of mapping one word to another. It can reduce your typing burden by making a shorter expression stand for a longer one:
alias c="cat"
This means every time you type a c the terminal is going to read it as cat, so instead of writing:
$ cat file.txtyou just write:
$ c file.txtAnother use of alias is to weld particular flags onto a command, so every time the command is called, the flags go with it automatically, as in:
alias cp="cp -R"
or
alias mkdir="mkdir -p"
Recall the former allows you to copy directories as well as files, and the later allows you to make nested directories.
Perhaps you always want to use these options, but this is a tradeoff between convenience and freedom.
In general, I prefer to use new words for aliases and not overwrite preexisting bash commands.
Here are some aliases I use in my setup file:
# coreutils alias c="cat" alias e="clear" alias s="less -S" alias l="ls -hl" alias lt="ls -hlt" alias ll="ls -al" alias rr="rm -r" alias r="readlink -m" alias ct="column -t" alias ch="chmod -R 755" alias chh="chmod -R 644" alias grep="grep --color" alias yy="rsync -azv --progress" # remove empty lines with white space alias noempty="perl -ne '{print if not m/^(\s*)$/}'"
# awk alias awkf="awk -F'\t'" alias length="awk '{print length}'" # notesappend, my favorite alias alias n="history | tail -2 | head -1 | tr -s ' ' | cut -d' ' -f3- | awk '{print \"# \"\$0}' >> notes"
# HTML-related alias htmlsed="sed 's|\&|\&\;|g; s|>|\>\;|g; s|<|\<\;|g;'"
# git alias ga="git add" alias gc="git commit -m" alias gac="git commit -a -m" alias gp="git pull" alias gpush="git push" alias gs="git status" alias gl="git log" alias gg="git log --oneline --decorate --graph --all" # alias gg="git log --pretty=format:'%h %s %an' --graph" alias gb="git branch" alias gch="git checkout" alias gls="git ls-files" alias gd="git diff"To display all of your current aliases:
$ aliasTo get rid of an alias, use unalias, as in:
$ unalias myalias