« Back to Blog

Terminal Command Hacks - Using Aliases

By Paul Ibarra
Jul 30, 2018

I work in terminal frequently with various operating systems; primarily macOS and Fedora. The more I used it in my day to day work life, the more I found myself entering the same commands, some rather lengthy. Creating aliases for commands is a great way to make my terminal life more efficient. Let’s take a look at a simple example in which making an alias still provided what I needed and helps my work in different operating systems a little more seamless.

The first comes from the simple ll command in Fedora. This lists the contents of the current working directory. Take a look at the following…

I’m currently working in the directory /home/paullyb/Example and when I use the ll command you can see that I have 3 files and 2 folders in that directory. This view also lists the permissions for each as well as the time they were created. If I enter the same ll command from my Mac, this is the result…

This ll command is not universal; however, I used Fedora so frequently, that I found myself naturally entering ll in an attempt to list contents in the same manner. The macOS command to do the same is ls -al. As I found myself entering ll naturally I decided to make it an alias in macOS so that I could enter it and get the result that I wanted. I did this by editing my .bash_profile and adding this line at the end: alias ll=”ls -al”

After editing .bash_profile you need to either restart your terminal session or source the file for the changes to take effect.

After the changes were applied, I can now enter the ll command in terminal on my Mac and get the same view as if I entered ls -al.

This is just a simple example, but you can alias any command you need. If you have lengthy commands that you enter frequently, consider creating a short alias for them. This helps save time and reduces the chances of creating a typo when entering them. You’ll also still be able to tab complete the commands. Reach out of you have any questions as you are setting up your aliases!