How to move around the filesystem

Basic commands necessary for utilizing a linux terminal

The filesystem is the configuration of your system, in linux everything is a file, this makes it easier to interact with all resources on your system, everything will have permissions, and be able to be interacted with in the same basic ways. In order to successfully utilize the terminal you'll need to understand how to traverse the filesystem.

Begin by opening a terminal. The application should already be installed on your machine. The first thing you'll see is the following:

$ # The dollar sign indicates that you are a regular user

Normally you'll be a regular user this is indicated by the $ occasionally you'll need to become a super user (called root) - you can think of this as the system's admin account. This user has no limits so you must be careful when you become root.

The # sign in front of text such as this indicates a comment.

Who are you?

whoami
# Now that we know we're a regular user wwe should find out who that is
# In order to understand who you are simply type: `whoami`
# The output should be the user you're logged in as in my case its:
theo

How to see where you are:

pwd
# this shows you your current location 
# `pwd` stands for "print working directory"
# The output should be your home directory and should look like:
/home/theo/

What is in here?

ls
# ls stands for list and shows you everything in the current directory
# the output will look something like this:
Desktop Documents Downloads Music Pictures Public Templates Videos
# By default ls sorts things in alphabetical order

How to change locations

cd Desktop/
# Desktop is a directory in order to move into type `cd`
# cd stands for change directory in this case you are
# literally changing directories from /home/theo/ to 
# /home/theo/Desktop
# there is no output for this command you can verify its success
# by typing `pwd` the output of that should look like: 
/home/theo/Desktop # note if you are not theo, it'll be different

How to create a file:

touch myfile.txt
# touch creates empty files you can utilize this to quickly make files
# linux does not assume file types other than .txt you'll need to specify
# you can verify the file was created by running: 
ls
# the output of ls will print all contents of the directory
# to include our new file with nothing on the Desktop by default 
# The output should be:

myfile.txt
# with touch you can create multiple files separating them with a space

touch yourfile.txt theirfile.sh
# again to verify simply list the contents of the directory with: 
ls
# the output of this should now be 
myfile.txt theirfile.sh yourfile.txt
# remember ls sorts by alphabetical order by default

How to remove a file:

rm myfile.txt
# rm is the base command for removing files, be careful as there is not
# a trash for the rm command. Anything removed with rm is gone forever 
# There is no output for this command 
# In order to verify this worked correctly we run ls
ls
# The ls output should be: 
theirfile.sh yourfile.txt

How to go back a directory:

rm may or may not prompt you for comfirmation to ensure you want to permananently delete the file, this is a nice feature but isn't the default eveyrwhere, so ensure you're in the right directory with pwd and use ls to ensure it's the proper file.

cd ../
# to go back a directory issue the above command 
# there is no output for this command, you can run `pwd` to verify
# The output should be your home directory and should look like:
/home/theo/

Last updated