This article mainly introduces how to set command alias in linux. For more information, see
Recently, a Django site needs to frequently enter the/var/www/site/mycitsm/Directory. it is troublesome and time-consuming to enter this long string of paths each time, is there a good way to get an alias for a command such as "cd/var/www/site/mycitsm". every time you just enter this alias, you can enter this directory?
Fortunately, the Linux system provides a useful tool called alias, which allows us to set an alias for frequently used but overly lengthy commands, in the future, you only need to enter a brief alias to achieve the same effect.
Usage: alias [-p] [name [= value]...] note that '=' and the string cannot contain spaces.
Display the alias currently set:
Shell> alias-p
Alias l. = 'ls-d. * -- color = tty'
Alias ll = 'ls-l -- color = tty'
Alias ls = 'ls -- color = tty'
Alias vi = 'vim'
Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde'
Or enter:
Shell> alias-p
Alias l. = 'ls-d. * -- color = tty'
Alias ll = 'ls-l -- color = tty'
Alias ls = 'ls -- color = tty'
Alias vi = 'vim'
Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde'
If you only want to display the meaning of an alias, enter alias name, for example:
Shell> alias ll
Alias ll = 'ls-l -- color = tty'
To set an alias for a command, enter the new alias command = 'original command options/parameter', for example:
Shell> alias site = 'CD/var/www/site/mycitsm /'
To cancel an alias, enter the unalias name, for example
Shell> unalias site
However, there is a problem with the preceding setup method, that is, the configured command alias is only valid for the current session. the alias set before the connection is disconnected and reconnected is not valid.
You can write the alias setting command into the startup file to make the alias take effect permanently. Most Linux distributions use one of the following three startup files:
$ HOME/. bash_profile
$ HOME/. bash_login
$ HOME/. profile
You can write the command for setting aliases into the startup file, so that the alias will take effect every time you connect to the system. If you want to take effect immediately after the command is written to the startup file, execute the source command, for example:
Source $ HOME/. bash_profile
The preceding command alias settings solve the problem that the command alias only takes effect for calls. However, the command alias written into the startup file of a specific user's main directory is only valid for this user. It has no effect on other users, which is usually expected under normal circumstances. However, if the configured alias is valid for any user, you can write the alias setting command into the global startup file, such as/etc/profile.