What is an alias
In the process of managing and maintaining a Linux system, a large number of commands will be used, and some long commands or usages are often used, and it is undesirable to repeatedly and frequently enter a very long command or usage. You can use the alias feature to simplify the process.
Some of the commands under the Linux system, such as the RM CP MV, and so on, should be used with caution or by setting aliases to make some reminders in disguise.
Simply put,
1. Warning before using dangerous commands CP RM MV
2. More convenient use of complex commands
Issue: Configure the alias for RM do not use RM to run the RM command when the system prompts do not use RM.
1. Separate the command that you want to output does not use RM to the screen interface for Echo
[[Email protected] ~] # echo " do not use RM" not ~]#
2. See aliases that already exist
[[Email protected] ~]#aliasAlias cp='cp-i'alias L.='ls-d. *--color=auto'alias LL='ls-l--color=auto'alias ls='ls--color=auto'alias MV='mv-i'alias RM='rm-i'alias which='alias |/usr/bin/which--tty-only--read-alias--SHOW-DOT--show-tilde'
3.1 Configuring an alias for RM do not use RM
[[Email protected] ~] # alias rm= ' echo do not use RM '
Note: = no spaces on both sides enter characters directly
3.2 Check
[[Email protected] ~]#aliasAlias cp='cp-i'alias L.='ls-d. *--color=auto'alias LL='ls-l--color=auto'alias ls='ls--color=auto'alias MV='mv-i'alias RM='echo do not use RM'alias which='alias |/usr/bin/which--tty-only--read-alias--SHOW-DOT--show-tilde'[[Email protected]~]#Rm/data/oldboy.txtDo notUse rm/data/Oldboy.txt[[email protected]~]#
Note Now that the alias has been successfully configured but is limited to this connection Xshell the connection or the system reboot, the alias becomes invalid.
4.1 make the configured alias valid permanently
[[Email protected] ~] # Vim/etc/profile
The VIM editor below the G means that directly to the bottom O (lowercase o) indicates another line below the current line
After entering vim, directly press the capital G and then press the lowercase o
Enter the following command to ensure that the lowest end can be
# #alias rm='echodo not use RM'
4.2 Check whether the input succeeds with tail output the last two lines of the file
[[Email protected] ~] # Tail-2/etc/profile # #alias rm='echodo not use RM'~]#
5. Let the configuration take effect source
[[Email protected] ~] # Source/etc/profile [[Email protected] ~] # not use rm/data/~]#
6. Modify/ROOT/.BASHRC
[[Email protected] ~] # VIM/ROOT/.BASHRC # alias rm= ' Rm-i 'alias cp='cp-i'alias mv='MV -I.'
Add alias rm= ' Rm-i ' to the front and then exit Vim and save as shown above
7.rm How to remove something under alias status
7.1 The state of the RM is now used directly
[[Email protected] ~] # not use rm/data/~]# no use rm-f/data/~]# not use rm-r/data/~]#
Cannot delete files directly using RM
7.2 How to delete a file
Method One
[[Email protected] ~] #
\ indicates temporary cancellation of aliases
Method Two
[[Email protected] ~] # which RM [[Email protected] ~] #
Which RM can view the absolute path of the RM command
Must be! Linux systems configure aliases for commands