@@ -526,11 +526,20 @@ Using `ls` and wildcard characters, perform the following tasks:
526526 <br>
527527
528528 ` ` ` sh
529- ls -l * l? [a-h]* _g*
529+ ls -l * l? [a-h]* _g*
530530
531- # Eubalaena_glacialis (North Atlantic right whale).
532- # Gorilla_gorilla (Western gorilla).
533- # Plecturocebus_grovesi (Alta Floresta titi monkey - a New World monkey).
531+ # There are 3 matches:
532+ # Eubalaena_glacialis (North Atlantic right whale).
533+ # Gorilla_gorilla (Western gorilla).
534+ # Plecturocebus_grovesi (Alta Floresta titi monkey - a New World monkey).
535+ ` ` `
536+
537+ Note that if we wanted to also match species with the pattern ` l? [a-h]` at
538+ the start of their genus name, we would need:
539+
540+ ` ` ` sh
541+ # Returns the same 3 matches as above.
542+ ls -l * [Ll]? [a-h]* _g*
534543 ` ` `
535544
536545 </details>
@@ -640,6 +649,7 @@ becomes useful.
640649Enter the directory `exercise_3/` and perform the following tasks:
641650
6426511. **Create directories** with the **`mkdir`** command:
652+
643653 * In the directory `exercise_3/`, create 2 new directories:
644654 `species_by_genus` and `species_by_common_name`.
645655 * In `species_by_genus/`, create 2 new subdirectories:
@@ -648,16 +658,20 @@ Enter the directory `exercise_3/` and perform the following tasks:
648658 `Crocidura` ([a genus of shrews](https://en.wikipedia.org/wiki/Crocidura)).
649659 * In `species_by_common_name/`, create 2 new subdirectories
650660 named `B` and `R`.
661+
662+ <br>
651663
652- > **🔥 Tip:** to avoid having to rewrite a command, remember that you can
653- > use the **up arrow** of your keyboard to go back in your terminal history.
664+ > **🔥 Tip**
665+ >
666+ > To avoid having to rewrite a command, remember that you can use the
667+ > **up arrow** of your keyboard to go back in your terminal history.
654668 > This allows you to re-use a command that you wrote earlier, while making
655669 > changes to it if needed.
656670
657671 <details><summary><b>✅ Solution</b></summary>
658672 <br>
659673
660- * **Create directories `species_by_genus` and `species_by_common_name`**.
674+ **Create directories `species_by_genus` and `species_by_common_name`**.
661675
662676 ```sh
663677 cd exercise_3
@@ -673,7 +687,7 @@ Enter the directory `exercise_3/` and perform the following tasks:
673687 mkdir species_by_{genus,common_name}
674688 ```
675689
676- * **Create subdirectories `Dendrolagus` and `Crocidura`**.
690+ **Create subdirectories `Dendrolagus` and `Crocidura`**.
677691
678692 ```sh
679693 # Option 1: create the subdirectories from the root of exercise_3.
@@ -688,7 +702,7 @@ Enter the directory `exercise_3/` and perform the following tasks:
688702 mkdir species_by_genus/{Dendrolagus,Crocidura}
689703 ```
690704
691- * **Create subdirectories `B` and `R`**.
705+ **Create subdirectories `B` and `R`**.
692706
693707 ```sh
694708 # Option 1: specify the full (relative) path of the subdirectories to create.
@@ -703,22 +717,27 @@ Enter the directory `exercise_3/` and perform the following tasks:
703717 mkdir species_by_common_name/{B,R}
704718 ```
705719
706- **✨ Note:** using the **`-p` option of `mkdir`**, it is possible to create
707- multiple levels of directories in a single command. For example, we could
708- create all the directories for this exercise in a single command:
709-
710- ```sh
711- mkdir -p species_by_{genus/{Dendrolagus,Crocidura},common_name/{B,R}}
712- ```
713-
714- **🔥 Tip:** to preview the output of a brace expansion (or filename
715- expansion), you can run the command prefixed with **`echo`**: this prints
716- the command that would be executed to the terminal without running the
717- command.
720+ > **✨ Note**
721+ >
722+ > Using the **`-p` option of `mkdir`**, it is possible to create multiple
723+ > levels of directories in a single command. For example, we could create
724+ > all the directories for this exercise in a single command:
725+ >
726+ > ```sh
727+ > mkdir -p species_by_{genus/{Dendrolagus,Crocidura},common_name/{B,R}}
728+ > ```
718729
719- ```sh
720- echo mkdir -p species_by_{genus/{Dendrolagus,Crocidura},common_name/{B,R}}
721- ```
730+ > **🔥 Tip**
731+ >
732+ > To preview the output of a brace expansion (or filename expansion), you
733+ > can run the command prefixed with **`echo`**
734+ >
735+ > This prints the command that would be executed to the terminal (with all
736+ > expansions performed) without running it.
737+ >
738+ > ```sh
739+ > echo mkdir -p species_by_{genus/{Dendrolagus,Crocidura},common_name/{B,R}}
740+ > ```
722741
723742 </details>
724743 <br>
@@ -732,6 +751,7 @@ Enter the directory `exercise_3/` and perform the following tasks:
732751 [Red Wolf](https://en.wikipedia.org/wiki/Red_wolf) (_Canis rufus_) to the
733752 directory `species_by_common_name`.
734753
754+ <br>
735755 <details><summary><b>✅ Solution</b></summary>
736756 <br>
737757
@@ -755,6 +775,7 @@ Enter the directory `exercise_3/` and perform the following tasks:
755775 * Rename the `Canis_rufus` file you just moved into the subdirectory `R` to
756776 the common name of the species: `Red_wolf`.
757777
778+ <br>
758779 <details><summary><b>✅ Solution</b></summary>
759780 <br>
760781
@@ -788,6 +809,40 @@ Enter the directory `exercise_3/` and perform the following tasks:
788809 </details>
789810 <br>
790811
812+ **4. Copy and rename files in a single `cp` command:**
813+
814+ Similarly to what we did for the Red Wolf file, we will now copy and
815+ rename the file for the [Black Rhinoceros](https://en.wikipedia.org/wiki/Black_rhinoceros)
816+ _Diceros bicornis_, but this time we will copy and rename the file
817+ **in a single step** using the **`cp`** command.
818+
819+ Copy the file `Diceros_bicornis` from its original location (in
820+ `exercise_2/RedList_mammals`) into `species_by_common_name/B`, while directly
821+ renaming it to the common name of the species: `Black_rhino`.
822+
823+ <details><summary><b>✅ Solution</b></summary>
824+ <br>
825+
826+ ```sh
827+ # Note: this assumes the current working directory is "species_by_common_name".
828+ cp ../../exercise_2/RedList_mammals/Diceros_bicornis B/Black_rhino
829+ ```
830+
831+ </details>
832+ <br>
833+
834+ **5. Copy, rename and delete directories**:
835+
836+ * Change directory to the root of the `exercise_3/` directory.
837+ * Copy the entire directory `species_by_genus/Dendrolagus` - with all its
838+ content - to the root of `exercise_3`.
839+
840+ > **🎯 Hint:** to make a **recursive** copy of a directory, the option
841+ > is `-R`/`--recursive`.
842+
843+ * Rename the directory to `Tree-kangaroos`.
844+ * Delete the directory `Tree-kangaroos` and its content **in a safe way**.
845+
7918465. **Copy, rename and delete directories**:
792847 * Change directory to the root of the `exercise_3/` directory.
793848 * Copy the entire directory `species_by_genus/Dendrolagus` - with all its
0 commit comments