Bookmark this page

Lab: Creating, Viewing, and Editing Text Files

Performance Checklist

In this lab, you will edit a file using Vim's visual mode to simplify repetitive edits.

Outcomes

Familiarity with the utilities and techniques required to perform file editing. The final edited file will be a list of selected files and tabular data.

Perform the following steps on serverX unless directed otherwise. Log in as student and begin in the student's home directory.

  1. Redirect a long listing of all content in student's home directory, including hidden directories and files, into a file named editing_final_lab.txt. Your home directory files may not exactly match those shown in the example graphics. This lab edits arbitrary lines and columns. The important outcome is to practice the visual selection process.

    [student@serverX ~]$ cd
    [student@serverX ~]$ ls -al > editing_final_lab.txt
  2. Edit the file using Vim, to take advantage of visual mode.

    [student@serverX ~]$ vim editing_final_lab.txt
  3. Remove the first three lines, since those lines are not normal file names. Enter line-based visual mode with upper case V.

    Use the arrow keys to position the cursor at the first character in the first row. Enter line-based visual mode with V. Move down using the down arrow key twice to select the first three rows. Delete the rows with x.

  4. Remove the permission columns for group and other on the first line. In this step, enter visual mode with lower case v, which allows selecting characters on a single line only.

    Use the arrow keys to position the cursor at the first character. Enter visual mode with v. Use the arrow keys to position the cursor at the last character, as shown in the screenshot. Delete the selection with x.

  5. Remove the permission columns for group and other on the remaining lines. This step will use a more efficient block selection visual mode to avoid having to repeat the single line edit multiple times. This time, enter visual mode with the control sequence Ctrl+v, which allows selecting a block of characters on multiple lines.

    Use the arrow keys to position the cursor at the first character. Enter visual mode with the control sequence Ctrl+v. Use the arrow keys to position the cursor at the last character of the column on the last line, as shown in the screenshot. Delete the selection with x.

  6. Remove the group owner column, leaving only one "student" column on all lines. Use the same block selection technique as the last step.

    Use the arrow keys to position the cursor at the first character of the group owner column. Enter visual mode with Ctrl+v. Use the arrow keys to position the cursor at the last character and row of the group owner column, as shown in the screenshot. Delete the selection with x.

  7. Remove the time column, but leave the month and day on all lines. Again, use the block selection visual mode.

    Use the arrow keys to position the cursor at the first character. Enter visual mode with Ctrl+v. Use the arrow keys to position the cursor at the last character and row of the time column, as shown in the screenshot. Delete the selection with x.

  8. Remove the Desktop and Public rows. This time, enter visual mode with upper case V, which automatically selects full lines.

    Use the arrow keys to position the cursor at any character on the Desktop row. Enter visual mode with upper case V. The full line is selected, as shown in the screenshot. Delete the selection with x. Repeat for the Public row.

  9. Save and exit. Make a backup, using the date (in seconds) to create a unique file name.

    [student@serverX ~]$ cp editing_final_lab.txt editing_final_lab_$(date +%s).txt
  10. Mail the file contents as the message, not an attachment, to the user student.

    [student@serverX ~]$ cat editing_final_lab.txt | mail -s "lab file" student
  11. Append a dashed line to the file to recognize the beginning of newer content.

    [student@serverX ~]$ echo "----------------------------------------" >> editing_final_lab.txt
  12. Append a full process listing, but only for processes owned by the current user student and running on the currently used terminal. View the process listing and send the listing to the file with one command line.

    [student@serverX ~]$ ps -f | tee -a editing_final_lab.txt
  13. Confirm that the process listing is at the bottom of the lab file.

    [student@serverX ~]$ cat editing_final_lab.txt
    -rw-  1 student  7691 Mar  5  .bash_history
    -rw-  1 student    18 Jan 29  .bash_logout
    -rw-  1 student   193 Jan 29  .bash_profile
    -rw-  1 student   231 Jan 29  .bashrc
    drwx 12 student  4096 Feb 22  .cache
    drwx 18 student  4096 Feb 21  .config
    drwx  2 student  4096 Feb 23  Documents
    drwx  2 student     6 Feb 16  Downloads
    drwx  2 student  4096 Feb 23  Music
    drwx  2 student     6 Feb 23  Pictures
    drwx  2 student    24 Feb 22  .ssh
    drwx  2 student     6 Feb 16  Templates
    drwx  2 student  4096 Feb 23  Videos
    -rw-  1 student  1020 Feb 21  .viminfo
    
    ----------------------------------------
    UID        PID  PPID  C STIME TTY          TIME CMD
    student   2005  2001  0 16:01 pts/0    00:00:00 /bin/bash
    student  26923  2005  0 19:14 pts/0    00:00:00 ps -f
    student  26924  2005  0 19:14 pts/0    00:00:00 tee -a editing_final_lab.txt
Revision: rh124-7-1b00421