Command alias in Linux

Source: Internet
Author: User
The command alias function of a Linux system the command alias function will use a large number of commands during the management and maintenance of the Linux system, and some long commands or usage are often used, repeated and frequent input of a long command or usage is not advisable. In this case, you can use the command alias function... the command alias function of the Linux system the command alias function will use a large number of commands in the process of managing and maintaining the Linux system, and some long commands or usage are often used, repeated and frequent input of a long command or usage is not advisable. In this case, you can use the command alias function to simplify the process. 1. the alias defined by the system usually has some command aliases defined in the system. to view the alias defined by the command, you can use the alias command: # The alias command will output all the defined command aliases
# Alias cp = 'CP-I 'alias l. = 'ls-d. * -- color = tty 'Alias ll = 'ls-l -- color = tty 'Alias ls = 'ls -- color = tty 'Alias mv = 'MV-I 'alias rm =' rm-I 'Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde'
From the above results, we can see that when we use the command cp (Copy File command), the system will replace the cp in the command with cp-I. In addition, the ls command and its color, the music command for moving files, and the command for deleting rm are also defined. Files used to set the system alias are saved in/etc/profile. d/Directory (system alias directory), you can view it in the following way: www.2cto.com # enter the directory/etc/profile. d/# cd/etc/profile. d/# View files in the directory # ls colorls. csh glib2.sh krb5-workstation.csh lang. sh vim. csh colorls. sh gnome-ssh-askpass.csh krb5-workstation.sh less. csh vim. sh glib2.csh gnome-ssh-askpass.sh lang. csh less. sh which-2.sh # view the file less. csh content # cat less. csh # less. csh content, which defines the alias of the ls command, such as the color # less initialization SC Ript (csh) if (-x/usr/bin/lesspipe. sh) then setenv LESSOPEN "|/usr/bin/lesspipe. sh % s "endif # cat colorls. sh # color-ls initialization alias ll = 'ls-L' 2>/dev/null alias l. = 'ls-d. * '2>/dev/null ...... 2. custom aliases in many cases, administrators define command aliases according to their usage habits. For example, make the command to view the content of the current file compatible with the command to view the text in DOS type: # define an alias for the cat command # alias type = 'cat' then use the typecommand to access the contents of the alias.txt file # type alias.txt alias l. = 'ls-d. * -- color = tty 'Alias ll = 'ls-l -- color = tty 'Alias ls = 'ls -- color = tty 'Alias vi = 'vim 'alias which = 'Alias | /usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde 'in the command above, first, a type alias is defined for the cat command. When you use the command type, the system automatically uses the cat command to replace it. Www.2cto.com
3. to cancel a defined alias, you can use the unalias command: # unalias type # type alias.txt-bash: type: command not found 4. save alias settings when the system restarts or the user logs on again, the alias defined by the alias command will be lost. You can add an alias configuration file to the system alias Directory. However, aliases defined in this way take effect for all users. this method is not recommended. To define a global alias, we recommend that you add the command to the global configuration file/etc/profile. For example, to define a global alias: # echo "alias type = 'cat'">/etc/profile, add alias pg = 'cat' to the file/etc/profile. Note: Be cautious when operating system configuration files such as/etc/profile. Otherwise, the system may be damaged. Therefore, the preceding command uses ">" instead of ">", ">" to append the content to the end of the file. If you want to define your own command alias, you can add the command to the file. bash_profile in the user's home directory. For example, to define your own alias: # echo "alias vi = 'vim '" >> ~ /. Bash_profile
This article is from the fat shark network.
Related Article

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.