Submind YouTube summaries
Thumbnail for Navigating the Linux File System

Navigating the Linux File System

Watch on YouTube

Video summary

The core lesson from the first three chapters revolves around mastering the Linux file system tree, which functions like a hierarchical diagram where navigation is strictly limited to moving along vertical and horizontal lines. Users cannot move diagonally between directories; instead, they must traverse paths that combine horizontal moves into subdirectories and vertical moves down or up the hierarchy. This specific sequence of movements constitutes a path name, which serves as the instruction set for the shell to locate files. The tutorial illustrates this by showing how one cannot simply type a directory name like "South Korea" unless it is directly accessible from the current location, emphasizing that understanding the structure is essential before attempting any file operations. There are two primary types of paths used to navigate this tree: absolute and relative paths. An absolute path starts from the very top of the hierarchy, known as the root, and provides a complete route to a destination regardless of the user's current location, though typing these can be tedious if the current directory is already deep within the structure. In contrast, a relative path describes the route starting from the current working directory, allowing users to move forward into subdirectories or backward using special symbols like a single dot for the current folder and two dots for the parent directory. The video demonstrates that while relative paths are generally more convenient for short distances, they require careful counting of steps when moving up multiple levels to reach a target file located elsewhere in the tree. The choice between absolute and relative paths often depends on the distance to the destination. Relative paths are preferred for most everyday tasks because they save typing time and keep commands concise, especially when the target is within a few levels of the current directory. However, absolute paths become advantageous when navigating very long distances, such as moving from a deep subdirectory all the way up to the root and then down to a different branch of the tree. In scenarios where a user needs to traverse many levels upward to reach a file in a completely different section of the system, an absolute path eliminates the risk of miscounting the number of parent directories required and ensures the correct destination is reached efficiently. Ultimately, proficiency comes from practicing these movements until navigating the complex file system tree becomes intuitive.
Read the full video transcript
The most important part of chapters 1 through three is the part about understanding the file system tree. At the moment, I'm logged in as user Linux 150 and I've created a series of files containing information about world cities and their populations. You can see the file tree here at the left in the shell. If I use the pwd print working directory command, you'll see that I am in my home directory as shown here. In terms of this diagram, the only way to navigate from one place to another is by following vertical or horizontal lines. For example, if I want to change my directory to South Korea, I can't say cd South Korea, it'll say there's no such file or directory. Why? Because moving along this line, I will never encounter South Korea. To get from here to there would require me to move diagonally, which I'm not allowed to do. Instead, what I have to do is I have to go to the city's directory horizontally and then I can go vertically down this line and there is South Korea inside the city's directory. This series of vertical and horizontal moves is called a path or a path name. There are two kinds of paths. Absolute paths and relative paths. Let's start with absolute paths. An absolute path tells how to get to a file or directory starting from the very top of the file hierarchy. So let's say I wanted to see the contents of this file mumbai.txt with an absolute path. I have to start at the top of the hierarchy, follow this vertical line down to home, then go into Linux 150, then go into cities, then go down to India, and then finally get to Mumbai.txt. From the command line, we use a slash to separate the parts of a path name. I'm going to use a cat command to show the contents of this file mumbai.txt. I'm going to say cat and from the top of the file hierarchy which has no name I enter the home directory and from there I can get to Linux 150. From there I go to the cities directory. From there I can get to the India directory and finally inside that directory is Mumbai.txt and there are the file contents. If I wanted to see the contents of Nairobi.txt down here, I could use an absolute path name like this. slashhome/lininux150 enter the cities directory enter the Kenya directory and in there I will find Nairobi.txt txt. That's a lot of work. I'm already in the/home/inux150 directory. Why do I have to keep repeating myself? Instead of using an absolute path name, which always starts with a slash, I'm going to use a relative path name to tell how to get to my destination starting from my current directory. So instead of this long business here, I can say cat and then I'll specify my current directory symbolized by a single period. From my current directory, I will enter the city's directory which I'm allowed to do because it's on this vertical line. From there, I can go to Kenya and from there to Nairobi.txt. And that's a lot less typing for me to have to do. By the way, when a path starts with the current directory, you can leave out the dot slash at the beginning. As a convenience, I can type cat cities/kenya/nairobi.tx. txt. And that's even less typing and it works just as well. Remember, I'm still in this directory /home/lin 150. And let's say I want to change my current directory to Brazil. I'm going to make my life easier with a relative path name. I'll change a directory and starting from where I am right now which is /home/lininux150 I'm going to enter the cities directory and then go to the Brazil directory. So from my current directory go to cities and then Brazil and pwd shows you that that is exactly where I am. to look at the contents of the Sao Paulo. TXT file with the relative path name. Since that file is now in my current directory, I can either say cat in my current directory look at SAO Paulo.txt or again I can drop the dot slash at the beginning and say catso Paulo.tx txt. And from this point on, I'm going to drop that initial slash. The only reason I've been doing it so far is to emphasize that it's starting from my current directory. Now, up to this point, all of my movements have been down the file tree going to the right one level at a time. What if I'm want to change my directory to Italy? Remember, right now I'm in Brazil. That if I go down the vertical line here, there's no way I can get to Italy from here. Instead, what I'm going to have to do is I'm going to have to go to my parent directory. I'm going to have to go up one level to the city's directory and then from there I can get to Italy. First, let me clear the console so that it's a little bit cleaner here. And so again, I'm now in Brazil and what I need to do is change my directory and I'm going to go to my parent directory by typing two dots in a row. So from Brazil, I'm going to go up one level to my parent directory, which is cities. And from there, I can go to the Italy directory. And that's where I am now. Now, if I want to see what's in Milan.ext, I can say cat milan.txt because that is right in the folder where I currently am straight down this vertical line. To see the Vatican City.txt file, I can do this. I'm going to cat. Since I'm in Italy, I have to first enter the Vatican folder and then I can see this file. I type Vatican and then I can access Vatican City.txt. Notice that I'm still in the Italy directory. I didn't change my directory. And you can see that by the prompt here. Now let me change my directory to the Vatican directory. And this is now my current directory. Now the question is how would I go about displaying this file soul.txt without changing my directory. And there's no direct path from here to there. So I have to first back up to my parent directory, Italy. Then I have to back up one more time to get to my city's directory. And from there I can enter South Korea. And from there I can get to soul.txt. That means I have to use dot dot the parent directory more than once. Starting from Vatican, my current directory, I move up to the parent directory, Italy, and then up to Italy's parent, which is cities. And then I can go into the South Korea directory. And that's where I will find soul.txt. This might all seem very complicated, but it is possible to learn it with practice. So just for practice, how would you change the directory from where you are now, which is Vatican to get to Canada? Pause the video and see if you can figure it out and then resume the video to see the answer. To get to Canada from the Vatican, I have to move up one level to Italy, then up another level to get to the cities, and then it's a straight shot to Canada. So, I can say CD dot dot to get up to Italy, slash dot dot to get to cities, and then finally to Canada. And again the prompt shows that that is exactly where I am. You can get more practice at this URL. I have one final short comment to make here, but you might want to take a break because you've gotten a lot of information. I'll see you when you get back. The final comment I want to make is to ask a question. Is there any time that absolute path names can save you time? The answer is yes. Absolute path names are better if you're really far away from your destination. Right now, I'm in the Canada folder, and I'd like to see if the PDF to text program has been installed here in the bin directory. To get there with a relative path name, I'd have to back all the way up from Canada all the way to the top of the file hierarchy to get to the bin directory. So, here goes. I get out of Canada, out of cities, which leaves me in Linux 150, which gets me to home. And one more gets me to the top of the hierarchy. Then I can go into the bin directory and check to see if there's something called PDF to text there. And yes, it is there. But I got to tell you, I wasn't 100% sure I had the right number of dot dots in there. In this case, because I'm traveling such a long distance up the file system tree, an absolute path name would be a lot easier to type. I could say starting at the top of the file hierarchy, go into the bin directory and see if there's something called PDF to text. So again, 90% of the time you're going to be using relative path names to get from one part of your file system to another part of it. But if the distance is too far, you might be better off using an absolute path name. And that's what you need to know about navigating the file system in Linux.