Navigating Through the File System

Navigating Through the File System

By Jared York | JaredYork | 12 Jul 2019


In this guide, we will learn how to work with the file system.  Let's cut to the chase.  We can start by opening the terminal.

Now by default, your shell is looking in the home directory.  A shell is a program that processes commands and returns output.  A terminal runs a shell.  I think it's pretty important to clear up this vocabulary before we move on.  We can tell that we are in the current user's home directory by the blue tilde next to your cursor.  Well, what if we want to enter the Documents folder?  No problem, just type in the command:

cd Documents

There we go.  If you take a look at the path now, we can see were are in:

~/Documents

351665157-9b24e82c2e5e7b250a866f631280fc48b00da2c52f9bb93dc99335a2f997b9d8.png

The cd command stands for change directory.  Since the tilde represents the current user's home directory, really you can think of the current path like so:

<your user account name>/Documents

Another useful command to use when you're looking around is the pwd command.  This command allows you to view the full path to the directory you're in.  It's pretty neat!  If you give it a try, you should see the following output:

/home/jared/Documents

Great!  But, what if we want to move up a directory back to our user's home directory?  There are a couple ways to get back, but let's start with one of them.  Try running the following command:

cd ../

Once you run this, you should see that our path ~/Documents is back to ~.  Now, what if you wanted to move up two directories?  Since the user's home directory is within the home directory, which in turn is in the root directory, we can move to the root directory by moving up two levels.

cd ../../

If we run this, you will notice that the tilde changed to a forward slash.  How else do we know that we are in the home directory?  Run the following command to find out:

ls

If we run this command, all the files and directories in the root directory will be listed.

351665157-672f2baaf867551b5f24bffe825566f8abd3cb397cd6f42a31deaf51eca1af3c.png

Likewise, we can navigate back to our user's home directory like so:

cd /home/<your user account name here>

351665157-02608453ae629668f2fc4d1ab4dad0df7b82210355f592e7dce7cbbcb04f01a4.png

You can also specify absolute paths to directories.  For example, if you're currently in the root directory but you want to go to your user's Documents folder, you can do so by:

cd /home/<your user account name>/Documents

This will move the shell to the Documents folder.  Fantastic!

And that concludes this part of my blog, Linux Terminal Survival Guide.  I hope this series is able to help some of you beginners out there become masters at using the terminal!


Jared York
Jared York

business owner, programmer, game developer, educator, coffee enthusiast


JaredYork
JaredYork

The blog where I ramble about tech, crypto, and other things that interest me.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.