Moving up levels in directory tree easily

In Linux if you are in a directory level and want to jump for example 2-3 folders in one step, as far as I know there is no built-in command. If there is one, I would be very happy to know. There is a very nice command in Juniper’s JUNOS CLI which is “up” which moves you up in the configuration hierarchy. I wanted to do the same via a bash script like below;

After giving execution permission to the file, I put it under /bin folder BUT the point is I can’t simply run it like;

and expect to move 4 directory levels up. I must run it inside the current shell I am in without forking any other process and here is the handy command “.” comes in. If I am in the following directory for example;

running the command the following way;

will move us up to the /usr/libexec/gcc folder. The argument 2 here stands for in which directory we want to be above our working directory.

Although there may be a built-in bash command which already does this, I think it is good to see how “.” command can be this handy!

2 thoughts on “Moving up levels in directory tree easily

  1. rtoodtoo Post author

    Hi Seth,
    I have just checked this autojump project. It is definitely great. I was indeed using primitive CDPATH environmental variable which is a way primitive than this project of course.
    It is good to know this one as well. Thanks for your feedback.

    Reply

You have a feedback?