Moving into and out of Directories
In this video, we'll use the "cd" command to move into another directory before we list its files. We'll use "cd" to move down as well as up the directory structure.
The second way to list files in a directory, is to first move into the directory using the "cd" command (which stands for "change directory", then simply use the "ls" command.
I'll type "cd Downloads/Examples" to change directories into the "Examples" directory that is inside the "Downloads" directory.
Now, I can type "pwd" to verify that we're inside the "Examples" directory, and I can type "ls -al" to view the files and folders inside the "Examples" directory.
So, moving down into folders is pretty easy, but it might not be obvious how to move back up one level. You could type the entire path explicitly like "cd /Users/ModulesUnraveled/Downloads" but depending on how deep you are, that could quickly become obnoxious. This is where the "." and ".." come in.
The single dot represents the current directory, in this case the "Examples" directory. The two dots represent the directory that the current directory is inside, in this case the "Downloads" directory.
So, if we were to type "cd ." we would be changing directories to the one we're already in, which isn't very helpful. But if we type "cd .." we will be moved up one directory, into the "Downloads" directory. Let's give it a shot.
"cd .."
Now, if I type "pwd" you'll see that I'm inside the "Downloads" directory.
You might have noticed that just like the "ls" command could string directories with the "/", the "cd" command can as well. So, when I type "cd Examples/Example1/Test" I'll move all the way down into the Test folder directly. (I'll type "pwd" to verify that.) Likewise, typing "cd ../../.." will move me up three directories back up into the Downloads directory. (Again, I'll type "pwd" to verify that.)