Red Hat System Administration I
Edit a text file with the vim editor.
Outcomes
Use Vim to edit files.
Use Vim visual mode to simplify editing large files.
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 edit-review
Instructions
On
workstation, create thelab_fileshell variable and assignediting_final_lab.txtas the value. List the contents of thestudenthome directory, including hidden directories and files, as well as permissions, file sizes, and modification times, and redirect the output to theediting_final_lab.txtfile by using the shell variable.On the
workstationmachine, create thelab_fileshell variable and assign a value ofediting_final_lab.txt. Use thels -alcommand in thestudenthome directory and redirect the output to theediting_final_lab.txtfile.[student@workstation ~]$
lab_file=editing_final_lab.txt[student@workstation ~]$ls -al > $lab_fileUse Vim to edit the
editing_final_lab.txtfile. Use thelab_fileshell variable.Enter the line-based visual mode of Vim. Your screen output might differ from these examples. Remove the first three lines of the
editing_final_lab.txtfile.Enter the visual mode of Vim. Remove the last seven characters from the first column on the first line. Preserve only the first four characters of the first column.
Use the arrow keys to position the cursor at the last character of the first column on the first line. Delete the selection by typing x.
Enter the visual block mode of Vim. Repeat the operation of the previous step, but this time select from the second to the last line. Preserve only the first four characters of the first column.
Enter the visual block mode of Vim and remove the fourth column of the file.
Enter the visual block mode of Vim to remove the time column, to leave the month and day columns on all lines.
Enter the visual line mode of Vim and remove the rows that contain the
DesktopandPublicstrings.Save your changes and exit the file.
Back up the
editing_final_lab.txtfile and append the date (in seconds) at the end of the file name preceded with an underscore (_) character. Use thelab_fileshell variable.Append a dashed line to the
editing_final_lab.txtfile. The dashed line should contain 12 dash (-) characters for this lab to be graded correctly. Use thelab_fileshell variable.List the content of the
Documentsdirectory, and append the output to theediting_final_lab.txtfile, and display the output in the terminal. Use theteecommand and thelab_fileshell variable.Confirm that the directory listing is at the bottom of the lab file. Use the
lab_fileshell variable.[student@workstation ~]$
cat $lab_filedrwx 3 student 17 Mar 4 .ansible -rw- 1 student 18 Nov 5 .bash_logout -rw- 1 student 141 Nov 5 .bash_profile -rw- 1 student 492 Nov 5 .bashrc drwx 9 student 4096 Mar 8 .cache drwx 8 student 4096 Mar 8 .config drwx 2 student 6 Mar 8 Documents drwx 2 student 6 Mar 8 Downloads -rw- 1 student 0 Mar 8 editing_final_lab.txt drwx 2 student 25 Mar 4 .grading drwx 4 student 32 Mar 8 .local drwx 2 student 6 Mar 8 Music drwx 2 student 6 Mar 8 Pictures drwx 2 student 77 Mar 4 .ssh drwx 2 student 6 Mar 8 Templates drwx 3 student 18 Mar 4 .venv drwx 2 student 6 Mar 8 Videos ------------ lab_review.txt






