alias, unalias in Mac OS X

By: Strauss K Emailed: 1728 times Printed: 2329 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Create an alias. Aliases allow a string to be substituted for a word. An alias may be used as the first word of any simple command.

Syntax
      alias [-p] [name[=value] ...]

      unalias [-a] [name...]

Key
   -p   Print the current values

   -a   Remove All aliases

When arguments are supplied, an alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias
substitution when the alias is expanded.

If no value is given, (or with the -p option) alias will print a list of Aliases along with their current values. For each name in the argument list for which no value is supplied, the name and value of the alias is printed.

Alias returns true unless a name is given for which no alias has been defined.

name may not be `alias' or `unalias'.

unalias may be used to remove each name from the list of defined aliases.

Alias substitution 
The shell maintains a list of aliases which can be set, unset and printed by the alias and unalias commands. After a command line is parsed into simple commands the first word of each command, left-to-right, is checked to see if it has an alias. If so, the first word is replaced by the alias. If the alias contains a history reference, it undergoes History substitution (q.v.) as though the original command were the previous input line. If the alias does not contain a history reference, the argument list is left untouched.

Thus if the alias for ls were ls -l the command ls /usr would become ls -l /usr, the argument list here being undisturbed. If the alias for lookup were grep !^ /etc/passwd' then lookup bill would become grep bill /etc/passwd.

Aliases can be used to introduce parser metasyntax. For example, alias print 'pr \!* | lpr' defines a command (print) which pr's its arguments to the line printer.

The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second
time. This means that one may alias ls to ls -F, for instance, and bash does not try to recursively expand the replacement text.

Examples

Create an alias 'ls' that will change the default action of ls:
$ alias ls='ls --classify'
$ ls 
$ unalias ls

More aliases for ls:
$ alias la='ls -lAXh --color=always'   #Show all, sort by extension 
$ alias ls-al='ls -al'   #fix typo missing space 
$ alias l="ls -l"
$ alias la="ls -la"

Use alias to fix missing space typos:
$ alias cd..='cd ..'
$ alias ..='cd ..'

Display the working directory 
$ alias .='echo $PWD'

Prevent accidental deletions by making rm interactive: 
$ alias rm='rm -i'

Shorten apt-get installation commands: 
$ alias canhaz='sudo apt-get install'

Run firefox and open a specific website:
$ alias fftr='/Applications/Firefox.app/Contents/MacOS/firefox-bin http://ss64.com'

Produce a custom prompt to display which machine you are on, the current folder, and the number of the current command:

   $ alias cd='cd \!*; set currDir = `basename $cwd`; set currDir = `echo
   "<${host}:"$currDir
   " ! >"`; set prompt = "${currDir} "'
   $ cd $cwd

<Mac_One:Work-folder 15 >

Making an alias permanent:

Assuming you have the BASH shell, then use your favorite text editor to edit or create a file called ~/.bash_aliases and add your alias commands.

alias is a bash built-in command.


macos Home | All macos Tutorials | Latest macos Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Strauss K
cut in Mac OS X
curl in Mac OS X
crontab in Mac OS X
cron in Mac OS X
cp in Mac OS X
continue in Mac OS X
complete in Mac OS X
command in Mac OS X
comm in Mac OS X
cmp in Mac OS X
cksum in Mac OS X
chroot in Mac OS X
chown in Mac OS X
chmod in Mac OS X
chgrp in Mac OS X

More Tutorials in macos
Getting PHP running on Mac OS 10.1
Installing gedit for python programming in Mac OS X
What is Mac OS X?
History of Mac OS X
Major features of Mac OS X
Different Versions of Mac OS X
What is new in Mac OS X Snow Leopard
alias, unalias in Mac OS X
apropos in Mac OS X
awk in Mac OS X
basename in Mac OS X
bash in Mac OS X
bg in Mac OS X
bless in Mac OS X
break in Mac OS X

More Latest News
Most Viewed Articles (in macos )
Different Versions of Mac OS X
chroot in Mac OS X
cron in Mac OS X
Major features of Mac OS X
alias, unalias in Mac OS X
apropos in Mac OS X
caller in Mac OS X
case in Mac OS X
cd in Mac OS X
chflags in Mac OS X
chmod in Mac OS X
cmp in Mac OS X
comm in Mac OS X
cp in Mac OS X
curl in Mac OS X
Most Emailed Articles (in macos)
bless in Mac OS X
cal, ncal in Mac OS X
caller in Mac OS X
chmod in Mac OS X
continue in Mac OS X
Installing gedit for python programming in Mac OS X
What is Mac OS X?
History of Mac OS X
Major features of Mac OS X
Different Versions of Mac OS X
What is new in Mac OS X Snow Leopard
alias, unalias in Mac OS X
apropos in Mac OS X
awk in Mac OS X
basename in Mac OS X