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:

screen-shot-2016-11-16-at-11-04-08-am

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
Share:

0 Comments
Most Voted
Newest Oldest
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)!