JZ.
JZ.

Reputation: 21877

Where are alias' stored in Ubuntu 10.04

I'm using a command which I don't know where the information is stored.

alias nup='ps ax | grep "nginx"'

Where is this alias saved?

Upvotes: 16

Views: 37802

Answers (6)

Fin Hirschoff
Fin Hirschoff

Reputation: 241

The question here is:

if I have an alias named 'shortcut,' how do I find out what file is defining that as an alias?

The best and most user-friendly way to do this is this:

sudo grep -roI alias\ nameOfAliasHere=\' /etc/ /home/yourUserName/
  • -r tells grep to read everything in the directory, and go through the directories recursively, Without it, grep will complain about what you want to do.
  • -o means print only the part of the line that matches your string
  • -I suppresses binary files in the results, because those will not help you find out where your alias is
  • The backslashes mean "treat the next character as part of the string, instead of the normal way you interpret it"

The command will go through everything, including subdirectories, in your home folder and in /etc


If you want to start with the most likely places, just do your home directory:

sudo grep -roI alias\ nameOfAliasHere=\' /home/yourUserName/

To search everywhere it's likely to be defined or mentioned, which can be handy, this:

sudo grep -oIr alias\ ls=\' / --exclude-dir={sys,proc,srv,media,tmp,sbin,bin,boot,mnt,recovery,run,backups,var}

A lot of things like to make the 'ls' command fancier, for example. Check out the comparison below. I also included 'time' at the beginning for kicks:

results

You can see that there are a couple places outside of your home dir and /etc that have that alias, and it's also defined in both .alias and .bashrc. Personally, I like to throw my custom aliases in a file called .alias, and then tell everything to source it. If you're having trouble with an alias you're trying to define, that's handy. The things you see in the ~/Downloads and .cache directories won't affect your active aliases. Same with the /usr directory.

The file in /etc/skel is used to create home directories for new users, so anything there doesn't affect you. If something shows up in /etc/profile though, that will.

You can also see that the root user has an alias for ls.

Upvotes: 0

Arvind
Arvind

Reputation: 1902

In ubuntu alias get stored in the .bashrc file.

If you are typing alias update_linux='sudo apt-get update' in the terminal, then it will create an alias temporarily. It works until you close your terminal.

To add an alias permanently you can edit ~/.bashrc and add the alias to it:

gedit ~/.bashrc

and add alias at the end

alias update_linux='sudo apt-get update'

Don't forget to refresh the .bashrc configuration, by running:

source ~/.bashrc

for more details on creating alias you can read following blog: Codebucket.

Upvotes: 6

Daniel Dropik
Daniel Dropik

Reputation: 783

I am using Ubuntu 14.04, and you may put your aliases directly in .bashrc, but you may also create a file in ~/.bash_aliases, which will hold your aliases separately and load them automatically.

By default, the .bash_aliases file is not there. You will need to create it, but first make sure you create it in the same directory as your .bashrc file

To find your .bashrc, you may use this:

sudo find / -name .bashrc -print

My output was:

/root/.bashrc /home/ddropik/.bashrc /etc/skel/.bashrc

As mentioned by OddityOverseer and ranendra, I am probably interested in the one in my home directory, that is /home/ddropik/.bashrc. So I navigate to my home directory, cd ~/

Now create the .bash_aliases file with touch .bash_aliases and then edit it with nano .bash_aliases. Add whatever aliases you want.

You won't be able to use your newly added aliases until you open a new terminal session, or reload your profile, --bash login

Upvotes: 2

user unknown
user unknown

Reputation: 36229

Try

grep alias ~/.* 
grep alias /etc/*

to find most aliases. In /etc/default, /etc/environment, depending on your distribution (I read: ubuntu)/version there might be more in other /etc/ -subdirs.

Upvotes: 2

ranendra
ranendra

Reputation: 2512

It depends upon your environment and configurations. For bash, I would generally put it in a .bashrc file that in a home directory.

Upvotes: 12

dkniffin
dkniffin

Reputation: 1383

It's ussually in a file in your home directory, such as .aliases or something.

Upvotes: 1

Related Questions