Playing with Debian

Monday, 3rd March 2008 at 10:48pm

Speed up your CLI with aliases

There are a lot of switches to a lot of commands and sometimes they're just too long to remember, or you're just too lazy to type them. In cases like this, you can use aliases. They're basically shorthand for commands you use a lot.

For instance, to log onto MySQL I have to use the command:

mysql --user=dangermouse --password=letmeinplox

It gets a little boring typing that over and over again. Also, PuTTY doesn't hide the password as you're typing it which can be a little dangerous. An alias fixes both of those problems. Just do:

alias my_mysql='mysql --user=dangermouse --password=letmeinplox'

"alias" is the command, "my_mysql" is the new alias/command I'm creating, and the rest is what I want it to be. So, now I can type "my_mysql" and it'll log me into my MySQL server.

If you pick a name for your alias that already exists, the original one will just got overridden.

Unfortunately, you'll have to create this alias every time you log onto your server. You can fix that by adding it to your .bashrc file, which is in your home directory, (so, mine is /home/shamess/.bashrc). That file should already have a few aliases in it, so take a look around it for examples.

Comments

Your name: Your URL:

Body:

User comments

Marc says:

Another way to get around the password issue is just to type 'mysql -u username -p' and then press return and it'll then ask for the password and not show it on the screen :-)

shamess says:

@ Marc
Oh, cool. I had no idea you could do that. Thanks!

Read some previous entries