Command aliases alias settings

Source: Internet
Author: User

< turn:http://vbird.dic.ksu.edu.tw/linux_basic/0320bash_3.php>

Command alias configuration: Alias, Unalias

Command aliases are a very interesting thing, especially when your commands are very long! Also, add the default options to some of the usual commands, you can prevent some careless manslaughter files when the situation occurs! For example, if you want to query the hidden file, and need a long list and page by page, then need to release " Ls-al | more" This command, I feel very annoying! To enter several words! Can you use LM to simplify it? Of course, you can release it at the command line:

Alias lm= ' Ls-al | More

There's an extra command to run right now! This command name is LM, and in fact he is running Ls-al | More Ah! It's convenient. However, it is important to note that the "Alias definition code is almost identical to the variable definition code", so you just add your {"alias" = ' command option ...} after alias, so you just enter LM to enter the Ls-al|more command! Very convenient!

In addition, the configuration of command aliases can also replace the existing commands Oh! For example, we know that root can remove any data from (RM)! So when you are working as root, you need to be very careful, but there are always misses, then RM provides an option to let us know if we want to remove the file, which is the-i option! So, you can do this:

Alias rm= ' Rm-i '

Then use RM later, you do not have to worry about the mistake of deleting the situation! This is also the advantage of command aliases! So how do you know what the command aliases are now? Just use alias!

Aliasalias cp= ' cp-i ' Alias l.= ' ls-d. *--color=tty ' Alias ll= ' Ls-l--color=tty ' Alias lm= ' ls-l | More ' Alias ls= ' ls--color=tty ' alias mv= ' mv-i ' Alias rm= ' rm-i ' Alias Which= ' Alias | /usr/bin/which--tty-only--show-dot--show-tilde '

From the above data, you will also find a thing ah, we in the tenth chapter of the VIM program editor mentioned VI and Vim is not quite the same, vim can do some additional grammar test and color display, the default root is simply using VI. If you want to use VI to open the file directly with VIM, use the " alias vi= ' vim ' " configuration. If you want to cancel the command alias, then use Unalias! For example, to remove just the LM command alias, use:

Unalias LM

So what is the difference between a command alias and a variable? The command alias is "New Create a new command, you can release the command directly", as for the variable you need to use a similar "echo" command to be able to call out the contents of the variable! Of course the two are different! Many beginners here are always confused! Be careful! ^_^

Example: The DOS age, listing directories and files is dir, and clearing the screen is CLS, so what if I want to use the same command in Linux? A: It is simple to create a command alias via clear and LS:
alias cls= ' Clear '
Alias dir= ' Ls-l '

Command aliases alias settings

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.