Bookmark this page

Guided Exercise: Navigating Directories

Identify the file system hierarchy and navigate directories.

Outcomes

  • Navigate to a different directory by using absolute and relative paths.

  • Identify your current directory.

  • View a directory structure.

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

Instructions

  1. Use the tree command to view the directory structure of the /home/student directory, and use the -L 1 option to restrict the output to one level of results.

    [student@workstation ~]$ tree -L 1
    .
    ├── Desktop
    ├── Documents
    ├── Downloads
    ├── Music
    ├── Pictures
    ├── Public
    ├── Templates
    └── Videos
  2. Without changing to the Documents directory, create a Work directory in the Documents directory by using a relative path.

    [student@workstation ~]$ mkdir Documents/Work
    1. Change your current working directory to the new directory that you created.

      [student@workstation ~]$ cd Documents/Work
  3. From your new location, change to the Downloads directory by using a relative path.

    [student@workstation Work]$ cd ../../Downloads
    1. View the path of your current directory.

      [student@workstation Downloads]$ pwd
      /home/student/Downloads
  4. Redirect output into a file called hello.txt in the Documents/Work directory by using the absolute path.

    [student@workstation Downloads]$ echo "hello world" > \
    /home/student/Documents/Work/hello.txt
    1. View the contents of the hello.txt file by using a relative path.

      [student@workstation Downloads]$ cat ../Documents/Work/hello.txt
      hello world
    2. Use the relative path to the hello.txt file to obtain its absolute path.

      [student@workstation Downloads]$ realpath ../Documents/Work/hello.txt
      /home/student/Documents/Work/hello.txt
    3. View the contents of the hello.txt file by using the absolute path.

      [student@workstation Downloads]$ cat /home/student/Documents/Work/hello.txt
      hello world
  5. Return to the student user home directory by using the default action of the cd command.

    [student@workstation Downloads]$ cd
    [student@workstation ~]$

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

Revision: rh104-9.1-3d1f2bc