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.
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:
pwd
The output should look a little something like this:
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):
echo $PWD
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.
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.
Today we'll cover one way to enable or disable your network interface in the Linux…
Today's exercise is a nice and simple exercise where we check your NIC speed in…
Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…
I think I've covered this before with the ls command but this time we'll count…
Today we'll be learning about a basic Linux command that's known as 'uname' and it…
If you've used hardinfo in the past, it may interest you to know that hardinfo…