Linux alias command
The Linux alias command is used to set aliases for instructions. Users can use alias to customize command aliases.
It allows you to execute commands in a simpler and easier-to-remember way, without having to type the full command every time.
If you only enter alias, it will list all current alias settings.
The effect of alias is only valid for the current login session. If you want it to take effect every time you log in, you can.profileor.cshrcset command aliases in it.
Syntax
alias[别名]=[指令名称]
Parameter Description: If no parameters are added, all current alias settings will be listed.
Examples
1. Create an alias:
alias ll='ls -alF'
This command creates an alias namedll, which is used to display a detailed list of all files and directories in the current directory.
2. Display aliases:
alias
This command will display all aliases on the current system and their corresponding commands.
Delete an alias:
unalias ll
This command will delete the alias namedll.
3. Execute commands with root privileges:
alias sudo='sudo '
This command will create an alias namedsudo, so that you can prefix the command withsudoto execute withrootprivileges.
Note:There is a space at the end of the command because without the space, commands executed with root privileges cannot be correctly recognized.
4. Add timestamps to the history:
alias history='history | awk '"'"'{CMD="date +\"[%Y-%m-%d %H:%M:%S]\""; print CMD " " $0 }'"'"' | cut -c 29-'This command will create an alias namedhistory, which will add a timestamp when you execute the history command.
Note:
Inside the single quotes in this command, there are multiple single quotes and double quotes, which need to be properly escaped.5. Enable color output
Using the "--color=auto" parameter in the alias command allows the command to automatically enable color output on terminals that support color output, thereby improving the readability of the command line. For example:
alias ls='ls --color=auto'
This command will create a simplifiedlscommand that will automatically enable color output.
Other Extensions
Complete Linux Commands