Linux: alias takes effect permanently

alias (known as "alias" in Chinese) allows the use of shorter names to redefine shell commands in Linux, thereby simplifying command line input.

If you're dealing with the CLI a lot, using aliases not only saves time, but also increases efficiency, which is a good thing to kill two birds with one stone.

Basic usage: The basic usage of alias is: alias new command='original command-option/parameter'. For example, alias l='ls -lsh' will redefine the ls command, and now just type l to list the directory.
Knowing aliases: Entering the alias command directly will list all defined command aliases in the current system.
Deleting an alias: To delete an alias, use the unalias command, such as unalias l.

The above method is only temporary. If it is restarted once, it will be invalid. What if we want to make a command take effect permanently?

Open .bashrc (it should be of ubuntu distribution, other distributions may modify .bash_profile) to see
...
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l=' ls -CF'
...
Method 1: Add alias xx='xxxxx' directly in our environment variable file
Method 2: There is a sentence in .bashrc
# You may want to put all your additions into a separate file like
# ~/ .bash_aliases, instead of adding them here directly.
That is to say, you can create a new file to store your own alias information. For
example,
  $ cd
  $ vi .bash_aliases
  Enter the command you want to set in the file alias rm='rm -i' and then save rollout

  $ source .bashrc #Make our environment effective

for example:

alias ls='ls -ltr'
alias cat='nohup $CAT/start_navicat &'
alias db='mysql -uroot -proot'

......

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324127689&siteId=291194637