Linux Topic
   >  Why use the Command Line?
   >  Common Linux Commands
   >  Directory Structure
   >  Using Regular Expressions
   >  $STDIN; $STDOUT and $STDERR
   >  IO Redirection and Pipes

 

The Linux Directory Structure

The Linux Directory Structure

When using the command line, you need to be a little more aware of the general Linux directory structure - as you'll doubtless be moving around it to find things. The highest directory in the Linux tree structure is called the Root Directory (/). Directly under this are a number of important directories:

DirectoryMain Contents
/binThis directory contains the binaries for the minimal Linux O/S. Without this, Linux won't even boot
/bootBoot files for the O/S (-the grub loader sits under here). Without this directory, the O/S won't boot. Normally, people install this directory into it's own filesystem (-sized 50Mb+)
/devThe devices directory : any attached devices such as disc drives, USB drives, etc will be listed under this (-normally in the format /dev/sd<id>)
/etcContains most of the configuration files for the Linux system: these are normally text and are editable (-with extreme caution)
/homeAll the users directories sit under this (-for example /home/user1). Normally, people install this directory into it's own filesystem (-sized as big as they can get it!)
/libContains the Linux (code) libraries
/lib32Normally this is a symbolic link to /lib on 32 bit systems
/lib64Normally this is a symbolic link to /lib on 64 bit systems
/optHolds any application that can be run by Linux users (-rather than the Linux kernel itself)
/sbinContains Linux executables that are not essential at boot time: normally administration tools
/sysHolds system resources
/tmpContains temporary files created by the system or the users: normally the contents are deleted on reboot
/usrContains user installed applications (applications)
/varContains files written to by the Linux system (-for example, logs)

In general, you should stay away from all of these except the /home and /tmp directories, unless you are sure what you are doing: if you mess up any system files, your system may become unstable or fail to boot. If you do need to update anything in these directories, always make a backup of the file before you edit it - just in case!


Using Absolute Paths

You can find your way around the above structure with a minimum of basic commands. The simplest way to do this is using Absolute Paths: these specify the entire path to the directory in question starting at the Root Directory (/). Linux uses the forward slash (/) character to separate directories. Here are some examples of absolute paths:

Absolute Path
/
/var/tmp
/home/fredb/Documents/home

Here are some examples of absolute directories in use:

$ cd /
$ pwd
/
$ cd /home/myuser/scripts
$ pwd
/home/myuser/scripts
$ more /var/tmp/mylog
$

Using Relative Paths

Instead of specifying the absolute path in Linux, you can also use Relative Paths which define the directory that you want relative to the directory you are currently in. For relative paths, Linux defines various shorthand symbols that define your starting point:

ShorthandPoints To
.(A single dot) The current directory
..(Two dots) The directory above the current directory
~(Tilde) A reference to a user directory under /home. For example ~fredb would point to /home/fredb

To check the current directory, use the pwd command:

$ pwd
/home/user2/tmp

These symbols can be combined together (-separated by the forward slash character) for greater power. Here are some examples and what they actually point to:

ShorthandPoints To
../..The directory above the directory above the current directory (-i.e. two levels above the current directory)
../tmpThe sub directory called tmp within the directory above the current directory
~/fredb/..This would point to /home itself
./tmpThe directory called tmpthat is immediately below the current one
./tmp/..A long way of saying the current directory (!!)

Here are some examples of relative directories in use:

$ cd ~fredb
$ pwd
/home/fredb
$ cd ../user2
$ pwd
/home/user2
$ cd tmp
$ pwd
/home/user2/tmp

The Linux /home Structure

Linux structures it's /home directory (-under which all user data is stored) in a defined manner. Each user has their own subdirectory under /home, named for the user (-e.g. /home/fredb). Under this you'll find the following subdirectories:

DirectoryMain Contents
DesktopThis directory contains any shortcuts or files dragged to the GUI desktop
DocumentsThis directory is the default one for documents or text files
DownloadsThis directory is the default one for files downloaded from the web
MusicThis directory is the default one for music files downloaded from the web or uploaded from a CD
PicturesThis directory is the default one for image files or photos uploaded from a digital camera
PublicThis directory holds any files you want other users to be able to see
TemplatesThis directory holds any desktop publishing files and "blueprint" files used for creating files in the same format
VideosThis directory is the default one for video files downloaded from the web or uploaded from a DVD

HomeSite IndexDesktop GuideServer GuideHints and TipsHardware CornerVideo SectionContact Us

 sitelock verified Firefox Download Button