Keeping up with my workload is a constant challenge, and in order to maintain my sanity, I've had to come up with all sorts of tricks to speed up parts of my workflow that can eat into my day. Part of that involves becoming more of a keyboard user, so I use a launcher like Vicinae on my Linux PC.

But something else that really helps is setting aliases for important commands in the terminal. You can be very productive by using a keyboard instead of a mouse, but the commands you have to memorize each time also take a fair amount of time to type out, so aliases come in clutch and really make a big difference.

What are aliases?

And how do you create them?

Let me start with a primer on aliases. They let you define shorter commands that are easier to remember as stand-ins for longer commands, and even combinations of commands, and they're huge time savers.

You can define aliases for the current session by using the alias command and then defining the alias you want to use and what commands it should be equivalent to. For example, just use this command:

alias dl='cd /home/user/Downloads'

If you'd like to permanently save your aliases, you'll need to add them to the .bashrc file in your Home folder. Simply add a new line for each alias you want to register (as seen above), and you're good to go.

There's a bit of a neat trick here, though. While you can add aliases directly to this file, there are other settings stored there, and if you want to back up your aliases, backing up the .bashrc file isn't ideal. Instead, what you can do is create a separate file called .bash_aliases (as an example) in the Home folder, and add your aliases there. Then, add the following lines to your .bashrc file:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

This will let your computer pull the aliases from the standalone .bash_aliases, which you can more easily back up to use elsewhere. With that out of the way, let's get into some useful aliases you might want to set up.

Browse to specific folders

Starting simple

One command you may need to use often in the terminal is cd, which changes the working directory for your terminal. While the command itself is short, typing out the path you want to navigate to can be a bit of a headache because file paths can get pretty long. For example, your documents folder will usually be in a folder like /home/joaoc/Documents, and that's a pretty basic example.

So, what if instead of cd /home/joaoc/Documents, you could just type doc and instantly jump to the same folder? Simply enter this command into your terminal or add it to your .bashrc or .bash_aliases file:

alias doc='cd /home/joaoc/Documents'

After that, you terminal will respond to the doc alias by jumping right into the desired folder. You can repeat this for just about any folder you want and with any alias you prefer, so it's up to your own needs and consideration.

Update everything

System and apps

Due to the various distribution methods and package managers on Linux, updating your system can require a few commands depending on your distro and setup. On Ubuntu, updating all your APT packages would require two commands: sudo apt update and sudo apt full-upgrade, but that still leaves out Flatpak packages if you're using any. There's another command for that, sudo flatpak update.

So, why not combine them into one single alias? To define it, simply enter this into your terminal or add it to your aliases file:

alias update='sudo apt update && sudo apt full-upgrade && sudo flatpak update'

For myself, since I'm using Arch, this would look more like this:

alias update='sudo pacman -Syu && sudo flatpak update'

It will vary for other distros as well, but the core principle is the same.

Open Visual Studio Code in a specific folder

For coding, or not

I'll admit I'm not much of a Visual Studio Code user, but if you're using Microsoft's IDE for development (or even just for your personal notes), there's a good chance you might want to open it directly where your projects are so you can get started more quickly.

Let's say you've stored our VS Code files in a folder called Projects inside your Documents folder. If you want to open VS Code directly in that folder, you can define this alias (changing the user folder name to whatever matches your username):

alias work='cd /home/joaoc/Documents/Projects && code .'

This makes the work alias start by changing directories to the correct folder and then launch VS Code inside that folder. Again, this is something you can easily replicate for different folders if you want to have quick access to different projects.

Re-run the previous command as sudo

You just have to ask nicely

At one point or another, there's a good chance you've forgotten to use the sudo prefix for a command that requires it — or maybe I just don't want to be alone in this. Still, when it happens, it can be a little annoying to have to re-type the command all over again. Before, I'd use the up arrow to bring the command back and then move the cursor back to the beginning to add the sudo prefix. But even that takes longer than ideal.

To speed things up, you create a simple alias that automatically sends the last command again but with the sudo prefix. Here's how you can define it:

alias pls='sudo $(fc -ln -1)'

This makes it so you can simply type in pls to reissue that last command as it should have been, which is not only useful but also kind of funny.

Start an SSH session

Remotely access your homelab (or anything else)

If you've set up something like Proxmox on a PC, a Docker instance, or any machine that's not using a direct display output (like a headless Raspberry Pi), you already know SSH is a very useful tool for remotely accessing its terminal to change settings or otherwise manipulate it.

WhIle starting an SSH session isn't particularly hard, you can always shorten it more, or keep shorthand commands for different devices you may need to control. Say you want to start an SSH session for your NAS, you can set an alias like this:

alias nas='ssh joaoc@192.168.8.115'

This will allow you to connect the SSH session with an even shorter command (nas), saving you that much more time.

👁 Running an fio test on the TerraMaster F8 SSD Plus NAS via SSH
5 SSH features you might not know about

If you've ever used SSH, these are some features you might not know about that you can make use of.

Restart your network services

Fix any weird issues

A computer without internet these days is almost as good as a brick, so whenever issues arise, it's good to be able to fix them quickly. Restarting the network manager can go a long way to fixing your connection, but it's a tedious set of commands to type out. So, instead of doing all that, you can create an alias like this:

alias netfix="nmcli networking off && sleep2 && nmcli networking on"

This will allow you to turn off and then restart the Network Manager service by just typing in netfix. On some distros, the nmcli command may not work, so you'd use something like this instead:

alias netfix="sudo systemctl restart NetworkManager"

Either way, this makes it easier to troubleshoot your internet in a flash.

See all your Docker services

A quick overview of everything

Finally, if you're setting up multiple services using Docker, it can help to get an overview of everything running on your machine and the status of each service. There's a command that gives you a full rundown of everything, but it's a fairly convoluted one, so simplifying it is definitely for the best.

Here's how you can set up an alias for this command:

alias dps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'

This will return a table like what you see in the image above, and it's pretty useful. I don't run Docker on my desktop PCs, so I ran the command in my NAS, and it works just as well there.

Aliases are huge time savers

These are just a few examples, but you could realistically do this with any terminal command you use frequently, and it's easy to see how it would save you a lot of time. No matter your use case, aliases can cut down on how long you spend typing and memorizing commands, allowing you to put more time into things that matter. I highly recommend exploring the options nthat suit your needs, in addition to the ones above.