Welcome to another lesson! Today we’ll learn all about “file paths” and discover how they allow us to effectively manage the files and folders within our computer. Let’s dive in!
As you probably already know, using an operating system typically involves interacting with the various files and folders within it. And while on a windows machine you can just double click on a file or folder to open it, things work a bit differently in Linux.
Since we don’t have the luxury of using a mouse, we need some way of telling the terminal which files or folders we want to interact with. This is where “Linux file paths” come into play.
A Linux file path is essentially an address that describes the location of a file or folder within our system. Here’s what they look like:
/home/pictures/cat.png
Linux File paths such as the one we are looking at here, are made up of a series of names separated by slashes that help us pinpoint specific files or folders within our computer.
The files and folders on our computer are organized using a hierarchical structure, with each folder nested within another folder.
Starting from the very end of our path, we have the name of our item, and each name before that represents the folder it’s located in. So, in our example, this path tells us that the cat.png"
file is located inside a folder named pictures
, which in turn is nested within a folder called home
.
It’s important to note, that even though they’re called “file” paths, they can describe the locations of both files and folders. We’ll see what that looks like in just a bit.
Lets take a look at our path once again:
/home/pictures/cat.png
The keen-eyed among you might have noticed that the slash at the beginning isn’t preceded by the name of a folder. Like we said before slashes are used to separate words, so what is this lonely slash doing here? Well, this slash represents the starting point in our system.
As we mentioned earlier, the files and folders in our computer are organized in a hierarchical structure, as a result, we have a starting point from which everything else originates.
This base, or starting point, is referred to as the root
folder. Think of it as the main folder that contains all the other folders in our system. t’s called the root folder because it metaphorically resembles the base of a tree, from which all branches, or in our case folders, stem from.
In a Linux file path, the root folder isn’t represented by its name like most other folders, but rather by a single slash at the very beginning. In our example, this indicates that the home
folder is nested within the root folder. Don’t worry if the concept of the root
folder seems a bit abstract right now; we’ll delve deeper into it in subsequent lessons.
Now that we’ve got the basics down, let’s see how Linux file paths are used within our terminal. Like we said before, using an operating system often involves interacting with the files within it. To facilitate this, our terminal focuses on a specific folder at any given time, allowing us to manage the files within that folder with ease.
To illustrate, let’s figure out where our terminal is currently focused on. To unravel this mystery, we need to use the pwd
command which stands for “print working directory.”
The term “directory” is interchangeable with “folder,” (more on this here) so as you might have guessed, this command simply displays the folder our terminal is currently associated with. Let’s give it a shot!
ubuntu@ip-172-31-45-72:~$ pwd
/home/ubuntu
ubuntu@ip-172-31-45-72:~$
Here it is! Let’s dissect this path using our newfound knowledge. At the very end of the path, we have the name of the directory we’re currently in, and each name before that specifies the folder it’s nested within.
In this case, we find ourselves in a directory named after our username. This folder is located within the home
directory, which, in turn, is nestled within the root
directory, as represented by the slash at the very beginning.
You might be wondering: why is this directory named after our username? By default, Linux creates a folder for each user within the /home
directory, named after their respective usernames.
This folder is called the home directory for each user, which explains why it’s nestled within the /home
directory. By giving each user a separate directory for their files we can ensure that they are segregated and organized neatly.
It’s important to note that whenever we log in, our terminal will always be focused on our user’s home directory by default. How thoughtful
As we mentioned earlier, having the terminal focused on a specific directory allows us to easily interact with the files and folders contained within it.
For instance, let’s take a look at the contents of our current directory. To do so, we need to use the ls
command, which is short for “list” or “let’s see,” whichever tickles your fancy. Let’s put it to work!
ubuntu@ip-172-31-45-72:~$ ls
ubuntu@ip-172-31-45-72:~$
No output? This means that our current directory is completely empty. Bummer! But don’t fret, we’ll explore a more populated directory in the next lesson.
If the concept of paths still feels a bit unfamiliar, don’t worry. Transitioning from managing files and folders through a graphical interface to using paths and commands in a terminal can be a significant change.
But rest assured, this lesson was just the appetizer. As we move through the upcoming lessons, you’ll be able to use the terminal to perform all sorts of tasks!
Think of pwd as the terminal’s way of playing “Marco Polo” with directories — it always answers where it is.
Did you know your home directory is like your personal dorm room in the Linux university? Everyone gets one, and it’s all yours to decorate (with files and folders, of course)!
Think of ls as your Linux flashlight. It doesn’t find missing socks, but it sure lights up your current directory!
Navigating file paths in Linux is like using GPS, but without the annoying voice saying, “Recalculating.” Just don’t expect it to find the nearest coffee shop!
You can name a file almost anything in Linux. My_cat’s_birthday_party_v2_final_FINAL_really_final_this_time.png, anyone?
Learn the Linux command line with our interactive course!
Don't have an account? Select the register button to create one!
You're in the right place! Fill out the form to create your account: