Red Hat System Administration I
Note
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.
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
serverbas thestudentuser.Create the
/home/student/gradingdirectory.Create three empty files called
grade1,grade2, andgrade3, in the/home/student/gradingdirectory.Capture the first five lines of the
/home/student/bin/managefile in the/home/student/grading/review.txtfile.Append the last three lines of the
/home/student/bin/managefile to the/home/student/grading/review.txtfile. Do not overwrite any existing text in the/home/student/grading/review.txtfile.Copy the
/home/student/grading/review.txtfile to the/home/student/grading/review-copy.txtfile.Edit the
/home/student/grading/review-copy.txtfile so that theTest JJline appears twice.Edit the
/home/student/grading/review-copy.txtfile to remove theTest HHline.Edit the
/home/student/grading/review-copy.txtfile so that a line withA new lineexists between theTest BBline and theTest CCline.Create the
/home/student/hardcopyhard link to the/home/student/grading/grade1file. You must create the hard link after completing the earlier step to create the/home/student/grading/grade1file.Create the
/home/student/softcopysymbolic link to the/home/student/grading/grade2file.Save the output of a command that lists the contents of the
/bootdirectory to the/home/student/grading/longlisting.txtfile. 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
serverbas thestudentuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$Create the
/home/student/gradingdirectory. If the/home/studentdirectory is your current directory, then you do not need to specify the absolute path to thegradingdirectory when creating it.[student@serverb ~]$
mkdir gradingIn the
/home/student/gradingdirectory, create three empty files calledgrade1,grade2, andgrade3.Create the empty files called
grade1,grade2, andgrade3in the/home/student/gradingdirectory. Apply the brace expansion shell feature to create all three files with a singletouchcommand.[student@serverb ~]$
touch grading/grade{1,2,3}Verify that the
grade1,grade2, andgrade3files exist in the/home/student/gradingdirectory.[student@serverb ~]$
ls grading/grade1 grade2 grade3
Copy the first five lines of the
/home/student/bin/managefile to the/home/student/grading/review.txtfile.View the first five lines of the
/home/student/bin/managefile and redirect the output to the/home/student/grading/review.txtfile. 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.txtfile contains the following text:Test AA Test BB Test CC Test DD Test EE
Append the last three lines of the
/home/student/bin/managefile to the/home/student/grading/review.txtfile. 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/managefile and append the output to the/home/student/grading/review.txtfile.[student@serverb ~]$
tail -3 bin/manage >> grading/review.txtVerify that the
/home/student/grading/review.txtfile 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.txtfile to the/home/student/grading/review-copy.txtfile.Navigate to the
/home/student/gradingdirectory.[student@serverb ~]$
cd grading/[student@serverb grading]$Copy the
/home/student/grading/review.txtfile to the/home/student/grading/review-copy.txtfile.[student@serverb grading]$
cp review.txt review-copy.txtNavigate back to the home directory of the
studentuser.[student@serverb grading]$
cd[student@serverb ~]$
Edit the
/home/student/grading/review-copy.txtfile to have two sequentialTest JJlines.Use the
vimtext editor to open the/home/student/grading/review-copy.txtfile.[student@serverb ~]$
vim grading/review-copy.txtFrom the command mode in
vim, scroll down to theTest JJline. 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 quitvim. Verify that the/home/student/grading/review-copy.txtfile contains the following text:Test AA Test BB Test CC Test DD Test EE Test HH Test II
Test JJTest JJ
Edit the
/home/student/grading/review-copy.txtfile to remove theTest HHline.Use the Vim text editor to open the
/home/student/grading/review-copy.txtfile.[student@serverb ~]$
vim grading/review-copy.txtFrom the command mode in Vim, scroll down to the
Test HHline. Press the d key twice on your keyboard to delete the line of text. Type wq to save the changes and quitvim. Verify that the/home/student/grading/review-copy.txtfile 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.txtfile so that the line withA new lineexists between theTest BBline and theTest CCline.Use the Vim text editor to open the
/home/student/grading/review-copy.txtfile.[student@serverb ~]$
vim grading/review-copy.txtFrom the command mode in Vim, scroll down to the
Test CCline. Press the i key to switch to the insert mode while keeping the cursor at the beginning of theTest CCline. 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 ofA new linetext. 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.txtfile contains the following text.Test AA Test BB
A new lineTest CC Test DD Test EE Test II Test JJ Test JJ
Create the
/home/student/hardcopyhard link to the/home/student/grading/grade1file.Create the
/home/student/hardcopyhard link to the/home/student/grading/grade1file.[student@serverb ~]$
ln grading/grade1 hardcopyView the link count of the
/home/student/grading/grade1file.[student@serverb ~]$
ls -l grading/grade1-rw-r--r--.2student student 0 Mar 6 16:45 grading/grade1
Create the
/home/student/softcopysymbolic link to the/home/student/grading/grade2file.Create the
/home/student/softcopysymbolic link to the/home/student/grading/grade2file.[student@serverb ~]$
ln -s grading/grade2 softcopyView the properties of the
/home/student/softcopysymbolic link.[student@serverb ~]$
ls -l softcopylrwxrwxrwx. 1 student student 14 Mar 6 17:58softcopy -> grading/grade2
List the contents of the
/bootdirectory and redirect the output to the/home/student/grading/longlisting.txtfile. 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
/bootdirectory in the long listing format, and omit hidden files. Redirect the output to the/home/student/grading/longlisting.txtfile.[student@serverb ~]$
ls -l /boot > grading/longlisting.txtReturn to the
workstationsystem as thestudentuser.[student@serverb ~]$
exitlogout Connection to serverb closed.