s

The Linux Directory/File Tree– Part I

Linux uses the conventional hierarchical directory structure where directories may contain both files and sub-directories

  • Sub-directories may further hold more files and sub-directories
  • Sub-directory, also referred to as a child directory, is a directory located under a parent directory

The Linux directory structure is similar to an inverted tree where the top of the tree is the root of the directory and branches and leaves are sub-directories and files, respectively

There are some differences in the filesystems between Linux distributions. .For help about your machine, enter “man hier” to find information about the file system hierarchy. . .this manual will explain the directory structure on your computer.

Some of these directories hold static data while others contain dynamic (or variable) information

  • Static data refers to file contents that are usually not modified
  • Normally contain commands, library routines, kernel files, device files, etc.,
  • Dynamic or variable data refers to file contents that are modified and updated as required
  • Hold log files, status files, configuration files, temporary files, and so on

Explaination of “The Linux Directory/File Tree”:

/ – Root

  • The top-level file system in the FHS
  • The point where the entire file system structure is ultimately connected
  • Only root user has write privilege under this directory.
  • The root of the directory is represented by the forward slash (/) character
  • The forward slash character is also used as a directory separator in a path… such as /etc/rc.d/init.d/network
  • Please note that /root is root user’s home directory, which is not same as /.
  • Example: ls /

/bin – User Binaries

  • Contains binary executables.
  • Common linux commands you need to use in single-user modes are located under this directory.
  • Commands used by all the users of the system are located here.
  • For example: ps, ls, ping, grep, cp.
  • You can find a /binsubdirectory in many other directories. A user name serena could put her own programs in “/home/serena/bin
  • Example: ls /bin

/sbin – System Binaries

  • Just like /bin, /sbin also contains binary executables.
  • But, the linux commands located under this directory are used typically by system administrator, for system maintenance purpose.
  • For example: iptables, reboot, fdisk, ifconfig, swapon
  • /sbin contains binaries to configure the Operating System
  • Many of the system binaries require “root” privilege to perform certain tasks
  • Example: ls /sbin

/etc – Configuration Files

  • Contains system configuration files required by all programs.
  • This also contains startup and shutdown shell scripts used to start/stop individual programs.
  • For example:# ls /etc/resolv.conf, /etc/logrotate.conf

Reference Attached Sheet about the different files located in “/etc”

/dev – Device Files

  • Contains device files/nodes for physical hardware and virtual devices.
  • These include terminal devices, usb, or any device attached to the system.
  • Appear to be ordinary files, but are not actually located on the hard disk.
  • The Linux kernel communicates with these devices through corresponding device nodes located here
  • Example:ls /dev/sd*, /dev/tty1, /dev/usbmon0

/proc – Process Information

  • Contains information about system process.
  • /proc is another special directory, appearing to be ordinary files, but not taking up disk space. It is actually a view of the kernel, or better, what the kernel manages, and is a means to interact with it directly...Such as CPU, memory, disks, partitioning, file systems, networking, and running processes..
  • This is a pseudo filesystem which contains information about running processes. For example: # ls /proc/{pid} directory contains information about the process with that particular pid.
  • This is a virtual filesystem with text information about system resources. For example: # ls /proc/uptime

/var – Variable Files

  • var stands for variable files.
  • Content of the files that are expected to grow can be found under this directory.
  • Contains data that frequently changes while the system is operational
  • Files holding log, status, spool, lock, and other dynamic data are located here

Common sub-directories under “/var” …

/var/log:

  • Storage for most system log files like:
  • system logs
  • boot logs
  • failed user logs
  • user logs
  • installation logs
  • cron logs
  • mail logs
  • etc…

/var/opt:

  • Additional software installed in
  • Stores log, status, and other variable data files for that software

/var/spool:

  • Directories that hold print jobs, cron jobs, mail messages, and other queued items before being sent out

/var/tmp:

  • Large temporary files
  • Temporary files that need to exist for longer periods of time than what is allowed in /tmp
  • These files survive system reboots and are not automatically deleted

/tmp – Temporary Files

  • Directory that contains temporary files created by system and users.
  • Files under this directory are deleted when system is rebooted.
  • Never use /tmp to store data that is important or which you wish to archive
  • Example: # ls /tmp

/usr – User Programs

  • “usr” stands for Unix System Resources
  • Contains general files related to the system
  • Contains binaries, libraries, documentation, and source-code for second level programs.

Sub-directories under /usr:

  • /usr/bin:
  • contains binary files for user programs.
  • Contains crucial executable user executable commands
  • If you can’t find a user binary under /bin, look under /usr/bin.
  • For example: at, awk, cc, less, scp
  • /usr/sbin:
  • Most commands required at system boot are located here as well as commands requiring root privileges to run
  • contains crucial sys admin commands not intended for execution by regular users.
  • If you can’t find a system binary under /sbin, look under /usr/sbin.
  • For example: atd, cron, sshd, useradd, userdel
  • /usr/lib:
  • contains shared library routines required by many commands and programs located in /usr/bin and /usr/sbin directories, as well as by the kernel and other programs
  • /usr/local:
  • This directory serves as a sys admin repository for storing commands and tools downloaded from the web, developed in-house, or obtained elsewhere
  • /usr/src:
  • Used to store source code
  • /usr/include:
  • Contains header files for C language
  • /usr/share:
  • Location for man pages, documentation, sample templates, configuration files, etc… that may be shared on multi-vendor Linux platforms

/home – Home Directories

  • Home directories for all users to store their personal files.
  • It is common practice (but not mandatory) to name the users home directory after the user name in the format “ /home/$USERNAME ”
  • For example: # ls /home/john, /home/nikita

/boot – Boot Loader Files

  • Contains boot support and configuration files.
  • All Files needed to boot the computer
  • Kernel initrd, vmlinux, grub files are located under /boot
  • For example: # ls /boot

/lib – System Libraries

  • Contains library files that supports the binaries located under /bin and /sbin
  • Library filenames are either ld* or lib*.so.*
  • For example:# ls /lib

/opt – Optional add-on Applications

  • opt stands for optional.
  • The purpose of /opt is to store additional software. In many cases this is software from outside the distribution repository.. You may find an empty /opt directory on many systems.
  • Contains add-on applications from individual vendors.
  • add-on applications should be installed under either /opt/ or /opt/ sub-directory.
  • A Large package can install all its files in /bin, /lib, /etc subdirectories within /opt/$packagename/

/mnt – Mount Directory

  • Temporary mount directory where sysadmins can mount filesystems.
  • Should be empty and only used for temporary mount points

/media – Removable Media Devices

  • Temporary mount directory for removable media, such as floppy, CD, DVD, USB, and Zip drives.
  • For examples: # ls /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer
  • Since/media is rather new in the Unix world, you could very well encounter systems running without this directory. Most Linux distributions today mount all removable media in /media

/srv – Service Data

  • srv stands for service.
  • You may use /srv for data that is served by your system
  • The FHS allows locating cvs, rsync, ftp and www data in this location

For example: # ls /srv

/sys - System File System

  • Info about configured hotplug hardware devices is stored and maintained in the "/sys" file system
  • This info is referenced for loading kernel modules, creating device nodes in the "/dev" directory, and configuring each device.
  • This file system is auto maintained as well.

Assignments:

Internal Exercise

 Questions:

  • Request from Instructor when you have completed the video and Internal Exercise

Exercise(s):

No Exercise

Lab(s):

No Lab

Internal Exercise:

 Yes