Saturday, April 9, 2016

Unix: Alias

As the name suggests Alias is another/alternate name for a command or group of commands.
To know the aliases currently, just type alias at the prompt and hit enter

hadoop@ubuntu:~$ alias

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'


The above gives the list of aliases that we currently have in the system. 
To create an alias, 
hadoop@ubuntu:~$ alias ll='ls -lrt'

hadoop@ubuntu:~$ ll
total 224
-rw-r--r--  1 hadoop hadoop  8445 Feb 21  2015 examples.desktop
drwxr-xr-x  2 hadoop hadoop  4096 Feb 21  2015 Videos
drwxr-xr-x  2 hadoop hadoop  4096 Feb 21  2015 Templates
drwxr-xr-x  2 hadoop hadoop  4096 Feb 21  2015 Public
drwxr-xr-x  2 hadoop hadoop  4096 Feb 21  2015 Music
-rw-rw-r--  1 hadoop hadoop 14904 Feb 22  2015 pig_1424592579651.log
-rw-rw-r--  1 hadoop hadoop 11738 Feb 23  2015 pig_1424676723694.log
-rwxrwxr-x  1 hadoop hadoop     6 Mar  1  2015 cls


Notice that there shouldn't be any space between the = while setting up the alias.
 













No comments:

Post a Comment