Question: Project: Redirection Assignment Objectives: On completing this lab, you should be able to: Demonstrate using meta characters to redirect STDIN and STDOUT Part 1 Instructions:
Project: Redirection
Assignment Objectives:
On completing this lab, you should be able to:
- Demonstrate using meta characters to redirect STDIN and STDOUT
Part 1
Instructions:
Practice using redirection by completing the tasks below. These concepts and examples are demonstrated in TestOut material section 1.7. You will also be required to complete tasks previous covered in prior sections and in class. Perform the task being requested on your vSphere virtual machine. Provide the requested answer or screenshot as indicated in the task.
Task
Task 1
Read the handout on accessing the Virtual Lab in Canvas to access your virtual machine. Log in to the Will Adams account with the password netlab123 and open the terminal program.
Task 2
Create a directory (folder) in your users home called newsamples and move into the newly created directory.
Task 3
Create a file in the newsamples directory called sample1 with the command, echo Hello World. > sample1. Explain what this command is doing. Explain where the words Hello World went to.
Your answer below:
Task 4
Create a second file in the same directory called sample2 with the same words Hello World. Provide a screenshot that this task was completed successfully.
Your screenshot below:
Task 4
Execute the following command to list files: ls sample1 sample2 sample3 . This command should have output 2 lines. In your answer below, identify which line (actually put what the line is) be considered stdout and which line would be stderr. Explain why you received this output.
Your answer below:
Task 5
Execute the following directory listing: ls sample1 sample2 sample3 > fileA . Did any output appear on the screen when you ran this command? Explain why. Explain what happens when the > (greater than symbol) is used. What is the purpose of the fileA part of the command?
Your answer below:
Task 6
Open fileA and review the data in that file.
Task 7
Execute the following directory listing: ls sample1 sample2 sample3 1> fileA . Open fileA and review the data in that file. What happened differently from task 5? Explain why. Explain how the 1> (number one and greater than symbol) is different from just the > (greater than symbol).
Your answer below:
Task 8
Execute the following directory listing: ls sample1 sample2 sample3 2> fileA . Open fileA and review the data in that file. What happened differently from task 5 and 7? Explain why. Explain how the 2> is different from 1> and > .
Your answer below:
Task 9
Task 5, 7 and 8 each demonstrated redirecting output to fileA. Was the data in fileA from Task 5 saved when you executed the command for task 7 or 8 or was the data overridden? Explain why.
Your answer below:
Task 10
Execute the following command: date >> fileA . Open and review fileA. Was the data overridden or added (appended) to the file?
Your answer below:
Task 11
Clobbering a file means overwriting its contents. To prevent unintentional clobbering, use the noclobber option to the set command. Type the following: set -o noclobber .
Task 12
Now if you try override fileA with the command: echo Greetings > fileA . You get the error message: bash: fileA: cannot overwrite existing file.
Task 13
To remove the noclobber option: set +o noclobber . Now attempt to override fileA like you did in task 12. It should now override the file without an error.
Task 14
So far we have looked at redirecting stdout (stuff that happens on a computer screen) to someplace else such as a file. Lets now look at how to redirect stdin (stuff you type on a keyboard) to a program. In other words, instead of taking text we type and have a program do something with it, we will funnel text from a file (instead of the keyboard) to a program.
Lets begin by using the tr (translate) command and interact with it using the keyboard. The tr command translates text from one format to another, for instance from lower case to upper case. Execute the following command, tr a-z A-Z .
Then type hello world (all lower case) then press enter. The tr command should translate all lower case letters to upper case.
Type some more and press enter. Everything you type from the keyboard should change to uppercase letters.
Press ctrl-c to cancel and return to the command line.
Task 15
Instead of interacting with the tr command from the keyboard (stdin) we are going to have a text file interact with the tr command as if it was the keyboard. We are going to redirect stdin to the tr command. First lets be reminded whats in fileA. Execute the following command: cat fileA .
Task 16
Now execute the command: tr a-z A-Z < fileA . Paste a screenshot showing you successfully executed task 15 and 16.
Your screenshot below:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
