Bookmark this page

Lab: File Systems Overview

View file organization in a Linux file system and manipulate directories and files.

Outcomes

  • View directory and file structure.

  • Create, organize, copy, and remove files and directories.

  • Search for files.

  • Filter text in text files.

As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.

[student@workstation ~]$ lab start filesystem-review

Instructions

  1. List the files and directories in the student home directory. Create the utilities, scripts, and backups subdirectories in the Documents directory. Review the directory structure.

    1. View a list of entries in the home directory.

      [student@workstation ~]$ ls -l
      total 0
      drwxr-xr-x.  2 student student    6 Nov  9 21:09 Desktop
      drwxr-xr-x.  5 student student   53 Nov  9 21:35 Documents
      drwxr-xr-x.  2 student student    6 Nov  9 21:09 Downloads
      drwxr-xr-x.  2 student student    6 Nov  9 21:09 Music
      drwxr-xr-x.  2 student student    6 Nov  9 21:09 Pictures
      drwxr-xr-x.  2 student student    6 Nov  9 21:09 Public
      drwxr-xr-x.  2 student student    6 Nov  9 21:09 Templates
      drwxr-xr-x.  2 student student    6 Nov  9 21:09 Videos
    2. Create the utilities, scripts, and backups directories in the Documents directory.

      [student@workstation ~]$ mkdir Documents/utilities
      [student@workstation ~]$ mkdir Documents/scripts
      [student@workstation ~]$ mkdir Documents/backups
      [student@workstation ~]$ ls Documents
      backups  scripts  utilities
    3. View the /home/student directory structure.

      [student@workstation ~]$ tree
      .
      ├── Desktop
      ├── Documents
      │   ├── backups
      │   ├── scripts
      │   └── utilities
      ├── Downloads
      ├── Music
      ├── Pictures
      ├── Public
      ├── Templates
      └── Videos
      
      11 directories, 0 files
  2. Create servicedump.log, daily-task.sh, to-do.txt, and my-exec as empty files in the utilities directory.

    1. Change to the ~/Documents/utilities directory.

      [student@workstation ~]$ cd ~/Documents/utilities
    2. Create the servicedump.log, daily-task.sh, to-do.txt, and my-exec files.

      [student@workstation utilities]$ touch servicedump.log daily-task.sh \
      to-do.txt my-exec
      [student@workstation utilities]$ ls -l
      total 0
      -rw-r--r--. 1 student student 0 Nov  9 21:38 daily-task.sh
      -rw-r--r--. 1 student student 0 Nov  9 21:38 my-exec
      -rw-r--r--. 1 student student 0 Nov  9 21:38 servicedump.log
      -rw-r--r--. 1 student student 0 Nov  9 21:38 to-do.txt
  3. In the utilities directory, copy the daily-task.sh file to the scripts directory, and move the to-do.txt file to the backups directory.

    1. Copy the daily-task.sh file from the utilities directory to the scripts directory.

      [student@workstation utilities]$ cp daily-task.sh ../scripts/
      [student@workstation utilities]$ ls -l ../scripts/
      total 0
      -rw-r--r--. 1 student student 0 Nov  9 21:39 daily-task.sh
    2. Move the to-do.txt file to the backups directory.

      [student@workstation utilities]$ mv to-do.txt ../backups/
      [student@workstation utilities]$ ls -l ../backups/
      total 0
      -rw-r--r--. 1 student student 0 Nov  9 21:38 to-do.txt
  4. Navigate to the student home directory. Search in the Documents directory to find all the files that contain the string daily in the file name. Use the Documents directory's full path to perform the search. Save the output to the ~/results file.

    1. Change to the student user's home directory.

      [student@workstation utilities]$ cd
      [student@workstation ~]$
    2. Search in the /home/student/Documents directory to find all files with the string daily in their name. Use the Documents directory's full path to perform the search. Save the output to the ~/results file.

      [student@workstation ~]$ find /home/student/Documents -name "*daily*" > ~/results
    3. Verify that the results file has the expected content.

      [student@workstation ~]$ cat results
      /home/student/Documents/utilities/daily-task.sh
      /home/student/Documents/scripts/daily-task.sh
  5. Search the entire file system for the system dictionary file called words. The expected words file is stored in the dict parent directory. If the command produces errors, then run the command again and use output redirection to save any errors to the ~/error-results file.

    After you locate the words file, use redirection to append the first 15 lines of the words file to the ~/results file.

    1. Start the search for the words file in the / directory. The expected words file is stored in the dict parent directory.

      [student@workstation ~]$ find / -name "words"
      find: '/proc/34297/map_files': Permission denied
      find: '/proc/34297/ns': Permission denied
      find: '/proc/34299/task/34299/fd': Permission denied
      find: '/proc/34299/task/34299/ns': Permission denied
      find: '/proc/34299/fd': Permission denied
      ...output omitted...

      The find command returns many errors.

    2. Repeat the search, and use output redirection to save any errors to the ~/error-results file.

      [student@workstation ~]$ find / -name "words" 2> ~/error-results
      /usr/share/dict/words
      /usr/share/doc/words

      The /usr/share/dict/words file matches the requirements.

    3. Append the first 15 entries of the /usr/share/dict/words file to the ~/results file. Use redirection to save the results to the ~/results file.

      [student@workstation ~]$ head -15 /usr/share/dict/words >> ~/results
    4. Verify that the ~/results file has the expected content.

      [student@workstation ~]$ cat results
      /home/student/Documents/utilities/daily-task.sh
      /home/student/Documents/scripts/daily-task.sh
      1080
      10-point
      10th
      11-point
      12-point
      16-point
      18-point
      1st
      2
      20-point
      2,4,5-t
      2,4-d
      2D
      2nd
      30-30

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade filesystem-review

Finish

As the student user on the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish filesystem-review

Revision: rh104-9.1-3d1f2bc