How To: Return To The Previous Working Directory In The Terminal

Today is another easy day, but one that should be productive, where we’ll learn how to return to the previous working directory. It will be a short article, but you might find it useful. If nothing else, we’re making the more terminal accessible to new users. 

These Linux tips needed to be shared some time, so it might as well be now. I don’t wish to air my medical issues, but my ailment has gone on long enough and I went to a medical professional this morning. I’m sure I’ll be fine. They say only the good die young, so I’m probably gonna live forever!

Anyhow, to learn how to return to the previous working directory (in the terminal, of course), read on! I promise, it’s easy. It’s one simple command and that’s all there is to it.

Return To The Previous Working Directory:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

This is probably more useful for very-nested directories with long names, but it won’t take that to demonstrate today’s subject. It’s not terribly complicated.

Let’s say that you’ve navigated to ~/foo and performed some functions there. Next, you’ve navigated to ~/bar and performed some functions there. Now, if you want to return to the ~/foo directory you can do so with just a simple – added to your cd command, like so:

If that’s confusing, I’ve made an image that explains it better than I can…

use cd - to return to the previous working directory
It’s a simple concept. It’s a simple article about how to return to the previous working directory.

See? It’s nice and simple! If you were in one directory and left to go to a new directory, then it’s trivial to return to the previous working directory. The image should help make it clear if my description is lacking.

You might also be interested in:

Let’s Learn About Absolute And Relative Paths
How To: Find Your Present Working Directory
How To: Make A Directory In Linux

(There are a whole lot of articles with the word ‘directory’ in them!)

Closure:

I know… I know… This is a lot of short articles in a row. I’ll feel better. I’m sure of it! Amusingly, I was asked if I had any stress in my life and it was comforting to answer that I do not. My life is pretty drama free, but I do need to get an article out every other day! This time, I’ve shown you a quick and easy way to return to the previous working directory. It’s quick, easy, and effective!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Find Your Present Working Directory

There are times when you need to know your present working directory. You may need to know because the terminal doesn’t output that data, you may need to know for scripting, you may need to know for a variety of reasons.

So, what is the present working directory? Well, it’s simply a fancier name for the directory you happen to be working in – usually in the terminal. If you open your terminal and type something like cd Downloads, then your present working directory is going to be something like /home/<user>/Downloads. It’s pretty simple and this is going to be a pretty basic article. It’ll be a nice and easy exercise, even for a newbie.

There are a couple of ways to determine your present working directory and we’ll share them with you today. It’s really not a very complicated article, and not all articles need to be complicated. Sometimes, you just need new information that will help get you up to speed with your Linux understanding. After all, that’s the stated goal of the site.

Your Present Working Directory:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

As I said above, there are a couple of ways to do this. With your terminal open, why don’t you type something like cd Downloads just to have a different directory than your default directory.

When that’s done, just enter the following command:

The output should look a little something like this:

present working directory
See? It’s all pretty basic information that you’ll need to know.

But wait, there’s more! There’s also an environment variable that will show you your present working directory. It’s pretty simple and you can use it like this (among other ways):

Be sure to make note of the dollar sign and the all caps. You’ll need to include those if you want it to work. Depending on what you’re doing, you may want to use the environment variable (as I understand, it’s better to do this when  you’re scripting).

You can see an example of $PWD usage here.

Closure:

There you have it, another article. This one shows you how to determine you present working directory. As far as articles go, this one is pretty short and easy, aimed at newer Linux users.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.