≡ Menu

tree command

I’ve already written about conceptual information regarding file system, especially data structure and related terms that help you become a successful system administrator. However I do get few emails asking about /opt directory or /usr or /lost+found directories and their purpose on the system.

Exploring Linux File System Hierarchy

A typical Linux system has the following directories:

=> / : This is the root directory.

=> /bin : This directory contains executable programs which are needed in single user mode and to bring the system up or repair it.

=> /boot : Contains static files for the boot loader. This directory only holds the files which are needed during the boot process.

=> /dev : Special or device files, which refer to physical devices such as hard disk, keyboard, monitor, mouse and modem etc

=> /etc : Contains configuration files which are local to the machine. Some larger software packages, like Apache, can have their own subdirectories below /etc i.e. /etc/httpd. Some important subdirectories in /etc:

  • /etc/skel : When a new user account is created, files from this directory are usually copied into the user’s home directory.
  • /etc/X11 : Configuration files for the X11 window system .
  • /etc/sysconfig : Important configuration file used by SysV script stored in /etc/init.d and /etc.rcX directories
  • /etc/cron.* : cron daemon configuration files which is used to execute scheduled commands

=> /home : Your sweet home to store data and other files. However in large installation yhe structure of /home directory depends on local administration decisions.

=> /lib : This directory should hold those shared libraries that are necessary to boot the system and to run the commands in the root filesystem.

=> /lib64 : 64 bit shared libraries that are necessary to boot the system and to run the commands in the root filesystem.

=> /mnt : This directory contains mount points for temporarily mounted filesystems

=> /opt : This directory should contain add-on packages such as install download firefox or static files

=> /proc : This is a mount point for the proc filesystem, which provides information about running processes and the kernel.

=> /root : This directory is usually the home directory for the root user.

=> /sbin : Like /bin, this directory holds commands needed to boot the system, but which are usually not executed by normal users, root / admin user specific commands goes here.

=> /tmp : This directory contains temporary files which may be deleted with no notice, such as by a regular job or at system boot up.

=> /usr : This directory is usually mounted from a separate partition. It should hold only sharable, read-only data, so that it can be mounted by various machines run ning Linux (useful for diskless client or multiuser Linux network such as university network). Programs, libraries, documentation etc. for all user-related programs.

=> /var : This directory contains files which may change in size, such as spool and log files.

=> /lost+found : Every partition has a lost+found in its upper directory. Files that were saved during failures are here, for e.g ext2/ext3 fsck recovery.

How do I get information about each and every directory from command prompt?

Above list just summaries important directories, you can get list by entering the following command to display description of the file system hierarchy (works under all other UNIX like oses such as HP-UX ):
$ man hier

List contents of directories in a tree-like format

ls command is basic tool for exploring file system. You can use tree command for a recursive directory listing. It produces a depth indented listing of files.
$ tree
Output:

|-- DIR_COLORS
|-- DIR_COLORS.xterm
|-- Muttrc
|-- Muttrc.local
|-- NetworkManager
|-- X11
|   |-- Xmodmap
|   |-- Xresources
|   |-- applnk
|   |-- fs
|   |   `-- config
.....
.......
..

find is another useful command to search for files in a directory hierarchy.

Further readings:

Understanding UNIX / Linux filesystem directories

You use DNS (domain name system) to translate between domain names and IP addresses.

Similarly files are referred by file name, not by inode number. So what is the purpose of a directory? You can groups the files according to your usage. For example all configuration files are stored under /etc directory. So the purpose of a directory is to make a connection between file names and their associated inode number. Inside every directory you will find out two directories . (current directory) and .. (pointer to previous directory i.e. the directory immediately above the one I am in now). The .. appears in every directory except for the root directory.

Directory

A directory contained inside another directory is called a subdirectory. At the end the directories form a tree structure. Use tree command to see directory tree structure:
$ tree /etc | less
Again a directory has an inode just like a file. It is a specially formatted file containing records which associate each name with an inode number. Please note the following limitation of directories under ext2/3 file system:

  • There is an upper limit of 32768 subdirectories in a single directory.
  • There is a "soft" upper limit of about 10-15k files in a single directory

However according to official documentation of ext2/3 file system points that “Using a hashed directory index (which is under development) allows 100k-1M+ files in a single directory without performance problems'. Here are my two favorite alias commands related to directory :
$ alias ..='cd ..'
alias d='ls -l | grep -E "^d"'


Well I'm sure all of you know the basic commands related to directories and files managment. Click above (or here) to see summery of all basic commands related to directories and files managment. See interesting discussion about soft links and directories. This is 6th part of "Understanding UNIX/Linux file system, continue reading rest of the Understanding Linux file system series (this is part IV):

  • Part I - Understanding Linux superblock
  • Part II - Understanding Linux superblock
  • Part III - An example of Surviving a Linux Filesystem Failures
  • Part IV - Understanding filesystem Inodes
  • Part V - Understanding filesystem directories
  • Part VI - Understanding UNIX/Linux symbolic (soft) and hard links
  • Part VII - Why isn't it possible to create hard links across file system boundaries?