DEV Community


Discussion on: What do you use aliases for in terminal?

thefluxapex profile image
Ian Pride • Edited

If you are using Bash you can automate creating your aliases you have for:

...='cd ../..'


by looping a range of numbers (of your choice, of course) to create each alias in sequence:

dota='...' # Preset alias starting point, key
dotb='../../' # Preset match starting point, value
for int in {1..20}; do
    alias ${dota}='cd '"${dotb}" # Create the next alias 
    dota="${dota}"'.' # increment key string
    dotb="${dotb}"'../' # increment value string
unset int dota dotb # cleanup

In this way you can set more than just a few aliases of this sort and go back as many as 20 directories (or more, of course). Seems pointless or redundant to some, but I find myself navigating dirs this way often lol; maybe I'm just weird. If you're not interested then I'll just remove this post...

The only reason I posted is because I already do it this way and when I seen your post here I thought you or someone else might be interested in my method.

Forem Open with the Forem app