On the setting of alias of Linux Alias

Source: Internet
Author: User

Alias

Command: Alias

Feature Description: Set the alias of the command

Syntax: alias [command]= ' other commands '

Cases:

[[email protected] data]# alias

Alias cp= ' Cp-i '

Alias l.= ' ls-d. *--color=auto '

Alias ll= ' Ls-l--color=auto '

Alias ls= ' ls--color=auto '

Alias mv= ' Mv-i '

Alias net= ' Cat/etc/sysconfig/network-scripts/ifcfg-eth0 '

Alias rm= ' Rm-i '

Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '

Description

① If the logged on user 1 wants to temporarily set an alias, user 1 only needs to perform Alias [command]= ' Other command ', the alias of this command is only valid for user 1, invalid for other users, and user 1 is valid only at that time, the next login expires;

Cases:

YONGHU1 set the alias of RM, alias is temporary valid for YONGHU1;

[[email protected] ~]$ alias rm= ' echo do not use the RM command. '

[Email protected] ~]$ RM/DATA/1.TXT.LN

Don't use the RM command. /data/1.txt.ln

[Email protected] ~]$

YONGHU2 The RM command operation, the RM alias is invalid;

[Email protected] ~]$ WhoAmI

Yonghu2

[[email protected] ~]$ rm/data/1.txt.ln "YONGHU2 the RM alias for RM,YONGHU1 settings is invalid "

Rm:remove write-protected regular file '/data/1.txt.ln '?

YONGHU1 Log off and re-login, last set RM alias is invalid

[Email protected] ~]$ Logout

[Email protected] ~]# SU-YONGHU1

[Email protected] ~]$ WhoAmI

Yonghu1

[[email protected] ~]$ rm/data/1.txt.ln "yonghu1 execute RM again, the RM alias of the last login setting expires "

Rm:remove write-protected regular file '/data/1.txt.ln '?


② If user 1 wants the alias of this login setting to be valid at the next logon, the ~/.BASHRC or ~/.bash_profile . The method is to append alias [command]= ' other command ' to ~/.BASHRC or ~/.bash_profile , and execute source ~/.BASHRC or source . ~/.bash_profile the file into effect. (change ~/.BASHRC or ~/.bash_profile only valid for the current single user, not for other users )


Here is an example of modifying ~/.BASHRC:

YONGHU1 Set RM alias in ~/.BASHRC, alias is valid for YONGHU1;

[[email protected] ~]$ echo "Alias rm= ' echo do not use the RM command." >>~/.bash

[Email protected] ~]$ tail-1 ~/.BASHRC

Alias rm= ' echo do not use the RM command. '

[Email protected] ~]$ source ~/.BASHRC

[Email protected] ~]$ RM

Don't use the RM command.

● yonghu1 re-login, RM alias to YONGHU1 still valid, long-term effective;

[Email protected] ~]$ Logout

[Email protected] ~]$ RM

Don't use the RM command.

● YONGHU2 is executing the RM command, the alias is valid for YONGHU2;

[Email protected] ~]$ RM/DATA/1.TXT.LN

Rm:remove write-protected regular file '/data/1.txt.ln '?

[Email protected] ~]$ RM

Don't use the RM command.


③ if the alias you set is valid for all users, modify the environment variable file/etc/profile or/ETC/BASHRC by appending the alias [command]= ' other commands ' to/etc/profile or/etc/ BASHRC the last row, and corresponding to the execution of the source /etc/profile or/ETC/BASHRC to make the file effective, the operation is permanent, but the general user does not have permission to modify, requires root permission.


Here is an example of modifying/etc/profile :

★YONGHU2 The command to modify/etc/profile, append RM alias to /etc/profile, no permission;

[Email protected] root]$ WhoAmI

Yonghu2

[[email protected] root]$ echo "Alias rm= ' echo do not use the RM command." >>/etc/profile

BASH:/etc/profile:permission denied

......

★ Super User root The RM alias is appended to the /etc/profile, and the RM alias is valid for permanent use in the command to modify/etc/profile.

[Email protected] ~]# WhoAmI

Root

[[email protected] ~]# echo "Alias rm= ' echo do not use the RM command." >>/etc/profile

[Email protected] ~]# tail-1/etc/profile

Alias rm= ' echo do not use the RM command. '

[Email protected] ~]# Source/etc/profile

[Email protected] ~]# RM

Don't use the RM command.

......

★ User 2 in Execute RM command , the RM alias is also in effect;

[Email protected] ~]$ WhoAmI

Yonghu2

[Email protected] ~]$ RM

Don't use the RM command.

[Email protected] ~]$

★ User re-login , and then execute the RM command again, the alias is also in effect;

[Email protected] ~]$ RM

Don't use the RM command.

[Email protected] ~]$

Description

1. /ETC/BASHRC and ~/.BASHRC difference is that/ETC/BASHRC set the equivalent of the laws, set to the whole system,~/.BASHRC is the House rules, set to single-user use;

2.the difference between/etc/profile and ~/.bash_profile is that /etc/profile Set the equivalent of the laws ofset to the whole system;~/.bash_profileis the House rules, set up for single-user use;

3, single user settings including Super User root,root settings ~/.BASHRC or ~/.bash_profile only for root;

4, as for the difference between/etc/profile and/ETC/BASHRC in later in detail, here temporarily can be considered as the laws of the same effect;

5, As for the difference between ~/.bash_profile and ~/.BASHRC in the later in detail, here can be considered as family rules, the effect of the same;



This article is from the "11277557" blog, please be sure to keep this source http://11287557.blog.51cto.com/11277557/1868370

On the setting of alias of Linux Alias

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.