Skip to content

Navigating the Filesystem from the Command Line

This week’s Quick Guide isn’t specifically about WordPress. Instead, it’s a very brief primer on getting comfortable with the command line by navigating the filesystem on my Mac. As this week’s article explaining the core things you need to understand about the command line highlighted, a Mac is a Unix-like system as is Linux. This means that the commands this Quick Guide highlights are equally appropriate for your WordPress server, which has about a 98% chance of being some Linux variant.

Here’s the video explaining how to move through folders from the terminal:

And if text is more your speed:

The Three Essential Commands for Navigating a Unix Command Line

pwd — Find your “present working directory”

You may, at least if you don’t have a super strong memory, regularly forget where you currently are when navigating around on the command line. That’s where pwd comes in. Those three letters followed by the “Enter” key will give the full path you’re currently on back to you immediately. In the video that often looked like Users/david/Dropbox or similar.

ls — See the files in your current directory

The next thing you’ll probably need, once you know where you are, is a sense of what’s around you. That’s where the ls command comes in: it lists the files and folders in your current working directory. It’s pretty simple, and by default only gives you the names.

But ls is a great command to start to understand “flags” with. To get a little more detail about what files are in your directory and what else you might want to know about the file, it’s common to use the -l flag. So ls -l will give an output like the below:


cd — Change your current directory

Finally, it’s often useful to change which directory you’re in. This is where cd comes in. cd Dropbox can move me from a pwd or Users/david/ to one of /Users/david/Dropbox. From there, I could get back (go up a level) via cd ... The double dots (the last is a period :p) tell cd you want to go up a level.

The final note, which was forgotten in the video, is that you can and might want to pass cd a full path. If I want to get to the etc directory, which I know is at the root of my filesystem, I can get there with a cd /etc command, rather than having to chain together something like cd ../../../../etc. Most terminal commands that require a location have this property — a location that starts without a / is considered relative to wherever you are now, a location that starts with a forward slash is considered to be absolute and jumps right there relative to the whole file system.

We’re just getting started

To be effective on the command line, you need to know a lot more than moving around. But moving aroudn in the filesystem — and understanding the command line is inextricably linked to the filesystem, because you are always idling in a folder — is crucial for you to be comfortable with it. If this post felt over your head, please check out out recent article explaining the command line terminal from the most basic level.

Yay! 🎉 You made it to the end of the article!
David Hayes

Inline Feedbacks
View all comments

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

Would love your thoughts, please comment.x

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

20 Best Free WordPress Themes for 2024 (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...