Bash — Create a shortcut for cd ../../../../

Binary Belle
1 min readSep 15, 2020

You know how you get all down into a file path somewhere, and then you have to go back up, and then back down some other file path, and then back up?

.bash_aliases is your friend, at least for going back UP the hierarchy.

I put this in my .bash_aliases file, in my home directory:

alias cd2='cd ../../'
alias cd3='cd ../../../'
alias cd4='cd ../../../../'
alias cd5='cd ../../../../../'
alias cd6='cd ../../../../../../'
alias cd10='echo "Do you REALLY need this many directory levels!?" && cd ../../../../../../../../../'

After you add this, don’t forget to:

source ~/.bash_aliases

That’s how it is today…tomorrow, or the next day or the next day (../../../), I’ll change the .bash_aliases file to accept an integer for the number of directories to cd back to, so I don’t have multiple lines of hard-coded aliases to do this.

--

--

Binary Belle

Senior Software Engineer, Inventor, Writer, Zumba Instructor, Storm and Sky Photographer, Drone Pilot, Shar Pei Lover & Owner