diff --git a/source/sec_dev_basic_shell_commands.ptx b/source/sec_dev_basic_shell_commands.ptx index 08fc2d58..2e792ee7 100644 --- a/source/sec_dev_basic_shell_commands.ptx +++ b/source/sec_dev_basic_shell_commands.ptx @@ -11,20 +11,19 @@

- - Files, Directories, and Privileges -

- This and subsequent subsections are written to be followed as an extended exercise with explanations given as we go. -

- + + Introduction to Shell Commands + Exercise: Try shell commands for navigation +

Try each of the following commands on your own machine.

-

- First, follow the directions given in to open a terminal window so you can use your shell. All of the shell commands will be typed in this terminal window. -

- - Introduction to Shell Commands +

+ This and subsequent subsections are written to be followed as an extended exercise with explanations given as we go. +

+

+ This section is written to be followed as an extended exercise with explanations given as we go. +

@@ -94,9 +93,9 @@

The reason you see something like this is because the SHELL environment variable stores the location of the shell program. This location, called the file path, is given in the form of the path needed to find the location. We explore how this path is described in the next section.

+
- - + Files and File Systems

@@ -156,9 +155,9 @@

You should see a listing of files and directories.

+
-
- + Shell Command Options

@@ -187,10 +186,10 @@ lrwxrwxrwx 1 root root 7 Mar 24 2022 bin -> usr/bin

Thus, the -l flag changed how the listing is displayed. -

- -
- +

+
+ + File Permissions

@@ -219,9 +218,9 @@ lrwxrwxrwx 1 root pearcej 7 Mar 24 2022 bin -> usr/bin

Occasionally, you need to change permissions of a file. For example, you might need to change permissions to make a file executable. Changing file permissions is done with the chmod command. We will explore this in a bit.

- +
- + Learning More About Command Options

@@ -242,8 +241,8 @@ lrwxrwxrwx 1 root pearcej 7 Mar 24 2022 bin -> usr/bin
       ls -lra
       
-
- + + Creating and Removing Directories

@@ -333,8 +332,8 @@ lrwxrwxrwx 1 root pearcej 7 Mar 24 2022 bin -> usr/bin pwd -
- + + Input and Output Redirection

@@ -484,9 +483,9 @@ wc -w < temp.txt Try it! This is an improvement because it is faster and avoids the use of a temporary file.

-
+ - + Scripts

@@ -546,9 +545,9 @@ wc -w < temp.txt chmod +x hellouser.sh ./hellouser.sh - + - + File Management

@@ -614,21 +613,19 @@ rm -i newfile4.txt

And, if you respond with "n", then the removal will not happen.

-
- + + A few time-saving shell commands

- -

-

- The up arrow key retrieves the previous shell command. If you press it multiple times, it will take you back through multiple commands in your shell history. This is a useful way to repeat a command. For example, if you had a typo, you can use the up arrow, edit the command, and push enter to fix the command. Analogously, the down arrow will move you in the reverse direction through the shell command history. For more useful shell commands, type man bash for hints on how to search your shell history, re-execute commands, and much more.

+ The up arrow key retrieves the previous shell command. If you press it multiple times, it will take you back through multiple commands in your shell history. This is a useful way to repeat a command. For example, if you had a typo, you can use the up arrow, edit the command, and push enter to fix the command. Analogously, the down arrow will move you in the reverse direction through the shell command history. For more useful shell commands, type man bash for hints on how to search your shell history, re-execute commands, and much more. +

- An additional efficiency-enhancing feature is the history command. This command conveniently presents a record of previously executed shell commands, enabling users to effortlessly revisit their command history. + An additional efficiency-enhancing feature is the history command. This command conveniently presents a record of previously executed shell commands, enabling users to effortlessly revisit their command history.

- Here's an example of what might be displayed when the history command is executed: + Here's an example of what might be displayed when the history command is executed:

   1  git init
@@ -639,9 +636,8 @@ And, if you respond with "n", then the removal will not happen.
   6  history
   
-

+

This paragraph is intended to alert you to some useful search features. A couple examples of very common search patterns are using wildcards for zero or more characters or for a single character. The asterisk (*) specifies zero or more characters to match. In bash the question mark (?) is used for matching exactly one single character. -

* asterisk - wildcard for zero or more characters @@ -650,116 +646,81 @@ And, if you respond with "n", then the removal will not happen. ? question mark - wildcard for single character -

-

- For example, if we type the following: -

-
+  

+ For example, if we type the following: +

+
 rm -i newfile?.txt
 
-

+

Then the question mark will match with any single character, and we will see the following prompts:

-
+  
 rm: remove regular file 'newfile2.txt'?
 rm: remove regular file 'newfile4.txt'?
 
-

+

If we instead type:

-
+  
 rm -i newfile*.txt
-
-

+

+

Then the asterisk will match with any number of characters (including zero), and we will see the following prompts:

-
+  
 rm: remove regular file 'newfile2.txt'?
 rm: remove regular file 'newfile4.txt'?
 rm: remove regular file 'newfile2_cp.txt'?
 
-

-As you can see, these search patterns give you a lot of power and control. -

- - - - - -Conclusion

- Hopefully, you now feel a bit more comfortable using the shell. The shell commands discussed above are summarized in Appendix . +As you can see, these search patterns give you a lot of power and control.

-
- + + + Quiz: Basic Shell Commands -

- You have a file named data.txt that contains the following lines: -

-
apple
+      

+ You have a file named data.txt that contains the following lines: +

+
apple
 orange
 banana
 grape
-        
-

- Your task is to create a new file named fruits.txt and copy the contents of data.txt to fruits.txt. Next, append the word kiwi to fruits.txt. Then, display the contents of fruits.txt in the terminal. Next, count the number of fruits in fruits.txt and display the total count. Finally, overwrite the content of data.txt with the content of fruits.txt and rename data.txt to a new file named fruits2. -

-

- Here are some commands you may need to perform the task. Rearrange the correct commands in the correct order by dragging and dropping. -

+
+

+ Your task is to create a new file named fruits.txt and copy the contents of data.txt to fruits.txt. Next, append the word kiwi to fruits.txt. Then, display the contents of fruits.txt in the terminal. Next, count the number of fruits in fruits.txt and display the total count. Finally, overwrite the content of data.txt with the content of fruits.txt and rename data.txt to a new file named fruits2. +

+

+ Here are some commands you may need to perform the task. Rearrange the correct commands in the correct order by dragging and dropping. +

- - -

- cat data.txt > fruits.txt -

-
- -

- cat data.txt >> fruits.txt -

-
-
- -

- echo "kiwi" >> fruits.txt -

-
- -

- cat fruits.txt -

-
- - -

- wc -l < fruits.txt -

-
- -

- wc -w < fruits.txt -

-
-
- + +

- cp -i fruits.txt data.txt + cat data.txt > fruits.txt

-
- + +

- mv data.txt fruits2.txt + cat data.txt >> fruits.txt

-
- -

- rm data.txt fruits2.txt -

-
+ +
- + + + + + + + Conclusion +

+ Hopefully, you now feel a bit more comfortable using the shell. The shell commands discussed above are summarized in Appendix . +

+
+ \ No newline at end of file