Directory Tree
Contents
Filesystems Hierarchy Standard (FHS)
FHS is a standard that is widely used in Linux systems. It dictates the folders and layout of folders.A filesystem is a specification that allows us to store files and folders. As an example, on Windows we have the "NTFS" filesystem. If we plug-in a flash drive we will see that it has a different filesystem; maybe "FAT32" . Why did they put a different file system on the flash drive. So it's possible that when the person buys the flash drive the person may have a Linux or Mac machine and "NTFS" won't work on it but Linux and Mac both have support for "FAT32" and will recognize it.
We can have different partitions on a hard drive that have a file system assigned to each partition. A partition's file cannot extend into another partition. The partition concept is a hard drive concept and nothing to do with operating system specific things. The partitions are isolated from each other. On Windows if we plug-in in a flash drive, then we will automatically see a drive letter like "D:" or "E:" depending on what letters are used up already. However we do not have such a system in Linux. Rather we have folders; so if we plug-in a flash drive we might have a folder such as "/mnt/myflashdrive" to access it. If we want to see the files on the flash drive then we "cd" to "/mnt/myflashdrive" to access the files. The file system on the flash drive can be accessed by associating the device file in the "/dev" folder with the folder we want to use to access the device. This process is called mounting. These concepts ( mounting, filesystem, partition ) are covered in detail on the chapter on file systems.
If we have a "tmp" folder on the root drive then we could use mounting to mount this folder "/tmp" with an external hard drive just dedicated for the "tmp" folder" . This can be useful if "tmp" gets filled up very fast then only "tmp" will be affected; the other parts of the system would continue to work.
If we do a ls on the "/" on the hills server we get the following folders: [amittal@hills /]$ ls bin dev home logs ops pub run students users boot devnull lib media opt restore sbin sys usr clubweb etc lib64 mnt proc root srv tmp var
root
The root folder is indicated by "/" . It contains the files needed for booting up the system. It will have the "/boot" folder that contains the boot loader and may contain the kernel also. It also brings the whole system up to such a state such that other filesystems may be mounted on it. This is not to be confused with a folder named "root". That "root" folder is the home folder for the user root.usr
This contains commands, libraries, manual pages, and other files that do not change. No file should be specific to the machine. The filesystem could be mounted on a network drive to save hard drive space. It can also be mounted as read only.TO DO: What is in the following subfolders ? Pick a file or folder in the subfolder that you are familiar with and explain it's purpose.
General system wide binaries such as "grep" , "cat" , "date" . /usr/bin These are "C" language ".h" files. /usr/include Libararies that are needed by programs in "/usr" folder and elsewhere. /usr/lib Executables that are usually run by the superuser. /usr/sbin Configuration data files. /usr/share Contains the source code for the Linux kernel. /usr/srcbin
This folder contains user executable files. Sometimes as is the case for hills server the "/bin" is a symbolic link to "/usr/bin" .
sbin
This folder contains executable files but these files are not intended for normal users. Like the "bin" folder this is a link to "/usr/sbin" on the hills folder.
boot
Contians the bootloader, kernel executables,dev
This contains the device files ( not device driver files ). A device driver is software that allows us to interact with a device. The device file is an interface to a device driver file but appears as an ordinary file. These are special files that correspond to connected devices on the machine. Those devices can be accessed by mounting the device file.There are many kinds of devices that exist in the "dev" folder. We can have terminals, hard drives, cdroms, printers, scanners, etc. There are naming conventions for the different groups:
lp: line printers
pt: pseudo terminals
tty: terminals
There are usually 2 kinds of devices files; character and block device files. The character device files will read/write a character at a time whereas the block can read/write more. Some Linux systems will have a script called "makedev" or "MAKEDEV"
/dev/null
This is a virtual file and anything written to it, is discarded.[amittal@hills /]$ echo "Test" Test [amittal@hills /]$ echo "Test" > /dev/null [amittal@hills /]$It is usually used to suppress error messages to the screen.[amittal@hills ~]$ cd /tmp [amittal@hills tmp]$ find . -name "*.sh" find: ‘./systemd-private-dbe57da33f664111acfb7a59cceda729-php-fpm.service-qPcWyg’: Permission denied find: ‘./systemd-private-dbe57da33f664111acfb7a59cceda729-httpd.service-DmKG9e’: Permission denied find: ‘./systemd-private-dbe57da33f664111acfb7a59cceda729-chronyd.service-2WaGhh’: Permission denied find: ‘./vmware-root_1216-2965448157’: Permission denied find: ‘./systemd-private-dbe57da33f664111acfb7a59cceda729-postfix.service-0oMVZe’: Permission denied We can suppress these message by redirecting the errors to "/dev/null" . [amittal@hills tmp]$ find . -name "*.sh" -print 2>/dev/null [amittal@hills tmp]$/dev/random /dev/urandom
We also have virtual files "/dev/random" and "/dev/urandom" . These generate random data. "The data generated by "random" is more random than "urandom" and thus takes more time.Generating 1 line of random data [amittal@hills ~]$ head -1 /dev/random ¦G¦/no?O¦iK¦L¦4¦z¦_?¦:¦##¦+r¦¦¦q6'?¦¦¦ ¦J¦}Lq)¦-(4 ¦q¦¦<¦K+¦¦¦xR¦j¦¦¦1S¦¦na~=¦¦¦¦¦cRG [amittal@hills ~]$/dev/sda
The first SCSI drive. The files "sda1" , "sda2" signify the other SCSI drives.TO DO Do a ls on the "/dev" folder. Find out what the "sda" and "tty" files mean.
etc
This contains the configuration files specific to the machine./etc/rc
This folder contains scripts to run at boot time. This can also contain a directory of scripts./etc/passwd
This is a file about the users in the system. It does not contain passwords[amittal@hills ~]$ cat /etc/passwd | grep amittal amittal:x:2548:1258:Ajay MIttal:/users/amittal:/bin/bash The first entry is the username. The "x" means the password is stored in the "/etc/passwd" file. The third entry is the user id. The fourth entry is the primary group id. Tje fifth entry is the comment section. In this case it contains my name. The sixth entry is the home directory when the user logs in. . The seventh entry is the shell that starts up when the user logs in./etc/shadow
This is a file about the user's passwords/etc/fdprm
Floppy disk parameter table. Describes the different floppy disk formats./etc/fstab
Lists the filesystems mounted at start time./etc/group
Contains the group names and the users that belong to those groups./etc/inittab
Configuration program for the init program. The hills server does not use "init" and instead uses "systemd" ./etc/issue
Contains the message output by the system upon user login./etc/magic
Contains information about the various file formats./etc/motd
Message of the day. As an example this can a notification of the downtimes./etc/mtab
Lists the current mounted file systems./etc/login.defs
Configuration file for the login command./etc/printcap
Configuration information for the printers./etc/profile /etc/bash.rc
Files executed at login. Used to set default global settings.TO DO Do a cat on "etc/profile" on the hills server. Search for the HISTSIZE parameter . What is this set to. What does it signify ? From the shell type: [amittal@hills ~]$ set | grep "HISTSIZE" HISTSIZE=1000 [amittal@hills ~]$ How was this set to 1000 ?/etc/shells
Lists the trusted shells that a user can select to login.[amittal@hills ~]$ cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /usr/bin/bash /bin/ksh /bin/rksh /usr/bin/ksh /usr/bin/rksh /bin/csh /bin/tcsh /usr/bin/csh /usr/bin/tcsh [amittal@hills ~]$Video on Filesystems, Virtual File Systems, Mounting
lib
Libararies that are needed by programs in "/usr" folder and elsewhere. On the hills server this is a link pointing to "/usr/lib" .$ cd / $ ls -l total 392 lrwxrwxrwx. 1 root root 7 Apr 22 2020 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 Apr 25 2022 boot drwxr-xr-x 5 root root 42 Aug 23 2017 clubweb drwxr-xr-x 22 root root 3320 Jan 12 09:57 dev -rw------- 1 root root 0 Aug 16 12:18 devnull drwxr-xr-x. 129 root root 8192 Jan 14 21:34 etc drwxr-xr-x. 9 root root 127 Jun 30 2022 home lrwxrwxrwx. 1 root root 7 Apr 22 2020 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Apr 22 2020 lib64 -> usr/lib64tmp
Used for storing temporary files.$ cd /tmp $ ls -lt total 0 drwxr-xr-x 2 galforte students 6 Jan 12 21:23 hsperfdata_galforte drwx------ 3 root root 17 Jan 12 09:57 systemd-private-dbe57da33f664111acfb7a59cceda729-httpd.service-DmKG9e drwx------ 3 root root 17 Jan 12 09:57 systemd-private-dbe57da33f664111acfb7a59cceda729-php-fpm.service-qPcWyg drwx------ 3 root root 17 Jan 12 09:57 systemd-private-dbe57da33f664111acfb7a59cceda729-postfix.service-0oMVZe drwx------ 2 root root 6 Jan 12 09:57 vmware-root_1216-2965448157 drwx------ 3 root root 17 Jan 12 09:57 systemd-private-dbe57da33f664111acfb7a59cceda729-chronyd.service-2WaGhhThe "t" option sorts the files by time. Using this and the output of the "/proc/uptime" we can get an idea that the "tmp" folder is cleaned up during system start up.mnt
Mount point for temporary mount points.proc
Virtual file system showing processes as files. By virtual we mean that the file is not a normal file and data is constructed when we try to do something with it. If we create a process then a folder with that process id gets created. There are many files and subfolders underneath this process id folder./proc/process id/status /proc/uptime /proc/meminfo
Example: Create a process. A process gets created with this shell command that waits 30 minutes . $ sleep 1800 & [1] 109792 We can get information about this process. $ cat /proc/109792/status Name: ksh Umask: 0022 State: S (sleeping) Tgid: 109792 Ngid: 0 Pid: 109792 PPid: 106524 TracerPid: 0 Uid: 2548 2548 2548 2548 ... The "uid" is the person who created the process. We can confirm that. $ cat /etc/passwd | grep "amittal" amittal:x:2548:1258:Ajay MIttal:/users/amittal:/bin/bash The uptime "file" contains 2 numbers. The first is the number of seconds the system has been up and the second is the idle time in seconds. $ cat /proc/uptime 199781.84 1189533.23 $ If we convert the first number to days by dividing it by ( 24*60*60 = 86,400 ) we get roughly 2 days. $ cat /proc/meminfo MemTotal: 12056536 kB MemFree: 10506660 kB MemAvailable: 11061820 kB Buffers: 4392 kB Cached: 801216 kB SwapCached: 0 kB Active: 492272 kB Inactive: 519916 kB Active(anon): 12552 kB Inactive(anon): 269820 kB ... The "meminfo" file contains information about the RAM and for the hills server shows that we have around 12 Gb of memory. The mounts file contains information about the mounting points currently used by the system. $ cat /proc/mounts sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 devtmpfs /dev devtmpfs rw,nosuid,size=6010896k,nr_inodes=1502724,mode=755 0 0 securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0 ...Similarly "/proc/cpuinfo" shows information about the processor and "/proc/version" displays the kernel version number.TO DO Find out the CPU manfacturer and speed of the CPU at hills server using the "/proc/cpuinfo" file. Find out the kernel version using the "/proc/version" file.var
The "var" stands for variable and is a folder where changing files are kept./var/cache
A cache is an area where we can store information that we obtained from the network, database , calculation etc. If a client requests that information then the application can first look in the cache and if the information exists then hand it back to the client. This speeds up the general process. There are considerations such as when the data should be considered stale and so on. Browsers normally use cache. Below is the setting snapshot from Chrome browser.
See full image
The "/var/cache" can store the cached data for various applications. One common use cas is the "man" application that creates man pages when we use it. We can see that there is a folder for man in "/var/cache/" /
See full image
/var/lib
Contains dynamic data libraries. Ex: "/var/lib/rpm" package files./var/lock
This is a general concept in programming. An application will create an empty file to indicate that something is being used. Another application or even the same application will check for the existence of the lock file and know that something is being used at the moment. Application can use the "/var/lock" folder to store their lock files.To do Find some folders in the lock folder and read about the applications. Ex: subsys/var/log
This folder contains application logs. The file "/var/log/wtmp" file contains login and logout information.TO DO Find this file on the hills server./var/tmp
This folder contains large temporary files that may need to exist longer than the files in the "/tmp" folder.home
Contains user home directories for users. The location may be different and can be "/users", "/usr" . We can see what folder this is by doing a simple "cd" to take us to our home folder. This is the folder we land in when we first sign on.$ cd $ pwd /users/amittal $ For a student the folder may be different: /students/