Navigating the Filesystem
reading
We will loosely follow the Software Carpentry lesson on The Unix Shell
The shell
The shell is your interface to the operator system. It implements a REPL interface: Read, Execute, Print, Loop. This means it:
Reads the input (commands) you type
Executes the command
Prints the result of the command
Loops back to the start, waiting to read a new command
The power of the shell is that we can easily combine different tools together to create powerful commands to manipulate files on the computer.
To access the shell, we need to open a terminal on the computer.
Here’s a quick demonstration: the echo
command simply prints anything following
it to the terminal:
echo Hello, World
Which shell?
There are a wide variety of shells that are used today. The default on many systems is BASH. Others that you might commonly encounter are zsh and fish.
We’ll focus on BASH, and most of what we learn here will apply directly to the other shells.
Some online shell documentation:
The Software Carpentry Unix Shell lesson
The official Bash Reference Manual
A basic “cheat sheet” is available here: Unix/Linux Command Reference.
Setting up
To help us understand some basic shell operations, we will all work with a collection of files and directories. Type the following commands (we’ll explain their meaning later) to get the files we need
curl https://swcarpentry.github.io/shell-novice/data/shell-lesson-data.zip --output shell-lesson-data.zip
unzip shell-lesson-data.zip
This data set comes from the Software Carpentry project.
This creates a directory on the filesystem named shell-lesson-data/
. To begin, we want to
“change directory” into that directory, using the cd
command:
cd shell-lesson-data
First walkthrough
Let’s walkthrough the Navigating Files and Directories lesson together. You are also encouraged to work through it on your own outside of class.
Filesystem terminology
We’ll use the following terms throughout here:
file system
: the collection (and organization) of all of the files stored on your computerfile
: a single unit containing a collection of datadirectory
: (also known as a folder) a collection of files and directorieshome directory
: your default directory. When you first open a shell on your computer, this is where you are.
Summary
We learned the following commands:
pwd
: print working directory (where you currently are in the file system)ls
: list the contents of a directorycd
: change directory
There are a few special directories that always exist the help us navigate:
.
: the current directory..
: one directory above us~
: our home directory
The /
character has 2 roles:
The
/
directory is the root of the filesystemA path uses
/
to separate directory names
Tip
The Unix shell uses tab-completion to make it easier to type. Start typing a path (or command) and then press the Tab key and it will either complete it (if there is a unique file / command) or display the possible completions.
Tip
You can navigate through your history of commands using the up and down arrows.