Bookmark this page

Guided Exercise: Manipulating Files and Directories

Manipulate files across different directories.

Outcomes

  • Create, copy, move, rename, and find files and directories.

  • Create shortcuts to files and to directories.

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-organize

Instructions

  1. Create a Work directory in the Documents directory.

    [student@workstation ~]$ mkdir Documents/Work
  2. Create an empty file called test.txt in the Documents/Work directory.

    [student@workstation ~]$ touch Documents/Work/test.txt
  3. Move the test.txt file to the Documents directory.

    [student@workstation ~]$ mv Documents/Work/test.txt Documents
    1. Confirm the file's new location by listing the contents of the Documents directory.

      [student@workstation ~]$ ls Documents
      Work  test.txt
  4. Copy the test.txt file into the Work directory and rename it to myfile.txt. Then remove the test.txt file in the Documents directory. You can perform these tasks in one command by using the mv command.

    [student@workstation ~]$ mv Documents/test.txt Documents/Work/myfile.txt
    1. Confirm the file's new location by using the find command.

      [student@workstation ~]$ find /home/student -iname myfile.txt
      /home/student/Documents/Work/myfile.txt
  5. Verify that the ~/.local/share/Trash/files directory exists. If the directory does not exist, then create the directory. Create the Bin symbolic link to the ~/.local/share/Trash/files directory.

    1. Verify that the ~/.local/share/Trash/files directory exists.

      [student@workstation ~]$ ls -l ~/.local/share/Trash/files
      ls: cannot access '/home/student/.local/share/Trash/files': No such file or directory
    2. Create the Trash directory under the ~/.local/share directory. Make sure to create any directory that is missing in the path.

      [student@workstation ~]$ mkdir -p ~/.local/share/Trash/files
    3. Create the Bin symbolic link to the Trash directory.

      [student@workstation ~]$ ln --symbolic /home/student/.local/share/Trash/files Bin
  6. Rename the Work directory to Done, and move it to the Trash directory by using the Bin symbolic link. You can perform these tasks in one command by using the mv command.

    [student@workstation ~]$ mv Documents/Work Bin/Done
  7. Create a symbolic link to the test.txt file.

    [student@workstation ~]$ ln --symbolic Documents/test.txt "shortcut to test.txt"
    1. Add the hello world text to the shortcut to test.txt file. You can perform this task by using the echo command and redirecting the output.

      [student@workstation ~]$ echo "hello world" > "shortcut to test.txt"
    2. Confirm that the text appears in the test.txt file.

      [student@workstation ~]$ cat Documents/test.txt
      hello world

Finish

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-organize

Revision: rh104-9.1-3d1f2bc