DEV Community

Cover image for New Year, New Terminal: Alias Your Directories the Unix Way

New Year, New Terminal: Alias Your Directories the Unix Way

Ben Myers on January 02, 2020

This article covers how to alias your directories on Unix, and was originally published on my blog. Additionally, you may be interested in the Wind...
Collapse
 
syntaxseed profile image
SyntaxSeed (Sherri W)

For anyone who wants a matching function to remove the aliases...

function del_alias() {
    if [[ "$#" -ne 1 ]]
    then
        echo "USAGE: del_alias <alias name>"
        return 0
    elif [[ -n "$(alias $1 2>/dev/null)" ]]
    then
        sed -i "/alias $1=/d" ~/.bashrc
        source ~/.bashrc
        echo "Alias removed."
        return 0
    fi
    echo "Alias does not exist."
}
Collapse
 
jsardev profile image
Jakub Sarnowski

Why not just use z?

Collapse
 
bendmyers profile image
Ben Myers

I hadn't heard about this before. This is really cool! Thank you for sharing!

Collapse
 
jsardev profile image
Jakub Sarnowski

Yeah it's an amazing tool! I can't live without it 😄 You won't ever need directory aliases again!

Collapse
 
darkwolf7 profile image
DarkWolf7

In most of the places I've worked the systems are very locked down and many are running Solaris Unix or AIX, so downloading libraries or compiling stuff from the web is not an option unless you want to be walked out, so using aliases like this is far more useful than z or goto (excellent tools! But only an option @ home).

How locked down, you ask? My office defaults you to ksh and the only way to change that is to have exec bash in my .profile

Collapse
 
syntaxseed profile image
SyntaxSeed (Sherri W)

Ooo I'm using this now. Thanks.

Collapse
 
bendmyers profile image
Ben Myers

This is neat. Thanks for sharing!