How do i make Linux user-defined command alias permanent?

Source: Internet
Author: User
Tags aliases

alias(Chinese is called"aliases"allows a shorter name to be used to redefineLinuxin theShellcommand, which simplifies the input of the command line. If often withCLIdeal with, then usealiasnot only will save time, but also can improve efficiency, really double benefit good.

???? * Basic usage:? AliasThe basic use of this method is:aliasthe new command= 'Original Command -Options/Parameters'. For example,alias l= ' Ls-lsh 'will be redefinedlscommand, now just enterLYou can list the list.
???? * Learn about aliases:Direct Inputaliascommand lists all of the command aliases that are already defined in the current system.
???? * To Delete an alias:to delete an alias, you can use theUnaliascommands, such asUnalias L.

The above is seen on the Internet, this method is only temporary, if the restart is not valid, if we want to have a permanent effect of a command to do?

Open. BASHRC(It should beUbuntudistributions, other distributions may be modified. Bash_profile) can see

......

# some more LS aliases

Alias Ll= ' Ls-alf '
Alias La= ' Ls-a '
Alias l= ' LS-CF '

......

Method1: Directly in ourthe environment variable file is addedalias xx= ' xxxxx '

Method2??:. BASHRCin a word

# want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.

This means that you can create a new file to store your ownaliasInformation

Example

$CD

$VI. bash_aliases

Enter the command you want to set in the file?? Alias rm= ' Rm-i '??then save the launch

$source. BASHRC??? #Let our environment take effect

Method...----------------------Please note that the actualcentos5TestThe discovery should be. BASHRC

Summary:??

1.many times we only pay attention to solve the problem itself, but often ignore the other things, in the process of solving the problem is also a learning opportunity, especially don't forget to read the software source and other comments! Suddenly found this is very important, because I read the comments, I found this method, and my original purpose is to set my own environment variables to modify, in solving the problem of environmental variables at the same time I have to solve thisaliasthe question, in the future to remember!!!

2.when looking for solutions on the Internet, it is often found that other files are not available on the computer, for example. BASHRCand the. bash_profile??may be on different distributions, this time you can change the search method, or try...
category: Ubuntu

Http://www.cnblogs.com/jjyoung/archive/2011/07/15/2107788.html


If this is the currentsession
used byLinuxOrder ofAlias-sets the alias of the command so thatLinuxcommand More concise

This article links:http://codingstandards.iteye.com/blog/1145318??? (reproduced Please specify the source )


use to be clear

sets the alias of the command. In theLinuxif the command is too long and does not conform to the user's habits, then we can specify an alias for it. Although you can create a command"links"resolves a long file name problem, but for commands with command-line arguments, the link is powerless. The specified alias can resolve all such problems "1". Common aliases to simplifySSHlog in to "see example three" to make the long command shorter, to shorten the usual long command line, to enforce the command when asked, and so on.


Common Parameters

format:Alias

format:alias-p

Displays the alias of the current setting.



format:alias name= ' command line '

sets the alias.



format:Alias Name

Displays the specified alias settings.



format:Unalias Name

cancels the specified alias setting.


using the example
Example OneSolverhel5/centos5underVIproblems that cannot be highlighted in syntax

in the/etc/profilethe end of the addVIthe alias Settings



Alias vi= "Vim"


showing twoDisplays the current alias settings

[[email protected] ~]# 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 '
[[email protected] ~]# alias CP
Alias cp= ' Cp-i '
[email protected] ~]#


example ThreeSSHaliases

SSHaliases-alias Server_name= ' Ssh-v-l USERNAME IP address ', Changeserver_name,USERNAMEandIPaddress to suit your needs. For frequently usedSSHLog on remotelyShellstudents, this is a worthy of the collection of aliases.



[[email protected] ~]# alias 180= ' ssh 192.168.1.180 '
[[email protected] ~]# 180
Ssh:connect to host 192.168.1.180 Port 22:no route to host
[[email protected] ~]# alias 181= ' ssh 192.168.1.181 '
[[email protected] ~]# 181
[email protected]' s password:

[email protected] ~]#


example FourCommon alias Settings collection

Alias l= "Ls-l"

Alias ll= "Ls-l"



Alias lm= ' Ls-al | More


SimulationDOSstyle of command

Alias Clr=clear
alias Cls=clear
alias copy= ' Cp-i '
alias del= ' Rm-i '
alias delete= ' Rm-i '
alias dir= ' Ls-alg '
alias home= ' CD ~ '
alias ls= ' ls-f '
alias Md=mkdir
alias move = ' Mv-i '
alias Type=more

Alias CD: = ' CD. '



alias home= ' cd/home/dave/public_html '

alias list= ' Ls-la '

alias attrib= ' chmod '
Alias chdir= ' CD '
alias copy= ' CP '
alias cp= ' Cp-i '
alias d= ' dir '
alias del= ' RM '
alias deltree= ' Rm-r '
alias dir= '/bin/ls $LS _options--format=vertical '
alias edit= ' Pico '
alias ff= ' Whereis '
alias ls= '/bin/ LS $LS _options '
alias mem= ' top '
alias move= ' MV '
alias mv= ' Mv-i '
alias pico= ' pico-w-Z '
alias rm= ' Rm-i '
alias search= ' grep '
alias v= ' VDir '
alias vdir= '/bin/ls $LS _options--format=long '
alias which= ' type- Path '
alias wtf= ' watch-n 1 w-hs '
alias wth= ' Ps-uxa | more '


Problem Thinking

1.How do I cancel the specified alias?

2.Aliases inShelldoes the script work?

3.How do I list all aliases?

4.How do I cancel all aliases?

5.How to performlsthe command itself, not the alias?


Related Information

"1"Linuxassigning aliases to commands under the systemaliasCommand Usage

"2"TenA practicalBash Alias

"3"Brother Bird's private cuisinecommand name setting:alias, Unalias

"4"Computer Hope Linux/unix alias command

"5"alias Command

"6"LinuxTreasure trovealias--aliases

"7"LinuxSafety netLinux aliascommand parameters and usage details--linuxdefining command AliasesAlias
"8"Jiacheoin theLinuxof thealiasused inawkproblems encountered??? http://codingstandards.iteye.com/blog/1145318




Life??????????make:??? Alias

Feature Description: Sets the alias of the directive.

Syntax:alias[aliases]=[directive name]

Additional notes: Users can usealias, the alias of the custom directive. If you enter onlyalias, you can list all of the current alias settings. aliasis only valid for the login operation. To log in every time, the alias is automatically set to/etc/profileor their own~/.BASHRCthe alias of the set directive in the.

????also, if you want to give each user an alias that is in effect, pleasealias la= ' Ls-al 'a row is added to/ETC/BASHRCthe last side,BASHRCis the configuration file for the environment variable/ETC/BASHRCand the~/.BASHRCThe difference is that one is set to a system-wide one is set up for single-user use.

parameters: If no parameters are added, all current alias settings are listed. information from? www.linuxso.com??? LinuxSafety net

CentOS5.6Bring your ownaliasdefinition


[[email protected]? ~] #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 '

not in some systems.llthis command,The reason is that there is no definitionll= ' ls-l--color=tty 'this alias

Usealiascan turn a long command into anything we like short

set up and modifyaliasCommand alias format is simple

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

If you want to take effect permanently,I'm going to write this one down/ETC/BASHRCinside

How do i make Linux user-defined command alias permanent?

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.