1.8 using Aliases
- aliases in Linux are the equivalent of shortcuts in Windows, and using aliases can save users from having to enter a long sequence of commands.
1.8.1 Creating temporary aliases (shortcuts)
alias new_command=‘command sequence‘#格式说明alias install=‘sudo apt-get install‘#实例说明
- After declaring install= ' sudo apt-get install ', you can use the install instead of ' sudo apt-get install '. Aliases declared in this way are only temporary, and once the terminal is closed, all settings are invalidated, and a permanent valid alias can be declared using the following method.
1.8.2 Creating a permanent alias (shortcut)
echo‘alias cmd="command sequence"‘>>~/.bashrc #格式说明echo‘alias install="sudo apt-get install"‘#实例说明
- Note: command sequence uses double quotation marks, and single quotation marks do not work correctly.
1.8.3 Deleting aliases (shortcuts)
- For temporary aliases, you can use the following method to remove
command #格式说明unalias install #实例说明aliascommand= #格式说明alias install #实例说明
- Note: The second method described above is actually the alias that was created after overwriting the alias with the same name.
the hidden dangers of 1.8.4 aliases
- Alias commands can be used to create aliases for any important command, but the alias command is not always secure. The description is as follows:
aliasls=‘command suquence‘ #使用ls作为其他命令的别名ls #执行command suquence\ls #执行原来的ls命令
- The above approach is dangerous, when LS is used as an alias for other commands, the previous LS command is overwritten, of course, this overlay is temporary, and if you want to execute the original LS command, you need to escape the LS command by adding the escape character \. in other words, an attacker could use an alias to disguise an attack instruction as a normal instruction, and the user does not know it to steal information.
1.8.5 Reference
- Linux Shell Script Raiders
Linux Shell Script Raiders (1.8)