diff --git a/episodes/03-create.md b/episodes/03-create.md index fcfdae144..6b5517b45 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,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 diff --git a/episodes/07-find.md b/episodes/07-find.md index 984d53f77..cf4496b56 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 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 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.