Monday, September 28, 2009

The Ubuntu Directory Tree

The directory tree is the hierarchal structure that organizes directories and files in a Unix-based system. As with any organizational chart, there is a hierarchy. In the Unix directory tree, the top order of the hierarchy is the root directory. Underneath the root directory are many other directories, subdirectories, and files that branch out to form the treelike structure. If you look at the Unix directory tree as an actuall tree, think of root as the trunk, the subdirectories under root as the main branches, their subdirectories as smaller branches, and the files as leaves on the tree.

To all Microsoft Windows converts: what Windows calls folders traditional GNU/Linux users call directories. The terms have become interchangeable with folders being a more generic term that is used.

To access a file from the terminal, you need to type in the file’s path. There are two different types of paths you can use to access a file. The first type of path is an absolute path. When you use an absolute path to access a file, it starts in the root folder and makes its way down the tree. For example, if I have a file named Ubuntu saved in my Documents folder, the absolute path for this document would be /home/jeff/Documents/Ubuntu. The slash (/) is the symbol for the root folder. The folder underneath root is the home folder, followed by the current user (in my case, jeff), the Documents folder, and lastly, the file named Ubuntu.

The root directory should not be confused with the root user. The root user is the account that has complete access to all files and directories on a computer or network and is similar to the administrator account in a Microsoft Windows system. When malicious hackers claim that they have “root” on a system, this is what they are talking about; it gives them complete access to the computer or network.

A relative path is the path that is taken when you are not starting from root, /, but are pointing to a file or directory that is within the current working directory. Let’s use our previous example to show a relative path. Suppose we have changed directories to the Documents folder using cd /home/jeff/Documents. Since the current working directory is Documents, the relative path to the file Ubuntu would be Ubuntu.

When navigating the directory structure of Ubuntu, a few special characters may help you on your journey. The character . is used to refer to the current directory, and .. is used to refer to the parent directory, while ~ is used to refer to the current user’s home directory. Also, if you have a filename that contains a space, you will need to use the backslash key (\) before the space. For example, if you have a file named Ubuntu forum, you would need to enter Ubuntu\ forum. The other way to enter a path that contains a space is to enclose the entire filename in quotation marks, for example, “/home/jeff/Documents/Ubuntu forum”.

To work your way around the shell, you must have a good understanding of the Ubuntu directory tree. Understanding which directories are home to certain files is essential to your exploration and mastery of the shell. Listed below, you will find each of the directories under the root directory, along with some of the important files and subdirectories housed therein.

Unless you are doing some heavy-duty configuring of your computer, you may never have to go into some of these directories; however, it is good to know what they are used for so that you don’t accidentally do anything to them or the files they house while you are working in the shell.

There is a difference between the root directory, which is /, and a /root subdirectory. The / directory is the directory where everything branches out from. This is what we consider root. The /root subdirectory is the home folder for the root user. If you have used a different distribution of GNU/Linux in the past, you have been asked to create a root user account. When you installed Ubuntu, no such account was created. This is so that you don’t make a habit of logging in as root and accidentally doing damage to some of the directories mentioned here.

/bin The bin directory contains the commands and utilities that are used most commonly in GNU/Linux like ls, cd, and rm. Since these are executable binary files, the directory is named bin for short.

/boot The boot directory contains the Linux kernel, the bootloader configuration files, and all other files that the system needs in order to start up, or boot.

/dev This is where all of the device files for the system are stored. This directory is rather unique since the files are actually the hardware devices themselves and are treated just like files in that you can read and write them. The label /dev/sda (or /dev/hda) refers to the computer’s first hard drive. SCSI drives are labeled sda, while IDE drives are hda.

/etc Pronounced “et-see,” this directory is home to all of the system-global configuration files for all system users. For example, /etc/passwd contains information that defines all of the user accounts, while /etc/init.d is home to the scripts that run when Ubuntu is booting up.

/home Home is where the files are—the user’s files, that is. This is where documents, music, pictures, videos, and so on, are stored for the individual user. Each user on a computer has his or her directory under /home.

/lib Shared libraries and kernel modules are stored in this directory. The files here are similar to DLL files in Microsoft Windows.

/media The media directory serves as the mount point for all external devices like CDs or DVDs. Devices mounted to the media directory are done automatically.

/mnt The mnt directory is home to temporarily mounted devices like a network shared folder. Mounts to the mnt directory are done manually as opposed to automatically as with the media directory.

/opt The opt directory is used to store software that is not managed by the package manager. These are generally add-on software packages that the user downloads outside of the Ubuntu repositories.

/proc The proc directory is actually a virtual directory that provides a means for the kernel to communicate with the processes running on the computer. Each process that is running is assigned a numbered entry, which we will learn more about shortly.

/sbin This directory contains files and commands like the bin directory does; however, the programs housed in sbin are only used in system administration tasks and require superuser privileges to run them. When you run something using the sudo command, odds are it comes from this directory.

/srv This directory is home to the data files used to run services like HTTP, FTP, or TELNET.

/sys This is another virtual file system that was added for plug-and-play devices. It contains files showing the resources that are allocated to each device on the system.

/tmp The tmp directory stores temporary files. Nothing more, nothing less.

/usr This is the directory that stores everything for the user’s applications such as dictionaries for spell checkers, documentation, and source code files. Subdirectories such as /usr/bin and /usr/lib are here as well for the individual user binaries and libraries.

/var Files that change while the system is running are stored here. Log files, print spools, cache files, and anything else that would be considered a dynamic file would be found in the var directory.

Source of Information : McGraw Hill Osborne Media How to Do Everything Ubuntu

No comments: