Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions episodes/03-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ The `-R` option to the `ls` command will list all nested subdirectories within a
Let's use `ls -FR` to recursively list the new directory hierarchy we just created in the
`project` directory:

The `-R` option to the `ls` command will list all nested subdirectories within a directory.
`R` in `-R` stands for "Recursive" which refers to the idea that the output of a process
becomes the input of another iteration of that same process.
So in this case, `ls -R` lists the contents of a directory, and for every directory
it finds, it lists the contents of that directory,
and for every directory inside those subdirectories,
it lists the contents, and so on.
Comment on lines +96 to +102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Recursion" should be in the glossary? This might allow simplifying the paragraph.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree it should be added. I'll add that to this PR. I still think a short inline explanation would be helpful. The instructor will need to verbally explain -R/-r somehow so I think coming up with some nice concise and approachable wording will be helpful.

Comment on lines +96 to +102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps if

The `-R` option to the `ls` command will list all nested subdirectories within a directory.

is changed to

The `-R` or `--recursive` option to the `ls` command will make `ls` a [recursive] procedure
which lists all nested sub-directories within a directory.

to ensure recursive links to the glossary add

just before the Keypoints section, see #1510
Then the above can be shortened to

Suggested change
The `-R` option to the `ls` command will list all nested subdirectories within a directory.
`R` in `-R` stands for "Recursive" which refers to the idea that the output of a process
becomes the input of another iteration of that same process.
So in this case, `ls -R` lists the contents of a directory, and for every directory
it finds, it lists the contents of that directory,
and for every directory inside those subdirectories,
it lists the contents, and so on.
The command `ls -R` lists the contents of a directory, and for every directory
it finds, it lists the contents of that directory,
and for every directory inside those subdirectories,
it lists the contents, and so on.


Let's use `ls -FR` to recursively list the new directory hierarchy we just created in the
`project` directory:

```bash
$ ls -FR ../project
```
Expand Down Expand Up @@ -477,9 +488,12 @@ $ ls quotes.txt thesis/quotations.txt
quotes.txt thesis/quotations.txt
```

We can also copy a directory and all its contents by using the
[recursive](https://en.wikipedia.org/wiki/Recursion) option `-r`,
e.g. to back up a directory:
Just like the recursive (`-R`) option for `ls`,
the `-r` option for `cp`
applies the command not just to the specifed directory,
but to all its contents.

As an example, we can use this to back up a directory:

```bash
$ cp -r thesis thesis_backup
Expand Down
9 changes: 6 additions & 3 deletions episodes/07-find.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ $ grep -n -w -v "the" haiku.txt
```

If we use the `-r` (recursive) option,
`grep` can search for a pattern recursively through a set of files in subdirectories.
`grep` can search for a pattern through all the files in
in a directory and its subdirectories subdirectories.

Let's search recursively for `Yesterday` in the `shell-lesson-data/exercise-data/writing` directory:
Let's search "recursively" for `Yesterday`
in the `shell-lesson-data/exercise-data/writing` directory:

```bash
$ grep -r Yesterday .
Expand Down Expand Up @@ -337,7 +339,8 @@ $1.txt
cut -d , -f 1,3
```

Hint: use `man grep` to look for how to grep text recursively in a directory
Hint: use `man grep` to remind ourselves how to find text in a directory
recursively (meaning include all subdirectories in the search)
and `man cut` to select more than one field in a line.

An example of such a file is provided in
Expand Down
6 changes: 6 additions & 0 deletions learners/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ so that the shell will not try to expand the `*` wildcard.
: (REPL): A [command-line interface](#command-line-interface) that reads a command from the user,
executes it, prints the result, and waits for another command.

[recursive]{#recursive}
: A recursive precudure is one where one step of the procedure is to apply the procedure itself
(usually to a different input).
In the context of shell, it often refers to applying a command to a directory and to all directories
contained within that directory.
Comment on lines +164 to +167
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: A recursive precudure is one where one step of the procedure is to apply the procedure itself
(usually to a different input).
In the context of shell, it often refers to applying a command to a directory and to all directories
contained within that directory.
: A recursive procedure is one where the output of an iteration
is the input of another iteration of that procedure.

Is context of the shell lesson helpful? Maybe should be added to
other terms if it is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this because for all except ls, the command itself is not recursive. Really the only "recursive" part is finding files that we apply the command to. e.g. in grep, we are not applying some kind of recursive algo to search ie feeding the output of the search back into the search algo multiple times (not sure what that would even mean, maybe something akin to a recursive regex 😬 ). We are recursively crawling the filesystem to identify files to search, and then searching them (once each).

For this reason, I think the main thing learners need to know is that -r/-R means "apply this to the entire directory tree within the specified directory". They don't need to fully understand recursion as a general concept. In fact, imo, trying to dig into that would be distracting/confusing. I think it's enough to cover that recursion is a more general concept that has something to do with applying a process in a tree-like manner and in this context when applied to a directory means applying to everything inside as well.

This "apply to everything inside" is probably novices default way of thinking of commands and the fact that it's not the default for shell commands and -r/-R needs to be added is something to actively learn. Meaning, when you copy a folder in a GUI, typically the contents are also copied. When you search a folder in a GUI, typically that means searching all the contents and subfolder contents etc.


[redirect]{#redirect}
: To send a command's output to a file rather than to the screen or another command,
or equivalently to read a command's input from a file.
Expand Down