Welcome! Today we're going to go over a really basic Linux command and it is PWD which stands for "Print Working Directory".

So what that command does, is just by itself, PWD shows you, it returns to the terminal, exactly what directory you're in within the file structure of your Linux distribution.

Obviously here I'm in Ubuntu but this will work with basically any Linux distribution.

PWD is super useful command when you're scripting if you're using it in normal circumstances, you can see where you actually are.

So if I go into "Downloads" you can see that Ubuntu, anyways, is nice enough, welcoming enough to show me that I'm in my home directory (that's the little ~ symbol) [forward slash]Downloads [~/Downloads].

In the directory called "Downloads".

However, if you're running a script.

that won't be the case.

So what happens is – I'm just going to go back out of my.

and clear screen – what happens is, we end up not knowing which directory the script is in, or where it's running from.

Just adding a little echo with a `pwd` is really useful inside your script.

Now obviously you didn't need to use echo in the terminal, but if you're inside the scripting environment, echo `pwd` and it shows you where that script is running from.

What's the working directory? Having that little trick up your sleeve it's super valuable because it's going to save you a lot of time and headaches from going, "Where is the script running from?" You know, if you're running a cron job which is a, in Linux thats a scheduled task.

You want to know, for sure, which cron job, which user is using it, and which directory it is coming from.

That's really important to know.

So PWD shows you exactly where you are.

I'm just going to take two seconds and walk through my file system, just to show you an example of how PWD works.

So if I were to CD to root [/] (that is the the base of the tree of the Linux file system), and I were to go, let's say cd media and then an LS.

oh sorry, LS, that's a listing by the way.

"dir" is equivalent in Windows.

So if I go into "Brad" and then I go to show [ls] that and I cd "Large External" inside of quotes because it has a space in the name of the drive.

And if I go, I know inside here I have some "Pictures" and then I do a listing on that, I can see a ton of files in here, obviously pictures that I've taken and and so on.

If I do PWD it returns, I'm just going to clear that, I'm going to a PWD to show you where I am.

It shows you where I am.

Now again, Ubuntu is nice enough that it does that automatically.

However, if you're using a scripting environment, if you're using a distribution that doesn't show you the file path that you're in, PWD is going to be your best friend, because you're going to get lost, you're not going to remember where you are.

"PWD" shows exactly where you are.

OK! Perfect! Thank you, keep watching these videos.

Sorry, I'm a little stuffy today, I've contracted a flu.

Not much I can do about that, but keep watching, they're gonna keep coming.

And I hope you enjoying and learning from these.

Have a good one!.

(Visited 11 times, 1 visits today)
adminTips-,command,commands,Linux,pwd,,Terminal
Welcome! Today we're going to go over a really basic Linux command and it is PWD which stands for "Print Working Directory".So what that command does, is just by itself, PWD shows you, it returns to the terminal, exactly what directory you're in within the file structure of...

Do you want to be notified about new DBA updates, releases, jobs and free tips? Join our email newsletter. It's fast and easy. You will be among the first to know about hot new DBA updates and stuff, it will help you enhance your DBA skills.
We take your privacy very seriously