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 16, 2021
1 parent 7ae1ee1 commit d098c12
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 129 deletions.
97 changes: 39 additions & 58 deletions _episodes/02-filedir.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ you may use <kbd>↑</kbd> and <kbd>↓</kbd> to move line-by-line,
or try <kbd>B</kbd> and <kbd>Spacebar</kbd> to skip up and down by a full page.
To search for a character or word in the `man` pages,
use <kbd>/</kbd> followed by the character or word you are searching for.
Sometimes a search will result in multiple hits.
If so, you can move between hits using <kbd>N</kbd> (for moving forward) and
Sometimes a search will result in multiple hits.
If so, you can move between hits using <kbd>N</kbd> (for moving forward) and
<kbd>Shift</kbd>+<kbd>N</kbd> (for moving backward).
To **quit** the `man` pages, press <kbd>Q</kbd>.
Expand Down Expand Up @@ -332,7 +332,7 @@ To **quit** the `man` pages, press <kbd>Q</kbd>.
### Exploring Other Directories
Not only can we use `ls` on the current working directory,
Not only can we use `ls` on the current working directory,
but we can use it to list the contents of a different directory.
Let's take a look at our `Desktop` directory by running `ls -F Desktop`,
i.e.,
Expand Down Expand Up @@ -380,8 +380,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 @@ -403,18 +402,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.
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.
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 @@ -423,7 +423,7 @@ $ pwd
{: .language-bash}
~~~
/Users/nelle/Desktop/shell-lesson-data/data
/Users/nelle/Desktop/shell-lesson-data/exercise-data
~~~
{: .output}
Expand All @@ -433,8 +433,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 @@ -493,8 +492,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 @@ -545,14 +543,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 @@ -574,7 +572,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 @@ -584,7 +582,7 @@ $ pwd
{: .language-bash}
~~~
/Users/nelle/Desktop/shell-lesson-data/data
/Users/nelle/Desktop/shell-lesson-data/exercise-data
~~~
{: .output}
Expand Down Expand Up @@ -620,9 +618,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 @@ -632,7 +630,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 All @@ -657,7 +655,7 @@ Run `pwd` and `ls -F` to ensure that we're in the directory we expect.
> > 3. No: Amanda's home directory is `/Users/amanda`.
> > 4. No: this command goes up two levels, i.e. ends in `/Users`.
> > 5. Yes: `~` stands for the user's home directory, in this case `/Users/amanda`.
> > 6. No: this command would navigate into a directory `home` in the current directory
> > 6. No: this command would navigate into a directory `home` in the current directory
> > if it exists.
> > 7. Yes: unnecessarily complicated, but correct.
> > 8. Yes: shortcut to go back to the user's home directory.
Expand Down Expand Up @@ -737,7 +735,7 @@ $ ls -F /
`ls` is the **command**, with an **option** `-F` and an
**argument** `/`.
We've already encountered options (also called **switches** or **flags**) which
either start with a single dash (`-`) or two dashes (`--`),
either start with a single dash (`-`) or two dashes (`--`),
and they change the behavior of a command.
[Arguments] tell the command what to operate on (e.g. files and directories).
Sometimes options and arguments are referred to as **parameters**.
Expand All @@ -751,13 +749,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 @@ -786,24 +782,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 @@ -815,11 +796,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 @@ -840,13 +824,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
Loading

0 comments on commit d098c12

Please sign in to comment.