Navigating the filesystem
Last updated on 2026-10-21 | Edit this page
Estimated time: 20 minutes
Overview
Questions
- Why do we use the shell in a Git workshop?
- How do you move around the filesystem in the shell?
Objectives
- explain why the Unix shell is used to work with Git
- apply shell commands to find out where you are in the file system and to move between directories
- apply flags to change the behaviour of a command, e.g. to show hidden files
- apply
manor--helpto look up the options of a command
Why the shell?
In this workshop we will use Git from the Unix shell (also called command line or terminal). There are graphical programs for Git, too, but the shell has some advantages for learning: the commands are the same on Windows, macOS and Linux, you see exactly what Git is doing, and almost every help page and tutorial you will find online uses the command line.
Before we start with Git, we will therefore learn the few shell commands that we need to find our way around: moving between folders and working with files.
Navigating the shell
For notes about OneDrive, see the Instructor Notes.
Let’s start by opening the shell (on Windows: Git Bash, on macOS and
Linux: Terminal, see Setup). This likely
results in seeing a black or white window with a cursor flashing next to
a dollar sign. This is our command line, and the $ is the
command prompt to show that the system is ready for our
input. The appearance of the prompt will vary from system to system,
depending on how the set up has been configured. Other common prompts
include the % or # signs, but we will use
$ in this lesson to represent the prompt generally.
When working in the shell, you are always somewhere in the
computer’s file system, in some folder (directory). We will therefore
start by finding out where we are by using the pwd command,
which you can use whenever you are unsure about where you are. It stands
for “print working directory” and the result of the command is printed
to your standard output, which is the screen.
Let’s type pwd and press enter to execute the command
(Note that the $ sign is used to indicate a command to be
typed on the command prompt, but we never type the $ sign
itself, just what follows after it.):
OUTPUT
/Users/riley
The output will be a path to your home directory (in Git Bash on
Windows it looks like /c/Users/riley). Let’s check if we
recognise it by looking at the contents of the directory. To do that, we
use the ls command. This stands for “list” and the result
is a print out of all the contents in the directory:
OUTPUT
Applications Documents Library Music Public
Desktop Downloads Movies Pictures
We may want more information than just a list of files and
directories. We can get this by specifying various
flags (also known as options,
parameters, or, most frequently, arguments) to
go with our basic commands. Arguments modify the workings of the command
by telling the computer what sort of output or manipulation we want.
If we type ls -l and press enter, the computer returns a
list of files that contains information similar to what we would find in
our Finder (Mac) or Explorer (Windows): the size of the files in bytes,
the date it was created or last modified, and the file name.
OUTPUT
total 0
drwx------+ 6 riley staff 204 Jul 16 11:50 Desktop
drwx------+ 3 riley staff 102 Jul 16 11:30 Documents
drwx------+ 3 riley staff 102 Jul 16 11:30 Downloads
drwx------@ 46 riley staff 1564 Jul 16 11:38 Library
drwx------+ 3 riley staff 102 Jul 16 11:30 Movies
drwx------+ 3 riley staff 102 Jul 16 11:30 Music
drwx------+ 3 riley staff 102 Jul 16 11:30 Pictures
drwxr-xr-x+ 5 riley staff 170 Jul 16 11:30 Public
In everyday usage we are more accustomed to units of measurement like
kilobytes, megabytes, and gigabytes. Luckily, there’s another flag
-h that when used with the -l option, prints unit suffixes:
Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to
reduce the number of digits to three or fewer using base 2 for
sizes.
Now ls -h won’t work on its own. When we want to combine
two flags, we can just run them together. So, by typing
ls -lh and pressing enter we receive an output in a
human-readable format (note: the order here doesn’t matter).
OUTPUT
total 0
drwx------+ 6 riley staff 204B Jul 16 11:50 Desktop
drwx------+ 3 riley staff 102B Jul 16 11:30 Documents
drwx------+ 3 riley staff 102B Jul 16 11:30 Downloads
drwx------@ 46 riley staff 1.5K Jul 16 11:38 Library
drwx------+ 3 riley staff 102B Jul 16 11:30 Movies
drwx------+ 3 riley staff 102B Jul 16 11:30 Music
drwx------+ 3 riley staff 102B Jul 16 11:30 Pictures
drwxr-xr-x+ 5 riley staff 170B Jul 16 11:30 Public
Some files and directories are hidden: their names start with a dot
(.), and ls does not show them by default. To
see them, we add the -a flag (for “all”):
OUTPUT
. .bash_history Applications Documents Library Music Public
.. .gitconfig Desktop Downloads Movies Pictures
Remember this flag: Git stores all its information in a hidden
directory called .git, and ls -a is how we
will find it later. The entries . and .. are
special: . means “the current directory” and
.. means “the directory above”.
We’ve now spent a great deal of time in our home directory. Let’s go
somewhere else. We can do that through the cd or Change
Directory command: (Note: On Windows and Mac, by default, the case of
the file/directory doesn’t matter. On Linux it does.)
Notice that the command didn’t output anything. This means that it
was carried out successfully. Let’s check by using pwd:
OUTPUT
/Users/riley/Desktop
If something had gone wrong, however, the command would have told you. Let’s test that by trying to move into a non-existent directory:
OUTPUT
bash: cd: things to learn about the shell: No such file or directory
Notice that we surrounded the name by quotation marks. The arguments given to any shell command are separated by spaces, so a way to let them know that we mean ‘one single thing called “things to learn about the shell”’, not ‘six different things’, is to use (single or double) quotation marks.
Avoid spaces in file and directory names
Spaces in names are allowed, but they make working in the shell more
cumbersome, because you always have to remember the quotation marks. For
your project folders and research data, use - or
_ instead, for example my-git-repo-riley or
2026-10_survey_data.csv.
We’ve now seen how we can go ‘down’ through our directory structure
(as in into more nested directories). If we want to go back, we can type
cd ... This moves us ‘up’ one directory, putting us back
where we started. If we ever get completely lost, the command
cd without any arguments will bring us right back to the
home directory, the place where we started.
Previous Directory
To switch back and forth between two directories use
cd -
Try exploring
Move around the computer, get used to moving in and out of
directories, see how different file types appear in the Unix shell. Be
sure to use the pwd and cd commands, and the
different flags for the ls command you learned so far.
If you run Windows, also try typing explorer . to open
Explorer for the current directory (the single dot means “current
directory”). If you’re on a Mac, try open . and for Linux
try xdg-open . to open their graphical file manager.
Being able to navigate the file system is very important for using the Unix shell effectively. As we become more comfortable, we can get very quickly to the directory that we want.
Getting help
Use the man command to invoke the manual page
(documentation) for a shell command. For example, man ls
displays all the arguments available to you - which saves you
remembering them all! Use the spacebar to navigate the manual
pages. Use q at any time to quit.
Note: this command is for Mac and Linux users
only. In Git Bash on Windows, type the command name followed by
--help instead, e.g. ls --help.
Find out how to list the files in a directory ordered by their last
modification date. Can you combine it with the -l
argument you learned before?
- Knowing where you are in your directory structure is key to working with the shell
-
pwdshows where you are,lslists the contents of a directory andcdmoves you to another directory -
ls -aalso shows hidden files and directories, whose names start with a dot -
manor--helpshow the options of a command