Skip to content

Commit

Permalink
Update material to reflect new directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gcapes committed Sep 7, 2021
1 parent 69edb08 commit 8e6eca3
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 143 deletions.
85 changes: 34 additions & 51 deletions _episodes/02-filedir.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,7 @@ $ ls -F Desktop/shell-lesson-data
{: .language-bash}
~~~
creatures/ molecules/ notes.txt solar.pdf
data/ north-pacific-gyre/ pizza.cfg writing/
exercise-data/ north-pacific-gyre/
~~~
{: .output}
Expand All @@ -400,15 +399,18 @@ 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. 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`.
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/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 @@ -417,7 +419,7 @@ $ pwd
{: .language-bash}
~~~
/Users/nelle/Desktop/shell-lesson-data/data
/Users/nelle/Desktop/shell-lesson-data/exercise-data
~~~
{: .output}
Expand All @@ -427,8 +429,7 @@ $ ls -F
{: .language-bash}
~~~
amino-acids.txt elements/ pdb/ salmon.txt
animals.txt morse.txt planets.txt sunspot.txt
animal-counts/ backup/ creatures/ numbers.txt project/ proteins/ writing/
~~~
{: .output}
Expand Down Expand Up @@ -487,8 +488,7 @@ $ ls -F -a
{: .language-bash}
~~~
./ .bash_profile data/ north-pacific-gyre/ pizza.cfg thesis/
../ creatures/ molecules/ notes.txt solar.pdf writing/
./ ../ exercise-data/ north-pacific-gyre/
~~~
{: .output}
Expand Down Expand Up @@ -552,14 +552,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 @@ -581,7 +581,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 @@ -591,7 +591,7 @@ $ pwd
{: .language-bash}
~~~
/Users/nelle/Desktop/shell-lesson-data/data
/Users/nelle/Desktop/shell-lesson-data/exercise-data
~~~
{: .output}
Expand Down Expand Up @@ -627,9 +627,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 @@ -639,7 +639,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 @@ -756,13 +756,11 @@ For example, `ls -s` will display the size of files and directories alongside th
while `ls -S` will sort the files and directories by size, as shown below:
~~~
$ ls -s Desktop/shell-lesson-data/data
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
$ ls -s Desktop/shell-lesson-data/exercise-data/
total 28
4 animal-counts 4 creatures 12 numbers.txt 4 proteins 4 writing
$ ls -S Desktop/shell-lesson-data/data
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 @@ -791,24 +789,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 @@ -820,11 +803,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 @@ -845,13 +831,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
47 changes: 28 additions & 19 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,13 +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/ data/ molecules/ north-pacific-gyre/ notes.txt pizza.cfg solar.pdf writing/
haiku.txt LittleWomen.txt
~~~
{: .output}

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

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

Expand All @@ -86,25 +95,25 @@ Note that `mkdir` is not limited to creating single directories one at a time.
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}

The `-R` option to the `ls` command will list all nested subdirectories within a directory.
Let's use `ls -FR` to recursively list the new directory hierarchy we just created in the `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 @@ -287,10 +296,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 @@ -536,7 +545,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 @@ -618,13 +627,13 @@ Oftentimes one needs to copy or move several files at once. This can be done by
> ## 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}
>
Expand All @@ -635,11 +644,11 @@ Oftentimes one needs to copy or move several files at once. This can be done by
> ~~~
> {: .language-bash}
> ~~~
> amino-acids.txt animals.txt backup/ elements/ morse.txt pdb/ planets.txt salmon.txt sunspot.txt
> amino-acids.txt animals.csv backup/ elements/ morse.txt pdb/ planets.txt salmon.txt sunspot.txt
> ~~~
> {: .output}
> ~~~
> $ cp amino-acids.txt animals.txt morse.txt
> $ $ cp creatures/minotaur.dat creatures/unicorn.dat backup/ creatures/basilisk.dat
> ~~~
> {: .language-bash}
>
Expand All @@ -651,7 +660,7 @@ Oftentimes one needs to copy or move several files at once. This can be done by
> > name as the last argument.
> >
> > ```
> > cp: target ‘morse.txt’ is not a directory
> > cp: target 'creatures/basilisk.dat' is not a directory
> > ```
> > {: .output}
> {: .solution}
Expand All @@ -662,7 +671,7 @@ Oftentimes one needs to copy or move several files at once. This can be done by
> ## 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 @@ -691,7 +700,7 @@ Oftentimes one needs to copy or move several files at once. This can be done by
> ## 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 8e6eca3

Please sign in to comment.