Recently engaged in a Django site, need to often enter the/var/www/site/mycitsm/directory, each time to repeat the input of this long path into the directory, it seems troublesome and time-consuming, there is no good way to "cd/var/www/site/ MYCITSM "Such a command takes an alias, you can enter the directory at a time by just entering the alias?"
Thankfully, the Linux system provides a useful tool called Alias, which allows us to set an alias for a number of commands that need to be used frequently but too long, so that you can do the same with just typing a short alias later.
Usage: alias [P] [Name[=value] ...] note ' = ' and string cannot contain spaces
Displays the alias for the current setting:
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 directly:
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 want to show only what an alias represents, enter alias name, for example:
Shell>alias LL
Alias ll= ' Ls-l--color=tty '
If you want to set an alias for a command, enter the alias new command = ' original command options/parameters ', such as:
Shell>alias site= ' cd/var/www/site/mycitsm/'
If you want to cancel an alias, enter Unalias name, such as
Shell>unalias site
However, there is a problem with the above setup method, which is that the command alias set is valid only for the current reply, and that the alias set before the connection is disconnected and connected is not valid.
The alias can be persisted by writing the alias-setting command into the startup file. Most Linux distributions use one of the following three startup files:
$HOME/.bash_profile
$HOME/.bash_login
$HOME/.profile
You can write an alias-setting command into the startup file so that the alias will take effect each time you connect to the system. If you want to take effect immediately after the command is written to the startup file, remember to execute the source command, such as:
SOURCE $HOME/.bash_profile
Setting the command alias in this manner solves the problem that the command alias is only valid for reply-to, but the command alias in the startup file that is written in each user-specific home directory is available only for that user. has little effect on other users, which is usually what you expect to see in normal circumstances. However, if you do like to make a set alias valid for any user, you can write the alias-setting command into the global startup file, such as/etc/profile.