Create a New Permanent Alias


alias [alias name]= '[command]'

If you want your aliases to stick around between shell sessions, you need to add them to the file your shell uses to store aliases. Most of the time that file is either .bashrc or .bash_aliases; in this case, you're going to use .bash_aliases. No matter which file it is, be careful editing it, as you can cause yourself problems later when logging in. If you want to be really careful, create a backup of the file before editing it. Better safe than sorry.

Note

How can you find out which file you should use? Simple: Type ls -a ~. If you see .bash_aliases, use that; otherwise, look in .bashrc and see if other aliases are defined in there. If you don't see any aliases in there, take a look at .profile, which is occasionally used.


To add an alias to .bash_aliases, open it with your favorite text editor and add a line like the following:

alias lsd= 'ls -d */' 


The same rule discussed in "Create a New Temporary Alias" applies here as well: Your alias name can't have an = in it. After adding your alias to .bash_aliases, save the file and close it. But the alias doesn't work yet. The .bash_aliases file (or .bashrc if that's what you used) needs to be reloaded for the new alias to work. You can do this in two ways. You can either log out and then log in again, which is a pain and not recommended, or you can just reload the file by running this command:

$ . .bash_aliases 


That's a dot, followed by a space, followed by the name of the file, which begins with a dot. Now your new alias will work. Because you have to reload the file every time you add an alias, it's a good idea to add several at a time to lessen the hassle.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net