Linux Directory Structure

8,271 views

Published on

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.

Published in: Technology
4 Comments
5 Likes
Statistics
Notes
No Downloads
Views
Total views
8,271
On SlideShare
0
From Embeds
0
Number of Embeds
1,014
Actions
Shares
0
Downloads
366
Comments
4
Likes
5
Embeds 0
No embeds

No notes for slide

Linux Directory Structure

  1. 1. Linux Directory Structure Kevin B. O’Brien Washtenaw Linux Users Group http://www.lugwash.org
  2. 2. 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
  3. 3. Drives 1● Linux derives from Unix● Different from Windows● Windows starts with drives, which are explicit – C: – D:
  4. 4. 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)
  5. 5. 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.
  6. 6. Root 2● For our purposes, we will refer to root as the top of the file structure in this presentation.
  7. 7. Comparison Linux Windows /home C: Disk /home/data Partitions D: /root /var E: •/boot •/bin F: •etc.
  8. 8. 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 dont mean much. You can even mount a separate physical drive under a directory that is on another drive.
  9. 9. 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.
  10. 10. 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.
  11. 11. 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
  12. 12. 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
  13. 13. 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
  14. 14. /● 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
  15. 15. /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
  16. 16. /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
  17. 17. /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
  18. 18. /dev● Kinda-sorta an equivalent to a mashup of the Device Manager and C:WindowsSystem 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.
  19. 19. /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
  20. 20. 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 dont 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.
  21. 21. 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.
  22. 22. /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
  23. 23. /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
  24. 24. /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
  25. 25. /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
  26. 26. /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.
  27. 27. /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 users “real name”● Each user is on its own line● Each user can select the shell they want to use (most use bash these days)
  28. 28. /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
  29. 29. /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
  30. 30. /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
  31. 31. 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 “.”
  32. 32. /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 dont want to lose● Putting it on its own partition, or even its own physical drive, is not a bad idea
  33. 33. 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.
  34. 34. /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
  35. 35. /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
  36. 36. /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
  37. 37. /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).
  38. 38. /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.
  39. 39. /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.
  40. 40. /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 youre an adult, do what you want● Gosh, what would happen if you deleted a file here?
  41. 41. /root● Home directory for the root account● Normally, you dont want to be root, and you dont want to go here● Give yourself a user account, and use that for day-to-day stuff. It is much safer that way.
  42. 42. /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
  43. 43. /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
  44. 44. /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
  45. 45. /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
  46. 46. /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
  47. 47. /usr/include● General use include files, including header files, for C and C++ programming languages
  48. 48. /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
  49. 49. /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
  50. 50. /usr/sbin● Non-essential standard system binaries, i.e. utilities● Essential utilities go in /sbin
  51. 51. /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.
  52. 52. /usr/share/man● Primary location for man pages for the system
  53. 53. /usr/src● Source code is placed here, for reference purposes only● This includes the source code for the Linux kernel
  54. 54. /var● This is for files that are expected to be updated and changed● This includes: – mail directories – print spool – logs – web sites
  55. 55. /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.
  56. 56. /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
  57. 57. /var/log● Contains the log files generated by programs
  58. 58. 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
  59. 59. What is /usr merge?● Move all executables into /usr/bin● Move all related libraries into either /usr/lib or /usr/lib64, as needed
  60. 60. 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?
  61. 61. 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.

×