Skip to content

Commit

Permalink
Update material to reflect new directory structure
Browse files Browse the repository at this point in the history
Fix #1225.
  • Loading branch information
gcapes committed Jan 7, 2022
1 parent 6e7622e commit c24e262
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 122 deletions.
89 changes: 36 additions & 53 deletions episodes/02-filedir.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,7 @@ $ ls -F Desktop/shell-lesson-data
{: .language-bash}
~~~
creatures/ molecules/ notes.txt pizza.cfg writing/
data/ north-pacific-gyre/ numbers.txt solar.pdf

exercise-data/ north-pacific-gyre/
~~~
{: .output}
Expand All @@ -400,18 +398,19 @@ use the following series of commands to get there:
~~~
$ cd Desktop
$ cd shell-lesson-data
$ cd data
$ cd exercise-data
~~~
{: .language-bash}
These commands will move us from our home directory into our Desktop directory, then into
the `shell-lesson-data` directory, then into the `data` directory.
the `shell-lesson-data` directory, then into the `exercise-data` directory.
You will notice that `cd` doesn't print anything. This is normal.
Many shell commands will not output anything to the screen when successfully executed.
But if we run `pwd` after it, we can see that we are now
in `/Users/nelle/Desktop/shell-lesson-data/data`.
in `/Users/nelle/Desktop/shell-lesson-data/exercise-data`.
If we run `ls -F` without arguments now,
it lists the contents of `/Users/nelle/Desktop/shell-lesson-data/data`,
it lists the contents of `/Users/nelle/Desktop/shell-lesson-data/exercise-data`,
because that's where we now are:
~~~
Expand All @@ -420,7 +419,7 @@ $ pwd
{: .language-bash}
~~~
/Users/nelle/Desktop/shell-lesson-data/data
/Users/nelle/Desktop/shell-lesson-data/exercise-data
~~~
{: .output}
Expand All @@ -430,8 +429,7 @@ $ ls -F
{: .language-bash}
~~~
amino-acids.txt animals.txt morse.txt planets.txt sunspot.txt
animal-counts/ elements/ pdb/ salmon.txt
animal-counts/ backup/ creatures/ numbers.txt project/ proteins/ writing/
~~~
{: .output}
Expand Down Expand Up @@ -490,8 +488,7 @@ $ ls -F -a
{: .language-bash}
~~~
./ .bash_profile data/ north-pacific-gyre/ numbers.txt solar.pdf
../ creatures/ molecules/ notes.txt pizza.cfg writing/
./ ../ exercise-data/ north-pacific-gyre/
~~~
{: .output}
Expand Down Expand Up @@ -542,14 +539,14 @@ $ pwd
{: .output}
It turns out that `cd` without an argument will return you to your home directory,
which is great if you've gotten lost in your own filesystem.
which is great if you've got lost in your own filesystem.
Let's try returning to the `data` directory from before. Last time, we used
Let's try returning to the `exercise-data` directory from before. Last time, we used
three commands, but we can actually string together the list of directories
to move to `data` in one step:
to move to `exercise-data` in one step:
~~~
$ cd Desktop/shell-lesson-data/data
$ cd Desktop/shell-lesson-data/exercise-data
~~~
{: .language-bash}
Expand All @@ -571,7 +568,7 @@ the root of the file system, so it always refers to exactly one directory,
no matter where we are when we run the command.
This allows us to move to our `shell-lesson-data` directory from anywhere on
the filesystem (including from inside `data`). To find the absolute path
the filesystem (including from inside `exercise-data`). To find the absolute path
we're looking for, we can use `pwd` and then extract the piece we need
to move to `shell-lesson-data`.
Expand All @@ -581,7 +578,7 @@ $ pwd
{: .language-bash}
~~~
/Users/nelle/Desktop/shell-lesson-data/data
/Users/nelle/Desktop/shell-lesson-data/exercise-data
~~~
{: .output}
Expand Down Expand Up @@ -617,9 +614,9 @@ Run `pwd` and `ls -F` to ensure that we're in the directory we expect.
> ~~~
> {: .language-bash}
>
> Then `cd` into the `creatures` directory
> Then `cd` into the `exercise-data/creatures` directory
> ~~~
> $ cd creatures
> $ cd exercise-data/creatures
> ~~~
> {: .language-bash}
>
Expand All @@ -629,7 +626,7 @@ Run `pwd` and `ls -F` to ensure that we're in the directory we expect.
> ~~~
> {: .language-bash}
> you'll see you're back in `~/Desktop/shell-lesson-data`.
> Run `cd -` again and you're back in `~/Desktop/shell-lesson-data/creatures`
> Run `cd -` again and you're back in `~/Desktop/shell-lesson-data/exercise-data/creatures`
{: .callout}
> ## Absolute vs Relative Paths
Expand Down Expand Up @@ -754,22 +751,23 @@ while `ls -S` will sort the files and directories by size, as shown below:
~~~
$ cd ~/Desktop/shell-lesson-data
$ ls -s data
$ ls -s exercise-data
~~~
{: .language-bash}
~~~
total 116
4 amino-acids.txt 4 animals.txt 4 morse.txt 12 planets.txt 76 sunspot.txt
4 animal-counts 4 elements 4 pdb 4 salmon.txt
total 28
4 animal-counts 4 creatures 12 numbers.txt 4 proteins 4 writing
~~~
{: .output}
~~~
$ ls -S data
$ ls -S exercise-data
~~~
{: .language-bash}
~~~
sunspot.txt animal-counts pdb amino-acids.txt salmon.txt
planets.txt elements morse.txt animals.txt
animal-counts creatures proteins writing numbers.txt
~~~
{: .output}
Expand Down Expand Up @@ -798,24 +796,9 @@ First,
she creates a directory called `north-pacific-gyre`
(to remind herself where the data came from).
Inside that,
she creates a directory called `2012-07-03`,
which is the date she started processing the samples.
She used to use names like `conference-paper` and `revised-results`,
but she found them hard to understand after a couple of years.
(The final straw was when she found herself creating
a directory called `revised-revised-results-3`.)
> ## Sorting Output
>
> Nelle names her directories 'year-month-day',
> with leading zeroes for months and days,
> because the shell displays file and directory names in alphabetical order.
> If she used month names,
> December would come before July;
> if she didn't use leading zeroes,
> November ('11') would come before July ('7'). Similarly, putting the year first
> means that June 2012 will come before June 2013.
{: .callout}
she creates a directory called `data`,
which will contains the data files from the assay machine.
Each of her physical samples is labelled according to her lab's convention
with a unique ten-character ID,
Expand All @@ -827,11 +810,14 @@ Since the assay machine's output is plain text,
she will call her files `NENE01729A.txt`, `NENE01812A.txt`, and so on.
All 1520 files will go into the same directory.
She also creates a `scripts` directory to contain the processing script `goostats.sh`
written by her supervisor, and any new scripts she will write for this project.
Now in her current directory `shell-lesson-data`,
Nelle can see what files she has using the command:
~~~
$ ls north-pacific-gyre/2012-07-03/
$ ls north-pacific-gyre/
~~~
{: .language-bash}
Expand All @@ -852,13 +838,10 @@ $ ls north-pacific-gyre/
~~~
{: .language-bash}
If she presses <kbd>Tab</kbd> again,
Bash will add `2012-07-03/` to the command,
since it's the only possible completion.
Pressing <kbd>Tab</kbd> again does nothing,
since there are 19 possibilities;
pressing <kbd>Tab</kbd> twice brings up a list of all the files,
and so on.
since there are 2 possibilities;
pressing <kbd>Tab</kbd> twice brings up a list of all the directories.
Nelle can select the `data` directory by typing <kbd>D</kbd> and pressing <kbd>Tab</kbd> again.
This is called **tab completion**,
and we will see it in many other tools as we go on.
Expand Down
51 changes: 29 additions & 22 deletions episodes/03-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ keypoints:
We now know how to explore files and directories,
but how do we create them in the first place?

