Directory

From LQWiki
Jump to navigation Jump to search

A directory or folder is basically an entry in the Filesystem which allows you to organize your files. You can think of these directories like binders in a filing cabinet. The root directory is the filing cabinet, subdirectories are binders and subdirectories of those directories are plastic wallets, folders and whatnot. There are several commands to manipulate directories including ls, cd, pwd, mkdir, and rmdir. Each user has a home directory where they can store their own files and subdirectories.

In most file systems, directories actually contain not files themselves but lists of files. The name "directory" refers to this characteristic. The actual files are stored elsewhere on the disk. Because the files exist apart from the directories, one can move (with mv) a huge file to another directory quite quickly. It is also possible that the same file is contained in several directories without multiple copies existing (via hard links, see the ln command).

Common top level directories in a standard Linux installation are:

  • / -- The root, there is only one root directory in Linux
  • /bin -- contains essential binary command line tools
  • /boot -- contains files used at boot
  • /dev -- contains special device files
  • /etc -- contains configuration files
  • /home -- contains files belonging to users
  • /lib -- contains essential libraries and kernel modules
  • /proc -- contains process information
  • /sbin -- contains binaries essential for the system administrator
  • /tmp -- contains temporary files
  • /usr -- contains files for shared by all common users
  • /var -- contains variable data, e.g. data that can and will change often

Other often encountered directories are:

  • /cdrom -- mount point for the first CD-ROM drive (not on official FHS directory)
  • /floppy -- mount point for the first floppy drive (not an official FHS directory)
  • /lost+found -- contains broken files, stored here by fsck
  • /sys -- directory where sysfs is mounted, found in distros using recent 2.6 kernels
  • /mnt -- Common mount point for other (non-linux or extra) partitions, removable media (like floppies or cdroms) or other temporary media.
  • /media -- sometimes also found and used for mounting points for removable media.
  • /opt -- contains locally installed (addon) software, similar to /usr/local

The full standard directory structure is specified in the Filesystem Hierarchy Standard.

find out a directories' size

To find out the size of a directory, in this example /tmp, use the command du like this:

du -csh /tmp

See also