Make Shell Aliases Easy

This blog started as part of a discussion about shell usage and putting aliases in. This is of interest to me because, before I went into full-time development, I did a lot of system administration in Unix and Linux. I spent most of my days in the shell and in a Unix editor. And I still get out of the IDE and into a shell.

Once upon a time, I remember reading somewhere that, if you run a command with at least one argument twice a day, then you should make an alias for it. Their reasoning made sense – the problem was that it was painful to do. They gave an example of an uber-alias — something in your shell init file ta helps you create them. What they went something like this:

Then you don’t store your aliases in your .profile but in it’s own file. For me that file is ~/.aliases for commands and ~/.diraliases for directory aliases (which is a zsh thing. If you haven’t checked out zsh you really should).

I read this article over 10 years ago and it’s still a setup that I use to today. I find a command that I suddenly use a lot of, I can quickly make an alias for it and use it immediately.

Here is a few of the aliases that have come so ingrained into my workflow that I really can’t live without:

The git smart-something aliases are from the git-smart project which could be the subject of another blog post, but let’s just say I find it very handy.

Sometimes you have a series of commands that you run over and over again. You could put it in a shell script in ~/bin but (if you are like me) that directory gets rather full. For me, I’d rather put them in function inside my ~/.aliases. Here is an example:

So save yourself some keystrokes and embrace the power of aliases in your shell.

About the Author

Mike Hostetler profile.

Mike Hostetler

Principal Technologist

Mike has almost 20 years of experience in technology. He started in networking and Unix administration, and grew into technical support and QA testing. But he has always done some development on the side and decided a few years ago to pursue it full-time. His history of working with users gives Mike a unique perspective on writing software.

One thought on “Make Shell Aliases Easy

  1. Nate says:

    Cool post. I do the same thing, and I even made an alias to easily create alias’.

    Example:
    echo ‘alias ‘$1’=”‘$2′”‘ >> ~/.bash_profile;

    full code here:
    https://gist.github.com/nateflink/f3652012615117488c47

Leave a Reply

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

Related Blog Posts
Performance Test Liquibase Update
When doing a liquibase update to a database if you’re having performance issues, it can be hard to find out which updates are causing problems. If you need to measure the time to apply each […]
TICK Stack Monitoring for the Non-Technical
TICK – Telegraf, Influx, Chronograf, and Kapacitor – is a method of monitoring your systems and applications. In this article, I discuss in non-technical terms what the difference is between TICK and Prometheus Grafana A […]
Design Systems, Part 1 • Introduction
Business leaders need a practical guide to plan and execute Design System Initiatives. The aim of this series is to be that guide. This installment introduces terms and definitions as a primer on Design Systems.
ML for Translating Dysarthria Speech (Pre-Part 1)
What is Dysarthria? Per the Mayo Clinic, Dysarthria occurs when the muscles you use for speech are weak or you have difficulty controlling them. Dysarthria often causes slurred or slow speech that can be difficult […]