DEV Community

Cover image for Tech Speak: Terminal Command Aliases
reduncan
reduncan

Posted on • Updated on

Tech Speak: Terminal Command Aliases

Do you ever get tired of typing ../ to go up a level in your folder structure when navigating via the terminal? How about mkdir? Or even clear? If using the terminal for navigating your file structure is supposed to be quick and easy why not make it even easier by aliasing certain commands so that you use less key strokes and use more memorable terms to achieve the same result.

To do this you will want to make sure that you set the aliases on a permanent basis otherwise each time you open a new terminal window you will have to set the aliases again. To set the alias permanently, you will need to create a file that the terminal will read each time it is loaded.

In your terminal type the following commands...

cd ~

This will take you to your root directory.

touch .bash_profile

This will create the file where your aliases are stored and will be read by your terminal each time it is loaded.

open -e .bash_profile

This command will open the new file in your default text editor.

Now that we have the file open in your text editor we can start setting our aliases. In the text file you will create an alias by typing alias followed by the shortcut you want followed by the equal sign and finished up by the actual terminal command.

alias create=mkdir
alias clr=clear
alias .=../

Once you have your aliases, save the file and close it. Reload your terminal and test out your aliases.

And that is how you can alias all of your most used commands to make navigating via the terminal easier.

Until next time :)

Discussion (0)