Linux Directories

Linux Directories

As you probably already know from working in graphics mode, in Linux the directories (aka "folders") use the slash (/) as a separator (Windows uses backslash (\) ). In other words it works just like websites or ftp servers.

Any directory which starts with a slash, such as "/usr/bin", means it is an "absolute" name - the name specifies the entire sequence of directories from the "root" directory (/) up to the specific directory being requested (bin). Thus, it doesn’t matter which directory is the "current" directory when you specify that name, it will always point to the /usr/bin directory.

On the other hand a directory which does not start with a slash is relative to the current directory. For example the directory "bin" will point to different directories depending on whether you are in the root directory (in which case it will point to "/bin"), in the "/usr" directory (in which case it will point to /usr/bin) or in the "/usr/local" directory (in which case it will point to /usr/local/bin).

The same applies to files - if you specify "file.txt" it is assumed to be in the current directory, while if you specify "/tmp/file.txt" it will always point to "file.txt" in the temporary directory.

Two special directory names are the current directory, represented by a single period (.) and the parent directory, represented by a double period (..). Thus, if you are in the /home/sandbox directory and type in ls .., it will list the contents of the parent directory, which is /home.

Some System Directories

Below is a list of some common directories that are found in Linux and Unix systems, and what they are used for.

/
This is the root directory, inside which all other directories reside
This is similar to the root directory of a drive in Windows (C:\),
except that in Linux even different hard disks reside within this root.
/bin
This stands for "binary", and contains program (executable) files.
This (and other "bin" directories) is where commands such as "ls" can be
found.
In Windows, the c:\windows\commands holds some of command-line programs, but others are scattered in various other directories.
/dev
This stands for "devices". It contains a number of special pseudo-files that are used to access the physical hardware that make up, or are connected to, your computer. For example the parallel-port would be a file called "lp0" in this directory, while the hard disk would be "hda", and its first partition would be "hda0".
Windows/DOS uses a similar method, however in Windows these are not in any particular directory. Devices have names like LPT1, COM1 or CON - any time you try to access a file with that name from any directory, you will get the parallel printer, serial port or console, respectively.
/etc
This is where (almost) all system-wide configuration information is stored. Almost all configuration information is stored in text files, so you can go into this directory and have a look around with a text viewer if you like. Some of the files are quite cryptic though.
There is no equivalent in Windows, where configuration data can be stored anywhere, including the registry, INI files and other data files in various directories.
/home
This is where users’ home directories are usually found. Thus, if you created a user called "sandbox", there will be a directory with the same name in this directory, which will be that user’s home directory.
The nearest equivalent in Windows is c:\windows\profiles, where some user-specific data is held, together with c:\My Documents, where user-created documents go. However other data can be written in many other directories.
/lib
This is where the library files are found. Libraries are files containing reusable functions and routines for programs to use.
There is no equivalent in Windows/DOS.
/mnt
This is where storage devices other than the hard disks are mounted. This directory usually contains subdirectories called "cdrom", "floppy", etc., which - when these devices are mounted - show the contents of the CD-ROM or floppy disk respectively. Your Windows drives may also be automatically mounted in this directory.
There is no equivalent in Windows/DOS.
/opt
This is where optional components of the system are installed. Products such as KDE, Gnome and Oracle may be installed into this directory.
The nearest thing in Windows is the c:\Program Files directory.
/tmp
This is a temporary directory. All files placed in here will automatically be deleted eventually.
The equivalent in Windows/DOS is c:\windows\temp.
/usr
Contains a copy of most of the directories in the root. For example, there is a "bin" directory containing programs, a "lib" directory containing libraries, etc. Usually, "core" Linux files are contained in the root direcories, while "non-core" files are in the "/usr" subdirectories.
There is no equivalent in Windows/DOS.
/var
Stands for "various". Among the files stored here are the system log files, spool files and other data files.
There is no equivalent in Windows/DOS.

Directory Commands

Here are the most common commands to work with directories.

mkdir new-directory-name
Creates a new directory, "new-directory-name"
cd directory-name
Goes to the specified directory, making it the "current directory"
cd
When you don’t give a directory name, goes to your "home" directory.
rmdir directory-name
Removes (deletes) the directory. As a safety measure, the directory must be
empty before it can be deleted.
pwd
Displays the current directory.
ls directory-name
Lists the contents of the directory.

The following sequence of commands (and results) demonstrates
the above commands. For clarity, the prompt has been coloured grey.
After displaying the directory contents, a new directory called "testing" is
created and the directory listed again. Then we go into the new directory,
display the current directory, go back to the "home" directory, and display
the current directory again. Finally the "testing" directory is removed.

sandbox@laptop:~ > ls
KDesktop  public_html 
sandbox@laptop:~ > mkdir testing
sandbox@laptop:~ > ls
KDesktop  public_html  testing
sandbox@laptop:~ > cd testing
sandbox@laptop:~/testing > pwd
/home/sandbox/testing
sandbox@laptop:~/testing > cd
sandbox@laptop:~ > pwd
/home/sandbox
sandbox@laptop:~ > rmdir testing
sandbox@laptop:~ >