π» Week 02 - Lab Roadmap (90 min)
DS105 - Data for Data Science
This week, we will learn to access and navigate your computer in a shell called bash, the most common way to access computers in the cloud (the topic of next weekβs lecture and lab).
By default, bash is available on Unix-based operating systems (Linux and macOS) but not on Windows. Those using Windows will have to install some additional software first.
Step 1: Setting up (5-20 min)
Step 1: Setting up
Windows users
Sadly, Windows command line interfaces differ from those used in Unix-based operating systems (Linux and macOS). Therefore, the commands we will learn today do not apply to Windows.
But fear not! Recent versions of Windows have a feature called Windows Subsystem for Linux, or WSL 1, which you can use to install Linux distributions. You just have to enable it first.
π― ACTION POINTS Follow Steps 1-4 of the tutorial βInstall Ubuntu on Wsl2 on Windows 11 with GUI Support.β
macOS users
π― ACTION POINTS
Open the terminal
Now, to ensure you are using the bash shell, type the following and hit ENTER:
echo $SHELL
If you see the following message printed on the terminal screen, you are all good to move to the next step.
/bin/bash
If instead, you saw the message below:
/bin/zsh
This means your computer came pre-packed with a different terminal called Z Shell. Read and follow the instructions in this tutorial to change your shell to bash 2.
Linux users
You probably already know how to get to the terminal β typically the shortcut Ctrl+T will get you there.
Just ensure you are running the bash shell. If not, follow the same instructions given to macOS users above.Step 2: Locate yourself (20 min)
Step 2: Locating yourself
We will follow the instructions below step by step together while answering whatever questions you might encounter along the way.
Open the bash shell using the instructions from Step 1 above
Type
pwd
and hit ENTER:pwd
You should get a string of text indicating the full path of where you are inside the terminal.
Are you currently in your
$HOME
directory? To find out where your home directory is, use the following command:echo $HOME
Are there any files/sub-directories inside the directory you are currently in? Use
ls
to investigate:ls
or
ls .
Are there any hidden files?
ls -a
Now, letβs explore what is above your current directory:
ls ..
Do you get what the different dots
.
and..
mean 3?Now, more than just look at the parent directory, letβs move there:
cd ..
then use the same
ls
commands you explored above. Did you notice anything different now?Letβs force
ls
to print the same information in a different format. Try the following command:ls . -lth
What does the
-l
,-t
and-h
arguments mean? You can find out by looking at thels
manual:man ls
Use the arrow keys in your keyboard to scroll up and down the manual. Type the character
q
when you are done browsing.Now, try to go back to the directory you were at the start of this tutorial. Hint: if you get stuck, try
pwd
again and compare the output you get now to the one you got the first time you used this command.
Step 3: Wandering away from $HOME
(20 min)
Step 3: Wandering away from $HOME
Now, given what we practiced, try to follow the steps below (help from colleagues is fine) and take note of your answers to the questions.
We will go over the solutions once everyone has finished this step.
π― ACTION POINTS
Go to the root of the filesystem:
cd /
What do you see with
ls
? What does it mean?Walk around freely up and down the directories and sub-directories you encounter along the way. Check the links on π Week 02 Appendix - Linux and the Terminal page to understand where you are navigating.
Which directory(ies) under
/
were you not allowed to enter? Why?What is the difference between the
/root
directory and the root filesystem/
?Go back
$HOME
Step 4: Installing software (10 min)
Step 4: Installing software
π How do you install apps in your computer or smart phone?
It is very likely that you just head to a software store (Play Store, Apple Store or Microsoft Store) and download apps from there. Linux has something similar, you can access and download software using the apt
command. Letβs use it to download the text editor vim.
π― ACTION POINTS
Whenever you want to download software with
apt
, you have to ensure you have the most up-to-date information from the central βstoreβ. You can do this via the following command:sudo apt update
This command requires you to have admin rights (as root), which is why we run it with
sudo
4. You might be asked to type your password.Install vim:
sudo apt install vim
Now you can open vim:
vim
To quit, press
Esc
, then type:q
and hitENTER
. Still stuck and cannot quit vim? You are not alone.
MacOS users
π― ACTION POINTS
You can use βHomebrewβ to install software in a very similar way to apt
command in a Linux system.
First, you need to be sure if homebrew is installed on your system. You can check it with the terminal.
brew
If you receive an error:
zsh: command not found: brew
You should install Homebrew in your system. You can do this with the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if you have not installed XCode before, the installation script will ask you to install it as well, please accept to continue.
You can install vim now:
brew install vim
You can open vim:
vim
You can update
brew
with the command:brew update
Step 5: Creating and editing files and directories (20 min)
Step 5: Creating and editing files and directories
π― ACTION POINTS
Go to your
$HOME
directory or a folder of your choice. Then, create and enter a directory, letβs call it DS105:cd $HOME mkdir DS105 cd DS105
Create a text file and call it
README.txt
:touch README.txt
Open this file with vim:
vim README.txt
Inside vim, write something to the file (your name, a verse, a sentence, whatever comes to mind).
To insert text characters, you need to switch to the Insert Mode
by pressing i
. In the left bottom, you can see βINSERTβ and start to write. You can shift back to βNormal Modeβ by pressing ESC
.
Now save your changes to the file. To save a file when inside vim, press
Esc
then type:w
and hitENTER
.Quit vim: press
Esc
, then type:q
and hitENTER
5.Print the content of your file with the
cat
command:cat README.txt
Formative assignment
Formative assignment
This problem set is not graded but you will get written feedback if you submit.
Follow the steps below and, when asked, copy your responses to the Moodle page of this assignment.
P1: Identify yourself
On the terminal, type the two commands below:
whoami
uname -a
Take a screenshot (how?) of your terminal and submit to Moodle, under the field identified as P1.
P2: Edit a file
Go to the DS105 folder you created earlier:
cd ~/DS105
Rename the
README.txt
toREADME.md
(a markdown file):mv README.txt README.md
Edit the README.md file following the template below, replacing all occurrences of
<>
with your responses:# DS105 Name: <> Date: <> Candidate Number: <> Degree Program: <> ## Notes - I want to learn data science because <>
Save and quit vim.
Print some metadata about your file to prove you were the one editing it:
stat README.md
Print the contents of your file to the terminal:
cat README.md
Take a screenshot (how?) of your terminal and submit to Moodle, under the field identified as P2. Make sure that both the output of
stat
andcat
commands are visible.
(Bonus) π Practice at home: vimtutor
Practice at home: vimtutor
π― ACTION POINTS
Open the terminal and type:
vimtutor
Follow the instructions on the screen and complete the tutorial (a total of 7 short lessons).
Check out the π Week 02 Appendix - π Text editors section for more info on vim
.
Footnotes
Microsoft Tutorial: βWhat Is Windows Subsystem for Linuxββ©οΈ
Curious about the different shells on Mac π€ ? Checkout the full article on βLearn Enough Tutorials: Using Z Shell on Macsβ©οΈ
See the answer to this question on Stackoverflow: βWhat is double dot(..) and single dot(.) in Linux?ββ©οΈ
The
sudo
Wikipedia entry has quite a good summaryβ©οΈStill stuck and cannot quit vim? You are not alone.β©οΈ