Describes how to set alias in linux and how to fix the failure after the alias command is restarted.

Source: Internet
Author: User

How to set up alias in linux

Setting alias in centos is relatively simple, for example:

Vim/root/. bashrc

Sample code:

Add
Alias rm = 'rm-I'

Detailed description of alias commands for setting commands in Linux alias

Function description: sets the alias of an instruction.
Syntax: alias [alias] = [command name]
Note: You can use alias to customize the alias of the command. If you only enter alias, all current alias settings can be listed. Alias is valid only for this login operation. To automatically set the alias for each login, you can set the alias for the command in. profile or. cshrc.
Parameter: If no parameter is added, all alias settings are listed.

Linuxalias and settings

I. INTRODUCTION

Linux alias is a command alias.

Alias

The output result is as follows:

Alias vi = "vim"

After entering vi, it is automatically directed to the vim command.
Alias is short for commands.

II. Modify alias

Add your own alias. Format:

Alias la = "ls-al -- color = auto"

3. Modify the configuration file

The preceding setting method of the alias command fails after the user exits.
You can modify the configuration file to make it take effect automatically every time.
To modify the user's own alias (not all users), you can modify ~ /. Bashrc file

Vii ~ /. Bashrc

Add custom alias at the end, for example:

Alias la = "ls-al -- color = auto"

This modification takes effect the next time you log on.

To take effect immediately, you can do this:

Source ~ /. Bashrc

4. Common alias

Set alias as needed.

4. You can modify the global alias by modifying the system configuration file.

Alias definition provided by CentOS5.6

Note: to cancel an alias, add \ before the command, for example, \ mkdir.
 

Root@jbxue.com ~ # Alias
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'

Some systems do not have the ll command because the ll = 'ls-l -- color = tty 'alias is not defined. You can use alias to convert a long command into any short command.

Set and modify the alias command alias format:

Alias ll = 'ls-l -- color = tty'
 
If it takes effect permanently, you can write the settings to the/etc/bashrc file.



Linux system failure after setting the alias command to restart

In most cases, linux is used on the character interface. We do not want to repeat some long commands every time, which is not only a waste of time but also prone to errors. We will use the alias command to solve this problem.

For example:

Alias ll = 'ls-l -- color'

In this way, we can directly enter ll to replace this long string or longer command.

However, in this case, it will expire after restart. The solution is to edit it ~ /. Bashrc file

Vim ~ /. Bashrc

Add an alias command to each line. For example:

Alias ll = 'ls-l -- color'
Alias la = 'ls-'
Alias cdhome = 'CD ~ '
Alias cdroot = 'CD /'

After wq saves the file, run:

Source ~ /. Bashrc

(Otherwise it will not take effect)

If not, it means no ~ /. Bash_profile file, or the. bashrc file is not executed in the file.

(The. bash_profile file is automatically executed when you log on to the terminal. It is generally called. bashrc)

If so, open the file (if not, create it first:

~ /. Bash_profile

Add a line to it:

Source ~ /. Bashrc

OK.

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.