Navigate the Filesystem in Bash

Cameron Nokes
InstructorCameron Nokes

Share this video with your friends

Send Tweet
Published 5 years ago
Updated 4 years ago

In this lesson, we’ll learn how to change the working directory using cd and list a directory's contents using ls. We'll see how ls's -l and -a flags work.

Instructor: [00:00] To start, let's open the terminal application. This is how we interact with Bash on macOS.

[00:06] When you first open Bash, you're started in your user's home directory. You can tell where you are in Bash by looking at before the prompts here. We see we have this tilde character. The tilde is a special character that represents your user's current home directory.

[00:21] To see what that is, we can run the pwd commands, which stands for print working directory. That'll print out an absolute file path of our current working directory. If we want to change the current working directory, you can run cd, which stands for change directory.

[00:36] I'm going to go to repos, egghead-bash. As I type the file path, you can hit the tab key, and it'll autocomplete for you. We cd there, and we can see that this portion before the Bash prompt changed to represent that directory.

[00:52] Now that we're here, let's see what other files and folders we have in this directory. To do that, I'll run the ls command. Ls stands for list. You can see we have one folder here called sandbox.

[01:04] Let's cd into sandbox. Let's run the list again in here. I have two files, index.html and index.js. Plain list, doesn't give us a lot of information. One thing we can do is we can pass a flag to ls, the long flag, that'll give us a long listing, which gives us more information, such as this little dash tells us that it's a file.

[01:26] This tells us the user and group that owns the file. This tells us when it was created or last modified, and then here's the filename.

[01:35] I also have a Git repository initialized at this folder. Whenever you have a Git repository, there is a hidden .git folder. To see hidden files and folders, we can pass the -a flag. I'll pass that along with the long listing flag.

[01:51] When we do that, we can see now here is the .gif folder. We can see it's a folder or directory, because it has the d there. We also see these two folders. There's the double dot and the dot. What are those?

[02:04] The dot stands for the current working directory, and the double dot stands for the parent directory of the current folder that you're in. These are special folders that the operating system and the filesystem sets up.

[02:16] If we cd into the double dots, we'll go up a directory, and you can see we're in egghead.bash now. If we cd back to sandbox, we're back there.