In this episode we will learn about creating and moving files and directories,
using the `exercise-data/writing` directory as an example.

### Step one: see where we are and what we already have
Let's go back to our `shell-lesson-data` directory on the Desktop
and use `ls -F` to see what it contains:
We should still be in the `shell-lesson-data` directory on the Desktop,
which we can checking using:

~~~
$ pwd
Expand All @@ -39,14 +42,19 @@ $ pwd
~~~
{: .output}

Next we'll move to the `exercise-data/writing` directory and see what it contains:
~~~
$ cd `exercise-data/writing`
~~~
{: .language-bash}

~~~
$ ls -F
~~~
{: .language-bash}

~~~
creatures/ molecules/ notes.txt pizza.cfg writing/
data/ north-pacific-gyre/ numbers.txt solar.pdf
haiku.txt LittleWomen.txt
~~~
{: .output}

Expand All @@ -72,8 +80,7 @@ $ ls -F
{: .language-bash}

~~~
creatures/ molecules/ notes.txt pizza.cfg thesis/
data/ north-pacific-gyre/ numbers.txt solar.pdf writing/
haiku.txt LittleWomen.txt thesis/
~~~
{: .output}

Expand All @@ -89,7 +96,7 @@ The `-p` option allows `mkdir` to create a directory with nested subdirectories
in a single operation:

