HakTip

Hosted by Darren Kitchen and Shannon Morse.

Whether you're a beginner or a pro, HakTip is essential viewing for current and aspiring hackers, computer enthusiasts, and IT professionals. With a how-to approach to all things Information Technology, HakTip breaks down the core concepts, tools, and techniques of Linux, Wireless Networks, Systems... Read More

Linux Terminal 101 - Create Your Own Command with Alias

Friday, July 20th, 2012 – running time 05:21

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

Let's 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 tips@hak5.org. 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.

Connect with HakTip

About the Show

Details
Show Title:
HakTip
Description:
Whether you're a beginner or a pro, HakTip is essential viewing for current and aspiring hackers, computer enthusiasts, and IT professionals. With a how-to approach to all things Information Technology, HakTip breaks down the core concepts, tools, and techniques of Linux, Wireless Networks, Systems Administration, and more
Categories:
How-To & DIY, Technology & Gadgets
Launch Date:
May 23, 2011
Episodes: