Skip to content

Practice Exercise: Exploring the Linux Filesystem Layout

Objectives

  • Gain a deep understanding of the Linux filesystem hierarchy.
  • Explore important directories and their purposes.
  • Learn how to navigate and interact with the Linux filesystem.

Scenario

As a Linux enthusiast, you want to become proficient in understanding the Linux filesystem hierarchy and the purposes of its various directories. This exercise will guide you through the essential directories and their roles within the Linux filesystem.

Tasks

Task 1: Researching the Linux Filesystem Hierarchy

  • Begin by researching and making a list of at least ten important directories in the Linux filesystem hierarchy.
  • For each directory, describe its purpose and the types of files or data it typically contains.
[intern@intern-a1t-inf-lnx1 ~]$ ls /
bin   dev  home  lost+found  mnt  proc  run   snap  swap.img  tmp  var
boot  etc  lib   media       opt  root  sbin  srv   sys       usr

Task 2: Navigating the Filesystem

  • Open a terminal on your Linux system.
  • Use the pwd command to display your current working directory.
  • Use the ls command to list the contents of your current directory.
  • Experiment with navigating the filesystem using cd to change directories and ls to list their contents.
  • Create a directory structure of your own to practice navigating.
[intern@intern-a1t-inf-lnx1 ~]$ pwd
/home/intern
[intern@intern-a1t-inf-lnx1 ~]$ ls
[intern@intern-a1t-inf-lnx1 ~]$ mkdir dir1
[intern@intern-a1t-inf-lnx1 ~]$ cd dir1
[intern@intern-a1t-inf-lnx1 dir1]$ ls
[intern@intern-a1t-inf-lnx1 dir1]$ mkdir academy
[intern@intern-a1t-inf-lnx1 dir1]$ ls -d academy
academy

Task 3: Understanding Key Directories

  • Select three directories from your list in Task 1, and explore them in more detail.
  • For each directory, perform the following:
  • Use ls to list its contents.
  • For this example I will explore /etc, /home, and /bin
    [intern@intern-a1t-inf-lnx1 ~]$ ls /etc/
    NetworkManager                 fonts            magic                rcS.d
    PackageKit                     fstab            magic.mime           resolv.conf
    X11                            fuse.conf        manpath.config       rmt
    stored
    [intern@intern-a1t-inf-lnx1 ~]$ ls /home/
    intern
    [intern@intern-a1t-inf-lnx1 ~]$ ls /bin/
    aa-enabled
    aa-exec
    aa-features-abi
    aarch64-linux-gnu-addr2line
    aarch64-linux-gnu-ar
    

Task 4: System Directories

  • Identify and describe the purpose of at least three directories that are critical to the Linux system's operation, such as /bin, /etc, and /lib.
    # /etc is the usual directory where applications/services configuration are 
    # /home is where the user/s home directory are created
    # /bin are where users essential binaries are stored
    

Task 5: User Directories

  • Explore the /home directory, which typically contains user home directories.
  • Identify your own home directory and display its contents using ls.
  • Create a new directory within your home directory, and then delete it.
    [intern@intern-a1t-inf-lnx1 ~]$ ls /home/
    intern
    [intern@intern-a1t-inf-lnx1 ~]$ mkdir /home/intern/new_directory
    [intern@intern-a1t-inf-lnx1 ~]$ ls /home/intern
    bin  cri-dockerd  go  hello.txt  installer_linux  new_directory
    [intern@intern-a1t-inf-lnx1 ~]$ rmdir /home/intern/new_directory/
    [intern@intern-a1t-inf-lnx1 ~]$ ls /home/intern
    bin  cri-dockerd  go  hello.txt  installer_linux
    

Task 6: Temporary Directories

  • Learn about the /tmp directory, which is used for temporary files.
  • Create a temporary file in the /tmp directory using the touch command.
  • Use ls to confirm the file's presence, and then delete it.
  • Try rebooting the instance and check if the temp.txt still exist

[intern@intern-a1t-inf-lnx1 ~]$ touch /tmp/temp.txt
[intern@intern-a1t-inf-lnx1 ~]$ ls /tmp/
snap-private-tmp
systemd-private-356e69e0d8424ce287c4e0a8352378bc-systemd-logind.service-JuEuFW
systemd-private-356e69e0d8424ce287c4e0a8352378bc-systemd-resolved.service-b6m3WE
systemd-private-356e69e0d8424ce287c
[intern@intern-a1t-inf-lnx1 ~]$ sudo reboot
...
...
[intern@intern-a1t-inf-lnx1 ~]$ ls /tmp
snap-private-tmp
systemd-private-65b7d3ffd46e4478be3d64c76d07f302-systemd-logind.service-3Faylz
systemd-private-65b7d3ffd46e4478be3d64c76d07f302-systemd-resolved.service-OcVfDh
systemd-private-65b7d3ffd46e4478be3d64c76d07f302-systemd-timesyncd.service-NmD5YB

Conclusion

This practice exercise has provided you with a comprehensive understanding of the Linux filesystem hierarchy. You've explored key directories, navigated the filesystem, and interacted with important system and user directories. This knowledge is crucial for efficient file management and system administration in Linux.