Ch. 7 – Working with Bash Enter your answers into this document in bold, and then upload it to the instructor via Moodle. PART ONE: Textbook Answer each question posed in these projects and insert the...

1 answer below »
Ch. 7 – Working with Bash
Enter your answers into this document in bold, and then upload it to the instructor via Moodle.
PART ONE: Textbook
Answer each question posed in these projects and insert the answers in order in Bold into this document directly under the project description. No need to enter the questions, only the answers. If asked to login to user1, use your personal account instead. When asked for passwords, use the ones you created on your system.
1. Do Project 7-1, pp. 335-336. In step 3, be sure you don’t have a sample3 file in the directory before entering the ls command. In step 13, use this command ls -l sample1 sample2 sample3 2>file2 >&2 instead of the one shown.
2. Do Project 7-2, pp. 336-337. In step 8, you use the stream editor sed, see pp. 304-305. In step 9, you use the pattern scanning and processing language awk, see pg. 306.
3. Do Project 7-3, pp. 337-338.
4. Do Project 7-4, pg. 339.
5. Do Discovery Exercise 5, pg. 344, as follows: Rather than describe what each line in the file does, enter the appropriate line(s) from .bash_profile on your system (which will be different than the file shown on pg. 344) immediately below the descriptions here:
Comments.
Set environment variable(s).
Exports these variables so they can be used in subshells.
The if statement that says if the hidden file .bashrc exists in the user’s home directory, then execute it.
6. Do Discovery Exercise 6, pg. 344. Include the shell script immediately below.
7. Additional Project. Indicate the command that can be used to:
a. Create an alias call mm that displays only those devices that are mounted and contain an ext4 filesystem.
b. Create a variable called NEWHOME that is equivalent to the value contained in the HOME variable.
c. Starting from the /etc directory find all the files whose names begin with the word “hosts” and save the stdout to a file named file1.
d. Display only the lines from the output of the set command that have the word “bash” regardless of case in them. The output on the terminal screen should be sorted alphabetically.
Upload this document including your answers in Bold through Moodle.
Answered Same DayDec 21, 2021

Answer To: Ch. 7 – Working with Bash Enter your answers into this document in bold, and then upload it to the...

David answered on Dec 21 2021
116 Votes
Project 7-1
In this hands-on project, you use the shell to redirect the stdout and stderr to
a file and take
stdin from a file.
1. Switch to a command-line terminal (tty2) by pressing Ctrl+Alt+F2 and log in
to the
terminal using the user name of root and the password of secret.

2. At the command prompt,
type touch sample1 sample2 and
press Enter to create
two new files named sample1 and sample2 in your home directory.
Verify thei
r creation
by typing ls –F at the command prompt and press Enter.
[root@(none) ~]# touch sample1 sample2
[root@(none) ~]# ls -F
anaconda-ks.cfg install.log install.log.syslog sample1 sample2

3. At the command prompt, type
ls -l sample1 sample2 sample3 and press Enter.
Is there any stdout displayed on the terminal screen? YES
Is there any stderr displayed on the terminal screen? YES as commands
send the output and error directly to the terminal

[root@(none) ~]# ls -l sample1 sample2 sample3
ls: cannot access sample3: No such file or directory
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample1
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample2

4. At the command prompt, type
ls -l sample1 sample2 sample3 > file and press
Enter.
Is there any stdout displayed on the terminal screen? NO
Is there any stderr displayed on the terminal screen? Why?
ls: cannot access sample3: No such file or directory


5. At the command prompt,
type cat file and press Enter.
What are the contents of file and why?
[root@(none) ~]# cat file
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample1
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample2

6. At the command prompt, type
ls -l sample1 sample2 sample3 2> file and press
Enter.
Is there any stdout displayed on the terminal screen? YES
Is there any stderr displayed on the terminal screen? NO as the error
message is being sent to the file named “file”

[root@(none) ~]# ls -l sample1 sample2 sample3 2> file
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample1
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample2

7. At the command prompt, type
cat file and press Enter.
What are the contents of file and why?
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample1
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample2
Were the previous contents retained? YES as the output is sent to the
screen now and not to the file.

8. At the command prompt, type
ls -l sample1 sample2 sample3 > file 2>file2 and press Enter.
Is there any stdout displayed on the terminal screen? No
Is there any stderr displayed on the terminal screen? NO , the error is sent
to the file2 and not on the screen.

9. At the command prompt, type
cat file and press Enter.
[root@(none) etc]# cat file
-rw-r--r--. 1 root root 0 Nov 1 12:53 sample1
-rw-r--r--. 1 root root 0 Nov 1 12:53 sample2

Because the error is not sent to this file

10. At the command prompt, type
cat file2 and press Enter.
[root@(none) etc]# cat file2
ls: cannot access sample3: No such file or directory

Error is sent to this file

11. At the command prompt, type
ls -l sample1 sample2 sample3 > file 2>&1 and
press Enter.
Is there any stdout displayed on the terminal screen? NO
Is there any stderr displayed on the terminal screen? NO Both the stdout
and the stderr are sent to the same file instead of to the terminal
screen.

12. At the command prompt, type
cat file and press Enter.
What are the contents of file and why?
[root@(none) ~]# ls -l sample1 sample2 sample3
ls: cannot access sample3: No such file or directory
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample1
-rw-r--r--. 1 root root 0 Oct 30 12:11 sample2
Both the stdout and the stderr are sent to the same file instead of to the
terminal
screen.

13. At the command prompt, type
ls -l sample1 sample2 sample3 2>file2 >&2
and press Enter.
Is there any stdout displayed on the terminal screen? NO
Is there any stderr displayed on the terminal screen? NO
Both the stdout and the stderr are sent to the same file instead of to the
terminal
screen.

14. At the command prompt, type
cat file2 and press Enter.
Both the stdout and the stderr are sent to the same file instead of to the
terminal
screen.

15. At the command prompt, type date > file and press Enter.

16. At the command prompt, type cat file and press Enter.
What are the contents of file and why?
It will display the today‟s date.

17. At the command prompt, type date >> file and press Enter.

18. At the command prompt, type...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here