What command will move you from the current directory to the one above it?
Use a single command to navigate multiple steps in your directory structure, including moving backwards (one level up). Show
Perform operations on files in directories outside your working directory. Work with hidden directories and hidden files. Interconvert between absolute and relative paths. Employ navigational shortcuts to move around your file system. Moving around the file systemWe’ve learned how to use 0 to find our current location within our file system. We’ve also learned how to use 1 to change locations and 2 to list the contents of a directory. Now we’re going to learn some additional commands for moving around within our file system.Use the commands we’ve learned so far to navigate to the 3 directory, if you’re not already there.
What if we want to move back up and out of this directory and to our top level directory? Can we type 4? Try it and see what happens.
Your computer looked for a directory or file called 5 within the directory you were already in. It didn’t know you wanted to look at a directory level above the one you were located in.We have a special command to tell the computer to move us back or up one directory level.
Now we can use 0 to make sure that we are in the directory we intended to navigate to, and 2 to check that the contents of the directory are correct.
From this output, we can see that 8 did indeed take us back one level in our file system.You can chain these together like so:
prints the contents of 9.
In most commands the flags can be combined together in no particular order to obtain the desired results/output. 5Examining the contents of other directoriesBy default, the 2 commands lists the contents of the working directory (i.e. the directory you are in). You can always find the directory you are in using the 0 command. However, you can also give 2 the names of other directories to view. Navigate to your home directory if you are not already there. 6Then enter the command: 7
This will list the contents of the 5 directory without you needing to navigate there.The 1 command works in a similar way.Try entering: 9This will take you to the 8 directory without having to go through the intermediate directory.
Full vs. Relative PathsThe 1 command takes an argument which is a directory name. Directories can be specified using either a relative path or a full absolute path. The directories on the computer are arranged into a hierarchy. The full path tells you where a directory is in that hierarchy. Navigate to the home directory, then enter the 0 command. 2You will see: 3This is the full name of your home directory. This tells you that you are in a directory called 2, which sits inside a directory called 3 which sits inside the very top directory in the hierarchy. The very top of the hierarchy is a directory called 4 which is usually referred to as the root directory. So, to summarize: 2 is a directory in 3 which is a directory in 4. More on 8 and 3 in the next section.Now enter the following command: 4This jumps forward multiple levels to the 9 directory. Now go back to the home directory. 6You can also navigate to the 9 directory using: 6These two commands have the same effect, they both take us to the 9 directory. The first uses the absolute path, giving the full address from the home directory. The second uses a relative path, giving only the address from the working directory. A full path always starts with a 4. A relative path does not.A relative path is like getting directions from someone on the street. They tell you to “go right at the stop sign, and then turn left on Main Street”. That works great if you’re standing there together, but not so well if you’re trying to tell someone how to get there from another country. A full path is like GPS coordinates. It tells you exactly where something is no matter where you are right now. You can usually use either a full path or a relative path depending on what is most convenient. If we are in the home directory, it is more convenient to enter the full path. If we are in the working directory, it is more convenient to enter the relative path since it involves less typing. Over time, it will become easier for you to keep a mental note of the structure of the directories that you are using and how to quickly navigate amongst them.
Navigational ShortcutsThe root directory is the highest level directory in your file system and contains files that are important for your computer to perform its daily work. While you will be using the root ( 4) at the beginning of your absolute paths, it is important that you avoid working with data in these higher-level directories, as your commands can permanently alter files that the operating system needs to function. In many cases, trying to run commands in 8 directories will require special permissions which are not discussed here, so it’s best to avoid them and work within your home directory. Dealing with the 3 directory is very common. The tilde character, 2, is a shortcut for your home directory. In our case, the 8 directory is two levels above our 3 directory, so 1 or 6 will take you to 7 and 8 will take you to 4. Navigate to the 5 directory: 7Then enter the command: 8 9This prints the contents of your home directory, without you needing to type the full path. The commands 1, and 6 are very useful for quickly navigating back to your home directory. We will be using the 2 character in later lessons to specify our home directory.
|