If you plan to take the RHCSA exam, then use the following approach to maximize the benefit of this Comprehensive Review: attempt each lab without viewing the solution buttons or referring to the course content. Use the grading scripts to gauge your progress as you complete each lab.
In this review, you manage files, redirect a specific set of lines from a text file to another file, and edit the text files.
Outcomes
Manage files from the command line.
Display a specific number of lines from text files and redirect the output to another file.
Edit text files.
If you did not reset your workstation and server machines at the end of the last chapter, then save any work that you want to keep from earlier exercises on those machines, and reset them now.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start rhcsa-rh124-review1
Specifications
Log in to serverb as the student user.
Create the /home/student/grading directory.
Create three empty files called grade1, grade2, and grade3, in the /home/student/grading directory.
Capture the first five lines of the /home/student/bin/manage file in the /home/student/grading/review.txt file.
Append the last three lines of the /home/student/bin/manage file to the /home/student/grading/review.txt file.
Do not overwrite any existing text in the /home/student/grading/review.txt file.
Copy the /home/student/grading/review.txt file to the /home/student/grading/review-copy.txt file.
Edit the /home/student/grading/review-copy.txt file so that the Test JJ line appears twice.
Edit the /home/student/grading/review-copy.txt file to remove the Test HH line.
Edit the /home/student/grading/review-copy.txt file so that a line with A new line exists between the Test BB line and the Test CC line.
Create the /home/student/hardcopy hard link to the /home/student/grading/grade1 file.
You must create the hard link after completing the earlier step to create the /home/student/grading/grade1 file.
Create the /home/student/softcopy symbolic link to the /home/student/grading/grade2 file.
Save the output of a command that lists the contents of the /boot directory to the /home/student/grading/longlisting.txt file.
The output should be a "long listing" that includes file permissions, owner and group owner, size, and modification date of each file.
The output should omit hidden files.
Log in to serverb as the student user.
[student@workstation ~]$ ssh student@serverb
...output omitted...
[student@serverb ~]$Create the /home/student/grading directory.
If the /home/student directory is your current directory, then you do not need to specify the absolute path to the grading directory when creating it.
[student@serverb ~]$ mkdir gradingIn the /home/student/grading directory, create three empty files called grade1, grade2, and grade3.
Create the empty files called grade1, grade2, and grade3 in the /home/student/grading directory.
Apply the brace expansion shell feature to create all three files with a single touch command.
[student@serverb ~]$ touch grading/grade{1,2,3}Verify that the grade1, grade2, and grade3 files exist in the /home/student/grading directory.
[student@serverb ~]$ ls grading/
grade1 grade2 grade3Copy the first five lines of the /home/student/bin/manage file to the /home/student/grading/review.txt file.
View the first five lines of the /home/student/bin/manage file and redirect the output to the /home/student/grading/review.txt file.
Use the single redirection symbol (>) to overwrite any existing content in the file.
[student@serverb ~]$ head -5 bin/manage > grading/review.txtVerify that the /home/student/grading/review.txt file contains the following text:
Test AA Test BB Test CC Test DD Test EE
Append the last three lines of the /home/student/bin/manage file to the /home/student/grading/review.txt file.
Use the double redirection symbol (>>) to append the output and preserve the contents of the file.
View the last three lines of the /home/student/bin/manage file and append the output to the /home/student/grading/review.txt file.
[student@serverb ~]$ tail -3 bin/manage >> grading/review.txtVerify that the /home/student/grading/review.txt file contains the following text:
Test AA Test BB Test CC Test DD Test EE Test HH Test II Test JJ
Copy the /home/student/grading/review.txt file to the /home/student/grading/review-copy.txt file.
Navigate to the /home/student/grading directory.
[student@serverb ~]$ cd grading/
[student@serverb grading]$Copy the /home/student/grading/review.txt file to the /home/student/grading/review-copy.txt file.
[student@serverb grading]$ cp review.txt review-copy.txtNavigate back to the home directory of the student user.
[student@serverb grading]$ cd
[student@serverb ~]$Edit the /home/student/grading/review-copy.txt file to have two sequential Test JJ lines.
Use the vim text editor to open the /home/student/grading/review-copy.txt file.
[student@serverb ~]$ vim grading/review-copy.txtFrom the command mode in vim, scroll down to the Test JJ line.
Press the y key twice to copy the line of text, and press the p key to paste it below the cursor.
Type wq to save the changes and quit vim.
Verify that the /home/student/grading/review-copy.txt file contains the following text:
Test AA Test BB Test CC Test DD Test EE Test HH Test IITest JJTest JJ
Edit the /home/student/grading/review-copy.txt file to remove the Test HH line.
Use the Vim text editor to open the /home/student/grading/review-copy.txt file.
[student@serverb ~]$ vim grading/review-copy.txtFrom the command mode in Vim, scroll down to the Test HH line.
Press the d key twice on your keyboard to delete the line of text.
Type wq to save the changes and quit vim.
Verify that the /home/student/grading/review-copy.txt file contains the following text:
Test AA Test BB Test CC Test DD Test EE Test II Test JJ Test JJ
Edit the /home/student/grading/review-copy.txt file so that the line with A new line exists between the Test BB line and the Test CC line.
Use the Vim text editor to open the /home/student/grading/review-copy.txt file.
[student@serverb ~]$ vim grading/review-copy.txtFrom the command mode in Vim, scroll down to the Test CC line.
Press the i key to switch to the insert mode while keeping the cursor at the beginning of the Test CC line.
From the insert mode, press Enter to create a blank line above the cursor.
Use the up arrow to navigate to the blank line and create the line of A new line text.
Press the Esc key to switch back to the command mode.
Type wq to save the changes and to quit Vim.
Verify that the /home/student/grading/review-copy.txt file contains the following text.
Test AA
Test BB
A new line
Test CC
Test DD
Test EE
Test II
Test JJ
Test JJCreate the /home/student/hardcopy hard link to the /home/student/grading/grade1 file.
Create the /home/student/hardcopy hard link to the /home/student/grading/grade1 file.
[student@serverb ~]$ ln grading/grade1 hardcopyView the link count of the /home/student/grading/grade1 file.
[student@serverb ~]$ls -l grading/grade1-rw-rw-r--.2student student 0 Mar 6 16:45 grading/grade1
Create the /home/student/softcopy symbolic link to the /home/student/grading/grade2 file.
Create the /home/student/softcopy symbolic link to the /home/student/grading/grade2 file.
[student@serverb ~]$ ln -s grading/grade2 softcopyView the properties of the /home/student/softcopy symbolic link.
[student@serverb ~]$ls -l softcopylrwxrwxrwx. 1 student student 14 Mar 6 17:58softcopy -> grading/grade2
List the contents of the /boot directory and redirect the output to the /home/student/grading/longlisting.txt file.
The output should be a long listing that includes the file permissions, owner and group owner, size, and modification date of each file.
The output should omit hidden files.
View the contents of the /boot directory in the long listing format, and omit hidden files.
Redirect the output to the /home/student/grading/longlisting.txt file.
[student@serverb ~]$ ls -l /boot > grading/longlisting.txtReturn to the workstation system as the student user.
[student@serverb ~]$ exit
logout
Connection to serverb closed.This concludes the section.