Navigating the Windows CLI 💻

📂 Checking Your Current Directory 🗺️

When you first open PowerShell, you'll usually be in your home directory. Your prompt shows you which director you're currently in. But there's also a command that will tell you where you are, pwd or print working directory tells you which directory you're currently in. 🔍

🔄 Changing Directories 📁

If we want to change the directory that we're in, we can use the cd or change directory command. To use this command we'll also need to specify the path that we want to change to.

Remember, this path can be absolute, which means it starts from this drive letter and spells out the entire path. On the flip side, it can be relative meaning that we only use part of the path to describe how to get to where we want to go relative to where we're currently are. 🗺️

For example, let's say that instead I want to go to c:\users\Cindy\documents. The command would be:

cd C:\Users\Cindy\documents

Now we've changed to the documents directory. We used an absolute path to get this directory, but this can be a little cumbersome to type out.

🆙 Relative Paths 📁

We know that the documents directory is under the Cindy folder. So can't we just go up one level to get to that folder? We absolutely can. There's a shortcut to get to the level above your current directory, cd...

Let's run the pwd command one more time. Now we can see that I'm in C:\users\Cindy, the parent directory of where I was before. The .. is considered a relative path because it will take you up one level relative to where you are.

Let's go back to the documents folder and try this again. Except this time, let's go to the desktop folder using the new command we learned. We know that the desktop and document directories are under the home directory so we could run cd.., then cd desktop but there's actually an easier way to write this: cd..\desktop.

🏠 Shortcuts 🔍

Another cool shortcut for cd that you can use is cd ~. The tilde ~ is a shortcut for the path of your home directory. Let's say I want to get to the desktop directory in my home folder. I can do something like this: cd ~/desktop.

🔍 Tab Completion 🪄

We've done quite a bit of typing so far, you might actually be wondering what would happen if we messed up while typing these directory names. How are you supposed to memorize where everything is and if it's spelled correctly? Fortunately we don't have to do that. Our shell has a built in feature called tab completion.

Tab completion lets us use the tab key to auto complete file names and directories. Let's use the tab completion to get to our desktop from our home directory. If I type d and then tab, the first file or directory starting with d will now complete. Now if this isn't the file or directory that I was looking for, I can continue to press tab and the path will rotate through all the options that complete the name that I started to type.

So I'll see desktop and then documents and then downloads. Take note that the dot in front of the path of ./desktop just means the current directory. If I erase this and instead type de, then the only directory that matches is desktop.

Tab completion is an awesome feature that you'll be using more and more as you continue to work with commands. 🎉

Last updated