File System and Navigating Directories (cd and pwd) - Images: Japanese
Hey there, everyone!
So, next up: the filesystem, the pwd command, and the cd command.
First, "what is a filesystem?" — it's a word (or concept) that refers to the mechanisms and structures involved in storing and manipulating data.
Think back to Windows and macOS for a moment. Both come with built-in software for managing directories (folders) and files. On Windows, that's 'Explorer' (Windows Explorer); on macOS, it's 'Finder'. Here's what they look like.

That's a slightly older version of Explorer on the left.

These tools let you access files, create directories, organize files into directories, and so on. Anyone who has used a computer is familiar with them. This is exactly what a filesystem is — a system designed to categorize and organize data, and to make copying, editing, and deleting data as straightforward as possible.
If you're curious how this works under the hood: when data is written to an SSD or HDD, the filesystem also secretly records where that data is located. So even though a file appears to "live inside" a directory visually, physically the storage is just writing 0s and 1s in arbitrary locations. The filesystem manages the metadata that makes those raw bytes appear as organized files and folders.
For example, when data labeled "A" is saved, the filesystem records something like: "this data belongs to user sakurama, so it lives in the sakurama directory." Then when that same filesystem reads data back, it can say: "data A is in the sakurama directory — show it there in Explorer (or Finder) so the user can work with it."
And this filesystem is critically important in UNIX-based OSes.
The best way to understand it is to try it hands-on. Let's do that with CentOS and macOS. When you log into CentOS, you'll see this output — the prompt from earlier, indicating the system is waiting for input.
[root@localhost ~]#
On macOS, opening the Terminal app with default settings looks something like this.
[@:~]$
When the prompt is showing, you're "inside the world built by the filesystem" — and more specifically, you (the operating user) are always located inside some directory, and you're operating from within it.
"So where am I right now?" — let's find out using the 'pwd' command, which tells you your current directory. Just type 'pwd' with no options or arguments and press Enter. The top example is CentOS, the bottom is macOS.
[root@localhost ~]# pwd
[@:~]$ pwd
After pressing Enter, you'll get output like this.
[root@localhost ~]# pwd /root
[@:~]$ pwd /Users/your-name
On CentOS it says '/root', and on macOS it shows '/Users/your-name' — where "your-name" will be whatever name is registered in macOS. For example, if your user is 'hsakurama', it'll show '/Users/hsakurama'. That's your current location.
Now, "current location" might feel abstract. Let's look at something specific in that output — the / (forward slash). This character represents a directory separator.
On Windows, you've probably seen backslash (¥ or \) used to separate folder names — like "user¥document¥miku_hatsune" for "the miku_hatsune folder inside document, inside user". The forward slash in UNIX works the same way.
So if your current location is /Users/hsakurama, you're inside the hsakurama directory, which is inside the Users directory at the top level. That should be clear enough.
By the way — modern macOS is a UNIX-based OS, so it uses '/' as the directory separator, both in CUI and GUI. The same separator applies in both contexts.
The pwd command is one of the most frequently used basic commands in UNIX. Commit it to memory.
On that note: pwd stands for "print working directory". When you encounter a new command, looking up its full name tends to make it easier to remember — so it's worth a quick search whenever you come across something new.
The nested structure of directories — folders within folders within folders — has a name: directory tree.
There's an older UNIX command called 'tree' that isn't included in recent CentOS or macOS default installations, but when you have it, it shows the directory structure like this.
. ├── sample.js ├── test.html
That output shows that the current directory contains 'sample.js' and 'test.html'.
The directory tree concept comes up occasionally in reference materials, though it's not a high-priority item. The 'tree' command itself is pretty handy — it's worth knowing it exists, even if you don't use it often.
Note: 'tree' is not installed by default in the minimal CentOS 6.9 package we're using here. You'll need to install it separately later — we'll cover that when we get there.
Now let's introduce one more command: cd. This command moves you to a different directory. For example, to navigate to '/home/test':
[root@localhost ~]# cd /home/test
The structure is: cd followed by the path of the directory you want to go to.
cd stands for "change directory" — but it's also worth knowing the term current directory. In UNIX, the directory you're currently working in is called the "current directory." This term comes up constantly in real-world work — make sure you know it cold.
In the world of computers, both 'directory' and 'folder' refer to the same thing — a container that organizes files into categories or levels. You can use them interchangeably.
In the author's experience, Windows environments tend to use "folder" while UNIX environments tend to use "directory" — but the two are essentially the same thing. There are some technical differences in strict definitions, but they're minor enough to safely ignore for our purposes.
Alright, that's a good stopping point for this article.
In the next article, we'll look at some important directories in UNIX systems and cover the 'ls' command. See you there!
This article was written by Sakurama.
Author's beloved small mammal |
桜舞 春人 Sakurama HarutoA Tokyo-based programmer who has been creating various content since the ISDN era, with a bit of concern about his hair. A true long sleeper who generally feels unwell without at least 10 hours of sleep. His dream is to live a life where he can sleep as much as he wants. Loves games, sports, and music. Please share some hair with him. |
If you find any errors or copyright issues, please contact us.