In this review, you will manage files, redirect a specific set of lines from a text file to another file and edit the text files.
Outcomes
You should be able to:
Manage files from the command line.
Display a certain number of lines from text files and redirect the output to another file.
Edit text files.
Copy any files or work you wish to keep to other systems before resetting.
Reset the workstation, servera, and serverb systems now.
Wait until the workstation, servera, and serverb systems are started.
Log in to workstation as student using student as the password.
On workstation, run lab rhcsa-rh124-review1 start to start the comprehensive review.
This script creates the necessary files to set up the environment correctly.
[student@workstation ~]$lab rhcsa-rh124-review1 start
Instructions
Accomplish the following tasks on serverb to complete the exercise.
Create a new directory called /home/student/grading.
Create three empty files in the /home/student/grading directory named grade1, grade2, and grade3.
Capture the first five lines of the /home/student/bin/manage-files file in the /home/student/grading/manage-files.txt file.
Append the last three lines of /home/student/bin/manage-files to the file /home/student/grading/manage-files.txt.
You must not overwrite any text already in the file /home/student/grading/manage-files.txt.
Copy /home/student/grading/manage-files.txt to /home/student/grading/manage-files-copy.txt.
Edit the file /home/student/grading/manage-files-copy.txt so that there should be two sequential lines of text reading Test JJ.
Edit the file /home/student/grading/manage-files-copy.txt so that the Test HH line of text must not exist in the file.
Edit the file /home/student/grading/manage-files-copy.txt so that the line A new line should exist between the line reading Test BB and the line reading Test CC.
Create a hard link named /home/student/hardlink to the file /home/student/grading/grade1.
You will need to do this after creating the empty file /home/student/grading/grade1 as specified above.
Create a soft link named /home/student/softlink to the file /home/student/grading/grade2.
Save the output of a command that lists the contents of the /boot directory to the file /home/student/grading/longlisting.txt.
The output should be a “long listing” that includes file permissions, owner and group owner, size, and modification date of each file.
Create a new directory called /home/student/grading.
From workstation, open an SSH session to serverb as student.
[student@workstation ~]$ssh student@serverb...output omitted...[student@serverb ~]$
Use the mkdir command to create the /home/student/grading directory.
[student@serverb ~]$mkdir grading
As you ran the preceding command while in the home directory of the student user, you did not specify the absolute path to the grading directory while creating it.
Create three empty files in the /home/student/grading directory named grade1, grade2, and grade3.
Use the touch command to 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}
Use the ls command to verify that the grade1, grade2, and grade3 files exist under the directory /home/student/grading.
[student@serverb ~]$ls grading/grade1 grade2 grade3
Capture the first five lines of the /home/student/bin/manage-files file in the /home/student/grading/manage-files.txt file.
Use the head command to view the first five lines of the file /home/student/bin/manage-files and redirect the output to the file /home/student/grading/manage-files.txt.
[student@serverb ~]$head -5 bin/manage-files > grading/manage-files.txt
The preceding command uses the single redirection symbol (>) to save the command output to /home/student/grading/manage-files.txt so that any existing content in the file gets overwritten.
Verify that the file /home/student/grading/manage-files.txt contains the following text.
Test AA Test BB Test CC Test DD Test EE
Append the last three lines of /home/student/bin/manage-files to the file /home/student/grading/manage-files.txt.
You must not overwrite any text already in the file /home/student/grading/manage-files.txt.
Use the tail command to view the last three lines of the file /home/student/bin/manage-files and append the output to /home/student/grading/manage-files.txt.
[student@serverb ~]$tail -3 bin/manage-files >> grading/manage-files.txt
The preceding command uses the double redirection symbol (>>) to append the output to /home/student/grading/manage-files.txt so that the existing contents in the file are preserved.
Verify that the file /home/student/grading/manage-files.txt 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/manage-files.txt file to /home/student/grading/manage-files-copy.txt.
Use the cd command to navigate to the directory /home/student/grading.
[student@serverb ~]$cd grading/[student@serverb grading]$
Use the cp command to copy the /home/student/grading/manage-files.txt file to /home/student/grading/manage-files-copy.txt.
[student@serverb grading]$cp manage-files.txt manage-files-copy.txt
Navigate back to the home directory of the user student.
[student@serverb grading]$cd[student@serverb ~]$
Edit the file /home/student/grading/manage-files-copy.txt so that there should be two sequential lines of text reading Test JJ.
Use the vim text editor to open the /home/student/grading/manage-files-copy.txt file.
[student@serverb ~]$vim grading/manage-files-copy.txt
From the command mode in vim, scroll down to the line that has the Test JJ line of text.
Press the y key twice on your keyboard 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/manage-files-copy.txt file contains the following text.
Test AA Test BB Test CC Test DD Test EE Test HH Test II Test JJ Test JJ
Notice that the preceding content includes two copies of the Test JJ line of text.
Edit the file /home/student/grading/manage-files-copy.txt so that the Test HH line of text must not exist in the file.
Use the vim text editor to open the /home/student/grading/manage-files-copy.txt file.
[student@serverb ~]$vim grading/manage-files-copy.txt
From the command mode in vim, scroll down to the line that has the Test HH line of text.
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/manage-files-copy.txt file contains the following text.
Test AA Test BB Test CC Test DD Test EE Test II Test JJ Test JJ
Notice that the preceding content does not include the Test HH line of text.
Edit the file /home/student/grading/manage-files-copy.txt so that the line A new line exists between the line reading Test BB and the line reading Test CC.
Use the vim text editor to open the /home/student/grading/manage-files-copy.txt file.
[student@serverb ~]$vim grading/manage-files-copy.txt
From the command mode in vim, scroll down to the line that has the Test CC line of text.
Press the i key on the keyboard to switch to the insert mode while keeping the cursor at the beginning of the Test CC line of text.
From the insert mode, press the Enter key on the keyboard to create a blank line above the cursor.
Use the up arrow to navigate to the blank line and create the A new line line of text.
Press the Esc key on the keyboard to switch back to the command mode.
Type :wq to save the changes and quit vim.
Verify that the /home/student/grading/manage-files-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 JJ
Notice that the preceding content includes the A new line line of text.
Create a hard link named /home/student/hardlink to the file /home/student/grading/grade1.
Use the ln command to create the hard link named /home/student/hardlink to the file /home/student/grading/grade1.
You will need to do this after creating the empty file /home/student/grading/grade1 as specified above.
[student@serverb ~]$ln grading/grade1 hardlink
Use the ls -l command to view 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 a soft link named /home/student/softlink to the file /home/student/grading/grade2.
Use the ln -s command to create the soft link named /home/student/softlink to the file /home/student/grading/grade2.
[student@serverb ~]$ln -s grading/grade2 softlink
Use the ls -l command to view the properties of the /home/student/softlink soft link.
[student@serverb ~]$ls -l softlinklrwxrwxrwx. 1 student student 14 Mar 6 17:58softlink -> grading/grade2
Save the output of a command that lists the contents of the /boot directory to the file /home/student/grading/longlisting.txt.
The output should be a “long listing” that includes file permissions, owner and group owner, size, and modification date of each file.
Use the ls -l command to view the contents of the directory /boot in the “long listing” format and redirect the output to the file /home/student/grading/longlisting.txt.
[student@serverb ~]$ls -l /boot > grading/longlisting.txt
Log out of serverb.
[student@serverb ~]$exitlogout Connection to serverb closed.