Skip to content

Instantly share code, notes, and snippets.

@wikrie
Last active June 27, 2017 13:24
Show Gist options
  • Save wikrie/191b6b092682c80aaacdc2e345173670 to your computer and use it in GitHub Desktop.
Save wikrie/191b6b092682c80aaacdc2e345173670 to your computer and use it in GitHub Desktop.
add function to multiple change directory back and or jump back to an existing directory in path name
# function to multiple change directory at once or jump back to an existing directory in the path
# using: cd.. n or cd.. dir or cd.. *part_of_directory*
function mcd() {
case $1 in
*[!0-9]*) # check if it is a number
cd $( pwd | sed -r "s|(.*/$1[^/]*/).*|\1|" ) # loopup for name or part of name of directory
;; # if not a number and not an existing directory of path do nothing
*)
cd $(printf "%0.0s../" $(seq 1 $1)); # change back directory n times
;;
esac
}
alias 'cd..'='mcd' # set alias for function so 2 options to run mcd n or cd.. n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment