Learning Objectives
After this lesson, students will be able to:
- recognize the elements of the unix shell
- will be able to use paths to files and directories
- understand the difference between absolute and relative paths
Day 1
Intro
- the data life cycle homework review
- Computers (and programming) are key tools for data science
- “Introducing the Shell” reading discussion:
- What is a GUI?
- What is a command shell?
- A command-line interface (CLI); how else do we interact with computers? Interfaces exercise.
- A scripting language; what is a scripting language? High-level languages presentation.
- Banksy fetch
- Programming and scripting languages provide a set of written rules that give instructions to a computational device (such as a computer) to perform a set of tasks.
- “Programming languages are artificial languages that can be used to control the behaviour of a machine, particularly a computer”.
- Different programming and scripting languages have different strengths.
- Why would I use the command shell? What are the strengths of the shell?
- Explain how the shell relates to the keyboard, the screen, the operating system, and users’ programs.
- Explain when and why command-line interfaces should be used instead of graphical interfaces.
- What is the prompt?
Navigating Files and Directories (40 min)
- SWC lesson
- the file system
- command
pwd
- the home directory and its variations
- the two meaning of the “forward slash”
/
- the command
ls
- getting help with
man ls
- the option
ls -F
- options that throw errors
- explore other directories with
ls -F Desktop
- changing locations down the file system with
cd
- going up in the file system with
..
.
means the current directoryls -F -a
- using
cd
with no argument to go back home - using the “tilde”
~
as shortcut of the current home directory - using
cd -
to go back - defining commands, options and arguments
- other names for options and arguments are parameters, switches or flags
-
capitalization is meaningful, example:
ls -s
vsls -S
- Joint exercise Absolute vs Relative Paths
- Solo exercise Relative Path Resolution
Working With Files and Directories (50 min)
- SWC lesson
- creating directories with
mkdir
andmkdir -p
- list nested directories with
ls -FR
- use the finder to see the folders you just created
- good names for files and directories do not use blank spaces
- creating a text file with
nano
- using the nano text editor
- homework challenge: creating a text file with
touch
- file extensions
- moving files and directories with
mv
- copying files and directories with
cp
- removing files with
rm
and directories withrm -r
- wildcards
*
and?
- Challenge
- Homework activities
Day 2
Pipes and filters (35 min)
A) Go into teams of 2 or 3 people. Find a name for your team and write it down in the etherpad along with the names of the team members. Take 5-7 min to do so.
B) Read https://swcarpentry.github.io/shell-novice/04-pipefilter/index.html and run along the example code on the terminal (as well as the exercises!). Email the code to your instructor once you are done. You can email the code as a .txt file or directly on the body of the email.
C) As you read, discuss with your team and answer:
1) what does the command wc
do?
2) what do the options -l
, -m
, and -w
from the wc
command do?
3) How do you escape a waiting command?
4) What symbol do you use to redirect output to a file instead of printing it to the screen?
5) What does the cat
command do?
6) What does sort -n
do?
7) What command can you use to confirm that a file exists?
8) What is the main difference between the cat
and less
commands?
9) What happens if you redirect the output of a command operating on a file to the same file?
10) What does the symbol >>
do?
11) What is the main difference between the commands head
and tail
?
12) What symbol do you use to pass the output of a command as input of the next command?
13) What is a pipeline?
14) What is the main difference between redirecting and piping an output?
15) What does the uniq
command do?