How to make the user-defined command alias for Linux permanently effective.
The alias (Chinese called "Alias") allows you to redefine the Shell command in Linux with a shorter name, simplifying the command line input. If you often deal with the CLI, using the alias will not only save time but also improve efficiency, and it is a good thing to kill the birds.
* Basic usage: The basic use of the alias is: alias new command = ' original command-option/parameter '. For example, alias l= ' Ls-lsh ' will redefine the LS command, and now you can just type L to list the directory.
* Learn aliases: direct input to the alias command lists all the command aliases that are already defined in the current system.
* Remove alias: To remove an alias, you can use the Unalias command, such as Unalias L.
The above is seen on the Internet, this method is only temporary, if the restart is invalidated, if we want to permanently effective an order how to do it?
Open. BASHRC (should be an Ubuntu release, and other distributions may be modified. Bash_profile) you can see
... # some more ls aliases alias ll= ' Ls-alf ' Alias la= ' Ls-a '
Alias l= ' LS-CF '
......
Method 1: Add alias xx= ' xxxxx ' directly to our environment variable file
Method 2: There is a word in BASHRC.
# you could want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
That means you can create a new file to store your own alias information.
Cases
$ cd
$ vi. bash_aliases
Enter the command you want to set in the file alias rm= ' Rm-i ' and save the launch
$ source. BASHRC #让我们的环境生效
Method ...----------------------Please note that the actual CENTOS5 test found that it should be. BASHRC
Summary:
1. Most of the time we only pay attention to solve the problem itself, but often ignore other things, in the process of solving the problem is also a learning opportunity, especially do not forget to look at the software source and so on comments. Suddenly found this is very important, because I read the annotation, I found this method, and my original purpose is to make changes to my own environment variables, in solving the problem of environmental variables at the same time I have to solve the problem of the alias, I have to remember ...
2. When looking for solutions on the Internet, it is often found that other people have files that are not native, for example. BASHRC and. Bash_profile may be on different distributions, this time you can change the search method, or try it yourself ...
Category: Ubuntu
If this is the current session
Alias of the Linux command used-set the aliases of the commands to make Linux commands more concise
This article link: http://codingstandards.iteye.com/blog/1145318 (reprint please indicate the source)
Purpose description
Sets the alias for the command. In a Linux system, if the command is too long and does not conform to the user's habits, then we can assign an alias to it. Although it is possible to establish a link for a command to solve a long file name problem, the link is powerless for commands with command-line arguments. Specifying an alias can solve all of these problems "1". Common aliases to simplify SSH login "See example three", make long commands shorter, so that the commonly used long command line shortened, forced to execute the command when asked.
Common parameters
Format: Alias
Format: alias-p
Displays the alias for 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 sample
Example one solves the problem that the RHEL5/CENTOS5 can not be highlighted under the VI syntax
Add the alias setting for VI at the end of/etc/profile
Alias vi= "Vim"
Show two displays the current alias settings
[Root@jfht ~]# 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 '
[Root@jfht ~]# alias CP
Alias cp= ' Cp-i '
[Root@jfht ~]#
Example Triple SSH Alias
SSH alias-alias Server_name= ' ssh-v-l USERNAME IP address ' To change server_name, USERNAME, and IP addresses to suit your needs. This is a favorite alias for students who often use SSH to log in to a remote shell.
[Root@jfht ~]# alias 180= ' ssh 192.168.1.180 '
[ROOT@JFHT ~]# 180
Ssh:connect to host 192.168.1.180 Port 22:no route to host
[Root@jfht ~]# alias 181= ' ssh 192.168.1.181 '
[Root@jfht ~]# 181
root@192.168.1.181 ' s Password:
[Root@jfht ~]#
Example four common alias settings collection
Alias l= "Ls-l"
Alias ll= "Ls-l"
Alias lm= ' Ls-al | More
Analog DOS-style commands
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 to cancel the alias designation.
2. Is the alias valid in the shell script?
3. How to list all aliases.
4. How to cancel all aliases.
5. How to execute the LS command itself, not alias.
Related information
"1" Linux system to assign aliases to commands alias alias command usage
"2" 10 useful Bash Alias
"3" Brother Bird's private dish order name: Alias, Unalias
"4" Computer Hope Linux/unix alias command
"5" Alias command
"6" Linux treasure trove alias--alias
"7" Linux Security Network Linux alias command parameters and usage details--linux define command aliases alias Alias
"8" Jiacheo the problem with awk in the Linux alias http://codingstandards.iteye.com/blog/1145318
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.