Linux Directories

There are many important directories in Linux. The current chapter focuses on several key directories so that you will be comfortable moving around. The focus is on directories where you might need to explore data and edit files.

Learning Objectives

You should be able to Describe the purpose of the following directories:

  • /home
  • /etc
  • /var
  • /root
  • /dev
  • /media

Video Walkthrough

Use this video to follow along with the steps in this lab.

Linux Directories

  • /home. This is where user files and directories go. By default, your user account will have read/write access only to your personal directories.
  • /etc. Configuration files are stored in /etc. Configurations include your network settings or background services.
  • /var. System files that will grow and change will be stored here. If you host a website, you will probably host it in /var/www. Logs are constantly being updated in the background in the /var/log directory.
  • /root. The root user is the most powerful Linux account. The root user can read or change any data on the machine. The root user has unlimited access to everything. The /root directory is the root user's home directory.
  • /dev. In Linux, devices like network cards, monitors, and keyboards are treated as files. These files live in the /dev directory. Sometimes, you might need to point a program at one of these devices to communicate with your hardware.
  • /media. USB drives and CD-Roms are some of the media that would show up in the /media directory.

Explore the Directories

Run the following commands and look at the output to answer the questions.

  • Run:
ls /home

How many user accounts are there in the /home directory?

  • Run:
cd ~
ls

What directories exist in your home directory?

  • Run:
ls /etc

The /etc directory stores configuration files. What kinds of things do you think you can configure based on the file and directory names?

  • Run:
ls /var
  • What directories exist in /var?
  • Website files are often stored in /var/www. Does there seem to be a website there? Run:
ls /var/www
  • Run:
ls /root
  • What happened when you tried to list the root user's files and directories? Why might this be a good thing?
  • Run:
ls /dev
  • There will be many devices that you do not recognize. What devices do you recognize? Can you guess what some of the others are?
  • Run:
ls /media
  • What media is available? Note that even though Linux is running as a virtual machine, it is possible to attach virtual media to it. In this case, media does not refer to music, pictures or video. Instead, "media" refers to physical media, like CD-ROMs or USB devices.

Reflection

  • How could you find out what all of the other directories are for?
  • How is the Linux directory structure similar to Windows? How is it different?

Key Terms

  • Linux Directories: The hierarchical structure used to organize files and folders in a Linux operating system. Each directory serves a specific purpose and contains files related to that purpose. The root of this hierarchy is the / directory, from which all other directories branch out.
  • Linux /home Directory: The directory where user-specific files and directories are stored. Each user has a subdirectory within /home named after their username, which contains their personal files, configuration settings, and application data.
  • Linux /etc Directory: The directory that contains system-wide configuration files and scripts. It includes settings for the operating system, installed applications, and services. Examples of files in /etc include passwd, fstab, and hosts.
  • Linux /var Directory: The directory used for storing variable data that changes frequently. This includes log files, spool files, cache files, and temporary files. Subdirectories within /var include /var/log, /var/spool, and /var/tmp.
  • Linux /root Directory: The home directory for the root user, the superuser with administrative privileges. It is separate from the /home directory to ensure that the root user's files are isolated from regular users' files.
  • Linux /dev Directory: The directory that contains device files, which represent hardware devices and peripherals. These files allow software to interact with hardware components. Examples include /dev/sda for a hard drive and /dev/tty for a terminal device.
  • Linux /media Directory: The directory used for mounting removable media such as USB drives, CDs, and DVDs. When a removable device is connected to the system, it is typically mounted to a subdirectory within /media, allowing users to access its contents.