Linux system setting command alias

  
Recently, a Django site needs to enter the /var/www/site/mycitsm/directory frequently. Every time you have to enter this long string of paths into the directory, it is troublesome and time consuming. Is there any? A good way to get an alias like "cd /var/www/site/mycitsm”", you only need to enter the alias to enter the directory. Fortunately, the Linux system provides a useful tool called alias, which allows us to set an alias for some commands that need to be used frequently but are too lengthy, so that you can achieve the same by entering a short alias in the future. effect. Usage:alias [-p] [name[=value] ... ] Note that ‘=’ and strings cannot contain spaces between the currently set aliases: shell>alias -palias 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 type: shell>alias -palias 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, you can type alias name, for example: shell> alias llalias ll= 'ls -l --color=tty' If you want to set an alias for a command, you can type alias new command = 'original command option /parameter', for example: shell>alias site='cd /var/www/site/mycitsm/'If you want to cancel an alias, you can enter the unalias name, such as shell>unalias site. However, there is a problem with the above setting method, that is, the set command alias is only valid for the current callback. Once the connection is disconnected and reconnected, the previously set alias is not present. effective. The alias can be persisted by writing a command to set the alias into the startup file. Most Linux distributions use one of the following three startup files: $HOME/.bash_profile$HOME/.bash_login$HOME/.profile to write the command to set the alias into the startup file, so that each time you connect to the system The alias will take effect. If you want to apply the source command immediately after the command is written to the startup file, remember to execute the source command, for example: source $HOME/.bash_profile. Set the command alias in the above way to solve the problem that the command alias only works for the callback, but it is written into each user-specific The command alias in the startup file under the home directory is only valid for this user. It has no effect on other users, which is usually what you would expect to see under normal circumstances. However, if you do make the set alias valid for any user, you can write the command to set the alias into the global startup file, such as /etc/profile.
Copyright © Windows knowledge All Rights Reserved