Recap of Command Line
Last updated on 2025-05-14 | Edit this page
Overview
Questions
- How can I see the files on my computer?
- How can I move between directories?
Objectives
- Understand the basics of the command line
- Understand how to list files and move around directories
The next few episodes introduce the commands needed to view files and move between directories (folders) on your computer.
The full details of how to use the command line are covered in the lesson Introduction to the Unix Shell. Learners are encouraged to look at those resources as this will help your understanding, but they are not needed for this lesson. In this lesson, we will have a quick recap of those commands.
The Shell/terminal
When you open git bash you will be presented with a terminal
(sometimes called a shell). The look and layout of the terminal
may vary depending on the program and computer it is on, but they
usually follow a similar layout. This layout typically has some
information about the user and machine in the form
user@machine
, information about where you are in the
directory structure (often ~
) and a prompt
($
). The prompt is where we will type in commands
(instructions) for the shell to run.
Where am I?
The first thing we may want to do is know where we are in in the
directory structure. We can find this out using the print
working directory command, pwd
. At the
command prompt, type pwd
. The press enter
to
run (or execute) the command.
OUTPUT
/c/Users/Alfredo/
Home directory variation
The directory path for your home area varies by operating
system. In Linux it it often /home/username
. In Windows it
tends to be /c/Users/username/
.
You are perhaps more familiar with it looking like this:
C:/Users/username
in windows. These two are the same,
however linux uses a forward slash to separate directories instead of a
backslash, and everything is in /
instead of lettered
drives. /
is known as the root directory.
Looking around
Now that we know where we are, we may want to see what files exist in
our home area. We can do this with the listings command,
ls
.
OUTPUT
Desktop Downloads Mywork.txt
This will output the contents of the directory to the screen.
Directories and files may appear in different colours, if they don’t you
can use the -F
flag to decorate the names:
OUTPUT
Desktop/ Downloads/ Mywork.txt
Moving around
To move between directories in the terminal we use the
change directory command, cd
. Typing
cd
without arguments will always take you to your home
directory. We can however pass arguments to cd
to tell it
where we want to move to.
OUTPUT
/c/Users/Alfredo/Desktop
To move back to out home directory we have a few options: -
cd ..
: ..
means the directory above (or
directory to the left when the path is printed). - cd -
:
-
takes you to the previous directory you were in. -
cd ~
: ‘~’ is a shortcut for home directory. -
cd /c/Users/Alfredo/
: The full path to our home
directory.
Paths
The path is the location of a file or directory. It describes where
it is. There are two types, relative and absolute. A relative path
describes how to get to a file or directory from where you are, usually
these do not begin with a forward slash (/
) and look like
these examples:
../Desktop
Downloads/Data/Carpentries
../../Alfredo/
Notice how we can chain many ..
together to go up many
more than one directory.
Absolute paths describe exactly where something is on a system, and start with a forward slash:
/c/Users/Alfredo/
/c/Users/Alfredo/Desktop
A special case is ~
which is a shortcut for your home
directory, we can use this in many ways:
- `~/Desktop/
~/../Alfredo
Key Points
-
pwd
shows us where we are. -
ls
lists the files in our directory -
cd
allows us to change directory and move around. -
~
is a shortcut for home area. -
..
means directory above, or parent directory