Today on HakTip I will be creating my own command with alias, then saving it with bashrc.

Download HD Download MP4

Lets create our own commands with the Alias command! Yay programming! First off, a terminal tip: you can put more than one command on the same line by separating with a semicolon (command1; command2; command3). Ex. cd /usr; ls; cd -. This will change the directory to /usr, then list the directory, then return to the original directory.

Let's name this new series of commands the foo command and we'll create it using alias. Do this by typing alias foo='cd /usr; ls; cd -'. The structure is alias name='string'.

Let's test our new command. Type 'foo', and it should work! You can type 'type foo' to see the actual string of commands you created. To delete that alias, type unalias foo, and it should delete the command. Now, type 'type foo' again and it should give you an error. Nice! You just learned how to create and remove a new command!

One problem though: Alias'd commands won't save, so when you close the terminal, it disappears. If you want it to save, type nano .bashrc. This Bashrc file is basically a customization tool, but most people use it just to save alias's and move this file from one computer to another. Scroll down to the Alias's and add your own. For example if I type Alias foo=echo Hello World and save, now every time I open the terminal and type foo, it'll say to me "Hello World"! Neat!

How did you learn the terminal? Got a favorite book, website, or did you learn it all on your own? Tell me about it in the comments or email me at And be sure to check out our sister show, Hak5 for more great stuff just like this. I'll be there, reminding you to trust your technolust.

Leave a Reply

Your email address will not be published. Required fields are marked *


1 Comment