linux directory structure
DESCRIPTION
This presentation examines the way files are stored in Linux following the File System Hierarchy. It also addresses the recent proposals by Fedora to change this to merge bin directories.TRANSCRIPT
![Page 1: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/1.jpg)
Linux Directory Structure
Kevin B. O’BrienWashtenaw Linux Users Group
http://www.lugwash.org
![Page 2: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/2.jpg)
General Notes● Linux derives from Unix and is designed
to be multi-user● This explains some otherwise puzzling
choices● This may have something to do with
Fedora proposing to change this Directory Structure
![Page 3: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/3.jpg)
Drives 1● Linux derives from Unix● Different from Windows● Windows starts with drives, which are
explicit– C:– D:
![Page 4: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/4.jpg)
Drives 2● Linux does not make drives explicit. ● You can have one physical drive, several
physical drives, partition the drives into multiple partitions, and normally you won’t be aware of it.
● In a file manager, you won’t see drives, just directories
● But if you look in fstab, you will see things like hda1, hda2, sda1, sda2. These are logical drives (either physical or from partitioning)
![Page 5: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/5.jpg)
Root● In Windows, every drive has its own root
– C:\ is the root of the C drive● In Linux, there is only one root, no matter
how many drives you may have– In Linux, / is the root
● Root is ambiguous in one respect, since it can refer to the top of the file structure, and is also the name of the Administrator-type account in Linux.
![Page 6: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/6.jpg)
Root 2● For our purposes, we will refer to root as
the top of the file structure in this presentation.
![Page 7: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/7.jpg)
Comparison
/home/data
/var
•/boot•/bin•etc.
C:
D:
E:
F:
/
Disk Partitions
Linux Windows
/home
root
![Page 8: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/8.jpg)
Watch out for...● Windows uses a backslash for
everything● Linux uses a forward slash for
everything● In Windows, the logical drive (e.g. C:) is
an important part of the directory structure
● In Linux, logical drives don't mean much. You can even mount a separate physical drive under a directory that is on another drive.
![Page 9: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/9.jpg)
Watch out for 2
● In Windows, case does not matter. The C:\Windows directory is the same as the c:\windows directory.
● In Linux, everything is case sensitive. The convention in Linux is to use lower case for most things, but the important thing to remember is that /usr/bin is not the same thing as /USR/BIN.
![Page 10: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/10.jpg)
Drives vs. directories
● In Windows, drives are directories● In Linux, you can have several drives all
under one overall directory, or nested one in another in the directory structure.
● In Linux, you tell the file system where you want a drive to appear by where it is mounted. See fstab for more on this.
![Page 11: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/11.jpg)
Where did this come from?● This started with a Linux effort in August,
1993● In 1996 some BSD folks decided it should
be expanded to all Unix-like systems● This resulted in the Filesystem Hierarchy
Standard, which can be found at http://www.pathname.com/fhs/pub/fhs-2.3.html
![Page 12: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/12.jpg)
Standard?● Of course, many distros vary from this to
some degree, some (Gobo) reject it entirely, and MacOS tends to substitute more “readable” names, like Library in place of lib, etc.
● Red Hat seems to be pretty faithful http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-filesystem-fhs.html
![Page 13: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/13.jpg)
Standard? 2
● Distros can vary, but so can programs● When you install a program, it may not
follow the FHS in deciding where to place its files
● So this presentation should be considered a guide to how things more-or-less ought to work, but YMMV
![Page 14: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/14.jpg)
/● This is the symbol for the root of the file
system in Linux● Every directory is “under” root,
ultimately● This is not the same as the user “root”,
which is the user with God-like powers over the system
● The user “root” does have a directory, called /root
![Page 15: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/15.jpg)
/bin● Contains many of the commands used on
the command line● Examples include cat, chmod,dmesg, kill,
ls, mkdir more, ps, pwd, sed, su● the above commands, and many others,
must be in /bin to meet the standard.● Other commands can be optionally
included, such as tar. gzip, netstat, and ping
![Page 16: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/16.jpg)
/bin 2● There are other commands that are not in
here● They are part of the shell (e.g. cd)● For most users, this will be bash, the
Bourne-Again Shell● You can tell by looking at the man pages● Commands in /bin will have their own man
page, commands in bash will have info in the bash man page
![Page 17: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/17.jpg)
/boot
● Contains files needed for boot– kernel– Grub menu (good to know if you are dual-
booting)– Lilo boot sector backups
● Contains data that is used before the kernel starts executing user-mode programs
![Page 18: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/18.jpg)
/dev● Kinda-sorta an equivalent to a mashup
of the Device Manager and C:\Windows\System in Windows
● Contains a file describing every device, and these files can send data to each device
● In Linux, everything is a file or a directory
● We mean it. We really mean it.
![Page 19: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/19.jpg)
/dev 2
● hda1, hda2, etc. are partitions on the first physical IDE drive
● sda1, sda2, etc. are partitions on the first physical SATA drive
● /dev/cdrom is the optical drive● /dev/fd0 is the floppy drive, if you have
one● /dev/dsp is the speaker device
![Page 20: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/20.jpg)
Fun with /dev
● Try this command out:cat /etc/lilo.conf > /dev/dsp
● The sound you will hear is the sound of your /etc/lilo.conf file
● If you don't have /etc/lilo.conf, substitute any other file you do have
● So, /dev/dsp is the speaker, and the speaker is the file /dev/dsp.
![Page 21: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/21.jpg)
More /dev fun
● The most famous device in /dev is the ubiquitous /dev/null
● Anything sent to this device disappears into a black hole, and reappears in another galaxy, much to the puzzlement of the Lizard people of Zorg in the CmfR!&v Galaxy.
![Page 22: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/22.jpg)
/etc● Perhaps the most important to understand● No binaries can be here, per the standard● This is just for configuration files● Examples include /etc/inittab, /etc/fstab,
/etc/passwd, /etc/hosts, /etc/x11,and /etc/opt
![Page 23: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/23.jpg)
/etc 2
● These files are generally text files and can be edited using any text editor: emacs or vi on the command line, or whatever graphical equivalent (e.g. gedit, kate) your desktop offers
![Page 24: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/24.jpg)
/etc/inittab
● Describes what takes place at bootup● Includes the runlevel of the system, and
which processes should be run at each runlevel
● Linux has seven runlevels, from 0-6
![Page 25: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/25.jpg)
/etc/fstab
● Automatically mounts filesystems across multiple drives or partitions, or even from remote systems
● This is where you would place an entry if you added a hard drive
● This file tells the system what drive to access, and where to mount it in your system
![Page 26: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/26.jpg)
/etc/hosts
● This is the famous hosts file, which matches up names with IP addresses
● This is like level 1 DNS. The system looks here first.
● This can be used to block sites by putting their URL in here and mapping it to 127.0.0.1. Great way to get rid of Double-Click.
![Page 27: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/27.jpg)
/etc/passwd
● This is the password file, but it contains more: user name, user password, user ID, group ID, home directory, and shell. It can optionally contain the user's “real name”
● Each user is on its own line● Each user can select the shell they
want to use (most use bash these days)
![Page 28: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/28.jpg)
/etc/opt/● This is a directory for the configuration files
for each system application you install. Each application gets its own subdirectory under /etc/opt/
● System applications are not just for one user, but for anyone logged in to the system
● This is not mandatory, so see the man pages or help for your application
![Page 29: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/29.jpg)
/etc/x11● Configuration directory for x11, which is the
display system for graphical interfaces in Linux
● This can vary with different distros, so again you need to check
● /etc/x11/xorg.conf is the configuration file that lets you specify the resolutions your monitor and graphics card can display, for instance
![Page 30: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/30.jpg)
/home
● This is where the home directories for all of the “ordinary” users are located.
● The exception is root, which has its own home directory, /root/
● Each user gets a directory with their user name: e.g. /home/baracko
● This can contain configuration files for applications that are user-specific
![Page 31: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/31.jpg)
User-specific Configurations
● These files should be in the /home directory, and should begin with a “.” character (i.e. “dot files”)
● If more than one, the files should go into a directory with a name that begins with the “.” character (i.e. “dot directory), and then the files should not begin with a “.”
![Page 32: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/32.jpg)
/home Partition?
● Your home directory is where you would place all of your documents, videos, MP3s, etc.
● It can get fairly large● It is also the stuff you want to back up,
and you don't want to lose● Putting it on its own partition, or even its
own physical drive, is not a bad idea
![Page 33: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/33.jpg)
Reinstalling
● If you have a separate /home partition, you can reinstall (or do a clean upgrade) and still keep not only your data, but many of your file configurations
● Examples are Firefox bookmarks, Thunderbird or Evolution e-mail settings and mail files, etc.
![Page 34: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/34.jpg)
/lib
● This is the location for shared library files that are used by system programs
● Shared library files are equivalent to Windows' “*.dll” files
● The files here are intended to be libraries for programs in /bin and /sbin, i.e. needed to boot the system and run the commands in the root file system
![Page 35: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/35.jpg)
/lib 2
● Also in this directory are kernel modules● Other library locations for other
programs include /usr/lib and /usr/local/lib
● Generally these correspond to where the binary is installed, i.e. a binary in /usr/bin would put a library in /usr/lib, and a binary in /usr/local/bin would put a library in usr/local/lib
![Page 36: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/36.jpg)
/media, /mnt● This is one where there is no general
agreement● Either directory can be a place to mount
removable media (e.g. CD, USB drive, Floppy disk)
● /mnt is the older way, and is still used for temporarily-mounted file systems
● At one time, these devices were often mounted in the root directory, but that is less common today
![Page 37: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/37.jpg)
/media, /mnt 2● Either directory is allowed by the standard● Most current distro versions will mount
these devices automatically● When they are mounted, an entry will go in
the directory● For USB devices, you want to safely
unmount before removing. Current graphical file managers let you do so in the directory (right-click on the device).
![Page 38: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/38.jpg)
/mnt vs. /etc/fstab● The distinction is temporary vs.
permanent● A file system that will be permanently
mounted should get an entry in fstab● A file system mounted temporarily will
get an entry in /mnt when you mount it● Again, everything in Linux is a file or a
directory. If you mount something on the command line, a file is created in /mnt.
![Page 39: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/39.jpg)
/opt
● Intended as a place for “optional” software, i.e. add-on packages that are not part of the default installation
● Intended for use by sysadmins doing something locally, not for software developers creating packages
● Treat this as something deprecated, but possibly still there.
![Page 40: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/40.jpg)
/proc
● Have we mentioned that everything in Linux is a file or a directory?
● Any time a process is created in Linux, a corresponding file goes in here
● Most users have no need to go here, but you're an adult, do what you want
● Gosh, what would happen if you deleted a file here?
![Page 41: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/41.jpg)
/root
● Home directory for the root account● Normally, you don't want to be root, and
you don't want to go here● Give yourself a user account, and use
that for day-to-day stuff. It is much safer that way.
![Page 42: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/42.jpg)
/sbin
● Place for System binaries● One of three such directories
– /sbin– /usr/sbin– /usr/local/sbin
● All three hold utilities used for system administration, and are intended for the root user
![Page 43: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/43.jpg)
/sbin 2● /sbin should have those utilities
essential for booting, restoring, recovering, and/or repairing the system
● Programs used after /usr is known to be mounted (i.e. when there are no problems) go into /usr/sbin
● Locally installed sysadmin programs go in /usr/local/sbin
![Page 44: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/44.jpg)
/tmp● Guess what this one is?● Yes, temporary files are placed here● Assume that anything in this directory
will be deleted whenever the system is booted
● If you want to have your own temporary directory and not lose files at reboot, create one in your home directory, i.e. /home/username/temp
![Page 45: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/45.jpg)
/usr
● Lots of stuff in here● Back in the mists of prehistory, these
were the user directories, equivalent to what are now /home directories
● Now /usr is for shareable data● Not intended for software packages, in
general
![Page 46: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/46.jpg)
/usr/bin
● Contains executable files for many Linux commands
● These are commands that are not part of the core Linux operating system
● They would go in /bin● Examples of commands in here: perl,
python
![Page 47: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/47.jpg)
/usr/include
● General use include files, including header files, for C and C++ programming languages
![Page 48: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/48.jpg)
/usr/lib
● Contains libraries for the C and C++ programming languages
● Object files, libraries, and internal files not intended to be executed directly by users or shell scripts
![Page 49: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/49.jpg)
/usr/local
● For use by System Administrator when installing software locally
● Must not be over-written when system software is updated
● Generally has same subdirectories as /usr
![Page 50: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/50.jpg)
/usr/sbin
● Non-essential standard system binaries, i.e. utilities
● Essential utilities go in /sbin
![Page 51: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/51.jpg)
/usr/share● For read-only architecture independent
data files● Intended to be shared across platforms
(e.g. i386, Alpha, PPC)● Must not change● If the contents are variable, go to /var
e.g. a game file in /usr/share/games must be static. Game play logs go in /var/games.
![Page 52: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/52.jpg)
/usr/share/man
● Primary location for man pages for the system
![Page 53: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/53.jpg)
/usr/src
● Source code is placed here, for reference purposes only
● This includes the source code for the Linux kernel
![Page 54: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/54.jpg)
/var
● This is for files that are expected to be updated and changed
● This includes:– mail directories– print spool– logs– web sites
![Page 55: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/55.jpg)
/var 2
● Because these can be written to constantly, they can grow over time
● On a server, you may want to put /var on its own partition to limit the growth
● This can also prevent the /var directory from bringing down the server by using up all of the drive space.
![Page 56: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/56.jpg)
/var/lock
● Contains lock files● These files prevent two users (or two
programs) from trying to access the same data at the same time
● You may need to delete a lock file from time to time
![Page 57: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/57.jpg)
/var/log
● Contains the log files generated by programs
![Page 58: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/58.jpg)
Fedora Proposal
● You may have noticed a lot of /bin directories in this strcuture
● So did Fedora developers Harald Hoyer and Kay Sievers
● Their proposal is called /usr merge
![Page 59: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/59.jpg)
What is /usr merge?
● Move all executables into /usr/bin● Move all related libraries into either
/usr/lib or /usr/lib64, as needed
![Page 60: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/60.jpg)
Problems with /usr merge
● LSB adheres to FHS● Would break most shell scripts that (for
example) start #!/bin/sh or #!/bin/bash● Would other distros go along? Doe
Fedora care if they do?
![Page 61: Linux Directory Structure](https://reader034.vdocument.in/reader034/viewer/2022052505/555603dad8b42a8a5f8b562a/html5/thumbnails/61.jpg)
Some benefits to /usr merge● Matches what Solaris does already● Simplifies● Easier to run multiple instances of OS
on different machines in a network. This is particularly true with btrfs.