~~~
$ mkdir -p project/data project/results
$ mkdir -p ../project/data ../project/results
~~~
{: .language-bash}

Expand All @@ -98,17 +105,17 @@ Let's use `ls -FR` to recursively list the new directory hierarchy we just creat
`project` directory:

~~~
$ ls -FR project
$ ls -FR ../project
~~~
{: .language-bash}

~~~
project/:
../project/:
data/ results/
project/data:
../project/data:
project/results:
../project/results:
~~~
{: .output}

Expand Down Expand Up @@ -292,10 +299,10 @@ draft.txt
{: .callout}
## Moving files and directories
Returning to the `shell-lesson-data` directory,
Returning to the `shell-lesson-data/writing` directory,
```
$ cd ~/Desktop/shell-lesson-data/
$ cd ~/Desktop/shell-lesson-data/writing
```
{: .language-bash}
Expand Down Expand Up @@ -544,7 +551,7 @@ quotations.txt
## Removing files and directories
Returning to the `shell-lesson-data` directory,
Returning to the `shell-lesson-data/writing` directory,
let's tidy up this directory by removing the `quotes.txt` file we created.
The Unix command we'll use for this is `rm` (short for 'remove'):
Expand Down Expand Up @@ -631,29 +638,29 @@ or specifying a naming pattern using wildcards.
> ## Copy with Multiple Filenames
>
> For this exercise, you can test the commands in the `shell-lesson-data/data` directory.
> For this exercise, you can test the commands in the `shell-lesson-data/exercise-data` directory.
>
> In the example below, what does `cp` do when given several filenames and a directory name?
>
> ~~~
> $ mkdir backup
> $ cp amino-acids.txt animals.txt backup/
> $ cp creatures/minotaur.dat creatures/unicorn.dat backup/
> ~~~
> {: .language-bash}
>
> In the example below, what does `cp` do when given three or more file names?
>
> ~~~
> $ cd creatures
> $ ls -F
> ~~~
> {: .language-bash}
> ~~~
> amino-acids.txt animals.txt elements/ pdb/ salmon.txt
> animal-counts/ backup/ morse.txt planets.txt sunspot.txt
> basilisk.dat minotaur.dat unicorn.dat
> ~~~
> {: .output}
> ~~~
> $ cp amino-acids.txt animals.txt morse.txt
> $ $ cp minotaur.dat unicorn.dat basilisk.dat
> ~~~
> {: .language-bash}
>
Expand All @@ -666,7 +673,7 @@ or specifying a naming pattern using wildcards.
> > because it is expecting a directory name as the last argument.
> >
> > ```
> > cp: target 'morse.txt' is not a directory
> > cp: target 'basilisk.dat' is not a directory
> > ```
> > {: .error}
> {: .solution}
Expand All @@ -677,7 +684,7 @@ or specifying a naming pattern using wildcards.
> ## Wildcards
>
> `*` is a **wildcard**, which matches zero or more characters.
> Let's consider the `shell-lesson-data/molecules` directory:
> Let's consider the `shell-lesson-data/exercise-data/proteins` directory:
> `*.pdb` matches `ethane.pdb`, `propane.pdb`, and every
> file that ends with '.pdb'. On the other hand, `p*.pdb` only matches
> `pentane.pdb` and `propane.pdb`, because the 'p' at the front only
Expand Down Expand Up @@ -706,7 +713,7 @@ or specifying a naming pattern using wildcards.
> ## List filenames matching a pattern
>
> When run in the `molecules` directory, which `ls` command(s) will
> When run in the `proteins` directory, which `ls` command(s) will
> produce this output?
>
> `ethane.pdb methane.pdb`
Expand Down
Loading

0 comments on commit c24e262

Please sign in to comment.