Raspberry Pi_Eng_10.4.4 “alias” Command


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


10.4.4  "alias" Command

 

On Linux, there is a feature that allows you to specify an alias name for a certain string in advance, and then use the defined alias name later instead of the string. The command to use at this time is the "alias" command.

 

[Command Format]

alias <alias-name>[='<value>']

 

[Command Overview]

   This assigns aliases to specified strings in advance and makes it available freely instead of the string afterward.

   User privilege          -- Normal user.

 

[Detail Description]

   If no special parameters are specified, the list of currently defined aliases is displayed.

 

To remove a defined alias, use the "unalias" command.

 

[Command Format]

unalias <alias-name>

 

[Command Overview]

   This deletes the pre-defined alias.

   User privilege          -- Normal user.

 

[Used Example]

 

pi@raspberrypi3:~ $ alias

alias egrep='egrep --color=auto'

alias fgrep='fgrep --color=auto'

alias grep='grep --color=auto'

alias ls='ls --color=auto'

 

 

 

Below is to define "dirlist" as alias for the command "ls -l"'. After you define it, you can see that the commands defined for the "dirlist" are executed by running "dirlist" as a normal command. If you can also check the list of alias definitions, you can see that there is a definition for "dirlist".

 

pi@raspberrypi3:~ $ alias dirlist='ls -l'

pi@raspberrypi3:~ $ dirlist

total 48

-rw-r--r-- 1 pi pi    0 Jun 14 06:42 =

-rw-r--r-- 1 pi pi    3 Jun 14 06:51 11

-rw-r--r-- 1 pi pi    2 Jun 14 06:42 6

drwxr-xr-x 2 pi pi 4096 May 27 11:40 Desktop

drwxr-xr-x 5 pi pi 4096 Jun 13 12:46 Documents

drwxr-xr-x 2 pi pi 4096 Jun 17 06:52 Downloads

drwxr-xr-x 2 pi pi 4096 May 27 11:50 Music

drwxr-xr-x 2 pi pi 4096 May 27 11:50 Pictures

drwxr-xr-x 2 pi pi 4096 May 27 11:50 Public

drwxr-xr-x 2 pi pi 4096 Jun 13 12:47 python_games

drwxr-xr-x 2 pi pi 4096 May 27 11:50 Templates

drwxr-xr-x 2 pi pi 4096 Jun 24 05:49 Test

drwxr-xr-x 2 pi pi 4096 May 27 11:50 Videos

pi@raspberrypi3:~ $ alias

alias egrep='egrep --color=auto'

alias fgrep='fgrep --color=auto'

alias grep='grep --color=auto'

alias dirlist='ls -l'

alias ls='ls --color=auto'

 

The following is an example of deleting the alias definition for the "dirlist" with the "unalias" command. After deleting the alias definition, you can see that an error occurs when you execute the "dirlist" command.

 

pi@raspberrypi3:~ $ unalias dirlist

pi@raspberrypi3:~ $ dirlist

-bash: dirlist: command not found