Linux alias Command
The Linux alias command is used to set command aliases; users can use alias to customize command aliases.
It lets you run commands in a simpler and easier-to-remember way, without typing the full command every time.
If you enter alias alone, it lists all current alias settings.
The effect of alias lasts only for that login session; to make it effective for every login, set command aliases in .profile or .cshrc.
Syntax
alias[别名]=[指令名称]
Parameter Description: If no arguments are given, all current alias settings are listed.
Example
1. Create an alias:
alias ll='ls -alF'
This command creates an alias named ll that shows a detailed list of all files and directories in the current directory.
2. Display aliases:
alias
This command displays all aliases and their corresponding commands on the current system.
Delete an alias:
unalias ll
This command deletes the alias named ll.
3. Execute a command with root privileges:
alias sudo='sudo '
This command creates an alias named sudo so that you can, by prefixing a command with sudo, execute it with root root privileges.
**Note:** There is a space at the end of the command; without it, commands to be run with root privileges cannot be recognized correctly.
4. Add timestamps to history records:
alias history='history | awk '"'"'{CMD="date +\"[%Y-%m-%d %H:%M:%S]\""; print CMD " " $0 }'"'"' | cut -c 29-'
This command creates an alias named history that adds a timestamp when you run the history command.
** Note:** This command contains multiple single and double quotes inside single quotes, which need to be escaped correctly.
5. Enable color output
Using the "--color=auto" option with the alias command lets it automatically enable color output on terminals that support it, improving command-line readability. For example:
alias ls='ls --color=auto'
This command creates a simplified ls command that automatically enables color output.
Linux Command Reference