Bash Alias Commands in Unix

[Unix] Bash Alias Commands
:: Use ::Alias is a way to define shortcut for a command. This offers the user with a very powerful functionality to replace a command or a group of command along with options with a single character. Aliases are often used to improve the productivity by cutting down time to input long commands that are commonly used. Another useful purpose is to define a Unix native command with its Windows equivalent name as the alias. This way, Windows users who are familiar with DOS environment can use their native commands on Bash Shell. Eg. The Unix command to change directory 'cd' can be replaced with it's DOS equivalent 'chdir'.

Alias command without any options defaults to display list of all defined aliases.
$ alias
alias ..='cd ..'
alias ...='cd ../..'
alias beep='echo -en "\007"'
alias cd..='cd ..'
alias dir='ls -l'
alias chdir='cd'
alias md='mkdir -p'
alias o='less'
alias rd='rmdir'
alias unmount='echo "Error: Try the command: umount" 1>&2; false'

:: [How To] Define an Alias ::alias name=value
alias name='command'
alias name='command arg1 arg2'
alias name='/path/to/script'
alias name='/path/to/ arg1'

:: [How To] Disable an Alias ::$ unalias aliasname

:: Example ::A useful example would be to replace the 'clear' command to clear the screen with an alias 'c'. Simple, short and quick !!
$ alias c='clear'Now to diable the alias, use the following comand.
$ unalias c

Another simple and quick way is to press CTRL+L .

:: Handy Must-Have Alias Commands ::
## a quick way to get out of current directory ##
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'

## handy short cuts ##alias h='history'
alias j='jobs -l'
alias c='clear'
alias d='pwd'
alias w='who'
alias now='date'

## resume wget by default ##
alias wget='wget -c'

It's your turn to share... :)

No comments :

Post a Comment