"Linux Command Details" 11, command alias-[Alias/unalias]

Source: Internet
Author: User
Tags aliases egrep

11, Alias/unalias

You can use the alias command to define an alias for a command, and if there are spaces in the command, you need to use double quotation marks (such as spaces between commands and options), and use the Unalias command when the user needs to cancel the alias definition.

11.1.1 Command syntax:

alias[alias]=[command to define aliases]

unalias[aliases]

11.1.2 instances:

Example 1: Creating an alias for the ls-l/boot command OK

[email protected] ~]# alias ok= "ls-l/Boot"

[[Email protected] ~]# OK

Total Dosage 87680
-rw-r--r--. 1 root root 123838 March 6 config-3.10.0-229.el7.x86_64
Drwxr-xr-x. 2 root root 26 July 11:36 Grub
Drwxr-xr-x. 6 root root 104 July 11:42 grub2
-rw-r--r--. 1 root root 39838267 July 11:40 initramfs-0-rescue-f9d368323f0740ecb329cccb5f1ce994.img
-RW-------. 1 root root 17944583 July 11:42 initramfs-3.10.0-229.el7.x86_64.img
-RW-------. 1 root root 18088584 July 11:49 initramfs-3.10.0-229.el7.x86_64kdump.img
-rw-r--r--. 1 root root 589709 July 11:39 initrd-plymouth.img
-rw-r--r--. 1 root root 240039 March 6 symvers-3.10.0-229.el7.x86_64.gz
-RW-------. 1 root root 2881257 March 6 system.map-3.10.0-229.el7.x86_64
-rwxr-xr-x. 1 root root 5029136 July 11:40 vmlinuz-0-rescue-f9d368323f0740ecb329cccb5f1ce994
-rwxr-xr-x. 1 root root 5029136 March 6 vmlinuz-3.10.0-229.el7.x86_64

Enter the alias in the terminal OK to view the contents of the/boot directory

Example 2: Viewing all aliases in the system

[[email protected] ~]# alias
Alias cp= ' Cp-i '
Alias egrep= ' Egrep--color=auto '
Alias fgrep= ' Fgrep--color=auto '
Alias grep= ' grep--color=auto '
Alias l.= ' ls-d. *--color=auto '
Alias ll= ' Ls-l--color=auto '
Alias ls= ' ls--color=auto '
Alias mv= ' Mv-i '
Alias ok= ' ls-l/boot '
Alias rm= ' Rm-i '
Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '

Example 3: Canceling a previously defined alias OK

[[email protected] ~]# Unalias OK
[[Email protected] ~]# OK
-bash:ok: Command not found

Attention:

After restarting the computer system and the terminal, the defined aliases are invalidated. If there is a command in the system and you define an alias with the same name, the alias will take precedence over the execution of the commands in the system.

If you want to restart the computer system and then close the terminal, the defined alias will still be valid, you can edit the/ETC/BASHRC (for all users in the system) or $HOME/.BASHRC (for a specified user, $HOME on behalf of the user home directory) file, Write the alias definition command to these two files.

"Linux Command Details" 11, command alias-[Alias/unalias]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.