Tue Jan 31 19:07:35 EST 2023

Studio 1: File System and Basic Unix Commands

Introduction

We will walk through this material in the studio part of the first class on February 1. You're welcome to start before then.

By the end of this session you should be comfortable with the Unix file system and minimal use of a commandline interface. You will have downloaded a dataset from the web and put it in its own directory.

We will use the file barrett.zip, which contains the Sonnets from the Portuguese by Elizabeth Barrett Browning.

You must use a computer for this studio (and the next few as well); you can't do it on a tablet. You should already have done the setup exercise Studio 0. If you haven't, do that now; we'll wait for you, though not for long.

In the following, we will indicate what you have to do in pink code blocks like this one:

open a Terminal window
	on macOS it's in Applications / Utilities
	on Win11 Start / All apps / Ubuntu (if you did Studio 0)

When the window starts, it may display a variety of mysterious text, but will eventually settle down with a "prompt", which is the signal that you can type commands that tell the system what to do. One command per line, hence "commandline". The prompt is usually a $, often preceded by a longer string of characters. Here's an example:

At this point, you can start experimenting with commands for navigating the file system.

Where am I?

$ pwd
		"print working directory".  you start in your home directory

What's there?

$ ls
		list names of files
$ ls -l
		"long" list permissions, owner, size, change date, name
$ ls -lt
		sorted by time of last change
$ ls -ltr
		prints them in reverse time order, so most recent at the end

Moving around

$ cd Downloads
		change directory
$ cd ..
		change directory to parent, which is called ".."
		try cd Destkop, Documents,  and other directories
$ cd ..
		if you repeat this often enough, you'll get all the way to the root
		the root is "/", so cd / takes you there directly
$ cd
		back to your home directory

Make a directory

$ mkdir hum307
		make a new directory within current directory
$ cd hum307
		change to it
$ ls -l
		list its contents

Get a file from the Internet

You can download a file using your favorite browser; it's likely to wind up in your Downloads folder, from whence you can move it to someplace else.

Alternatively, you can use the commandline program curl, which is an all-purpose program for fetching data from web pages.

$ cd hum307
		if you're not there already
$ mkdir barrett
$ cd barrett
		make a new directory for her sonnets and change to it
$ curl -L -k 'www.hum307.com/barrett.zip' -o barrett.zip
		one way to get something from the web (-L -k are magic for now)

		Alternatively, download it from the web page with your browser
		and use your newfound expertise to move it from your Download directory
		to this directory
$ ls -l barrett.zip
		you know this one by now

See what's in it before unzipping

$ unzip -lv barrett.zip
		-lv shows you what's there but doesn't do anything

Then unzip it

$ unzip barrett.zip
		really does unzip the contents
$ ls -l
		look at the names
$ cat README
		print the README

Create and edit a file

You need to know how to use a real text editor (NOT Word)
on macOS, you might use TextEdit
	Applications / Utilities
	You have to set the mode to plain text !!!!!
on Windows, you might use Notepad
	an ancient standby
on either, you might use nano (or pico)
	very simple, idiot-proof, not mouse-friendly

Here's a screenshot of nano in action:
       
As a temporary expedient, you can also create files with the "echo" command:

$ echo hello there >f1
$ echo farewell cruel world >f2

File manipulations

$ cp f1 f1.save
		copy file f1 to f1.save (so you now have two copies)
$ cat f1
		concatenate f1 to terminal (print)
		"more" and "less" are alternatives for page-at-a-time reading
$ mv f1 f2
		move f1 to f2: rename, so you still have one copy
$ cmp f1 f2
		compare f1 to f2; tells you whether they are the same
$ diff f1 f2
		tells you how the files differ
$ rm f2
		remove f2.  no training wheels: f2 is gone forever.

The online manual

$ man diff
		the manual page for diff (and similarly for all commands)
		though this is often way more than is needed or wanted
The first assignment is to do the same kinds of operations with a different file, a zip file of sonnets by some guy named Shakespeare.