From 60e2fe7b3c73bd36e037d111bb50c7e56c504620 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 7 Nov 2025 12:38:59 +0100 Subject: [PATCH 1/5] Gentler introduction to recursion - Explain the concept in simple words when first introduced - Remind learners of the in-context meaning throughout --- episodes/03-create.md | 19 +++++++++++++++++-- episodes/07-find.md | 9 ++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/episodes/03-create.md b/episodes/03-create.md index fcfdae144..63747ad67 100644 --- a/episodes/03-create.md +++ b/episodes/03-create.md @@ -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. + +Let's use `ls -FR` to recursively list the new directory hierarchy we just created in the +`project` directory: + ```bash $ ls -FR ../project ``` @@ -477,8 +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`, +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. + +We can use this option to copy a directory and all its contents e.g. to back up a directory: ```bash diff --git a/episodes/07-find.md b/episodes/07-find.md index 984d53f77..eaa811d82 100644 --- a/episodes/07-find.md +++ b/episodes/07-find.md @@ -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 . @@ -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 grep text in a directory +in 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 From 7e026888182f914f2b5d180ce8fd52681d67196c Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 7 Nov 2025 13:18:45 +0100 Subject: [PATCH 2/5] Update episodes/07-find.md Co-authored-by: Benson Muite --- episodes/07-find.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/07-find.md b/episodes/07-find.md index eaa811d82..2836afe28 100644 --- a/episodes/07-find.md +++ b/episodes/07-find.md @@ -339,7 +339,7 @@ $1.txt cut -d , -f 1,3 ``` -Hint: use `man grep` to remind ourselves how to grep text in a directory +Hint: use `man grep` to remind ourselves how to find text in a directory in recursively (meaning include all subdirectories in the search) and `man cut` to select more than one field in a line. From 32479527e72ef63e81bd33bd5a89ef6bd092de0e Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 7 Nov 2025 13:42:20 +0100 Subject: [PATCH 3/5] Add "recursive" to glossary --- learners/reference.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/learners/reference.md b/learners/reference.md index 484ecaa6b..699384172 100644 --- a/learners/reference.md +++ b/learners/reference.md @@ -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. + [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. From 8ea08ade0d1f6fed6a84c08bf573d9c15341655d Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 7 Nov 2025 14:49:26 +0100 Subject: [PATCH 4/5] Update episodes/07-find.md Co-authored-by: Benson Muite --- episodes/07-find.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/07-find.md b/episodes/07-find.md index 2836afe28..cf4496b56 100644 --- a/episodes/07-find.md +++ b/episodes/07-find.md @@ -340,7 +340,7 @@ cut -d , -f 1,3 ``` Hint: use `man grep` to remind ourselves how to find text in a directory -in recursively (meaning include all subdirectories in the search) +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 From 27481c7a25b718e64adaec60dbb3c122de99cedb Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 7 Nov 2025 14:49:45 +0100 Subject: [PATCH 5/5] Update episodes/03-create.md Co-authored-by: Benson Muite --- episodes/03-create.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/episodes/03-create.md b/episodes/03-create.md index 63747ad67..6b5517b45 100644 --- a/episodes/03-create.md +++ b/episodes/03-create.md @@ -493,8 +493,7 @@ the `-r` option for `cp` applies the command not just to the specifed directory, but to all its contents. -We can use this option to copy a directory and all its contents -e.g. to back up a directory: +As an example, we can use this to back up a directory: ```bash $ cp -r thesis thesis_backup