Unix File System Organization
Every Unix has a similar organization of the file system. a
listing of the root directory ("/") will show a list of
directories similar to those shown below:
|
|
mark@platypus:~> cd /
mark@platypus:/> ls -F
bin/ dev/ initrd/ mnt/ root/ scratch_net/ tmp/
boot/ etc/ lib/ opt/ sbin/ software/ usr/
data/ home/ lost+found/ proc/ scratch/ sys/ var/
mark@platypus:/>
|
bin - contains system binary executables
boot - contains files necessary for the system to boot up
dev - contains device files which function as an interface to the
various hardware drivers. These will vary greatly depending on
the version of Unix.
etc - contains system configuration settings
home - contains the user's home directories
lib - contains system libraries
lost+found - ignore
mnt - used to hold mount point directories for removable storage
opt -
proc - contains a virtual file system which holds information about
running processes and the state of the system.
root - the root (administrator) user's home directory
sbin - contains static binary executables needed for the system
tmp - temporary directory used by many applications
usr - contains binaries, data and settings for various applications.
The structure of /usr mimics the root file system organization.
var - stores logs, data for services and other transient data.
The actual organization for each version will be slightly different
depending on the version of Unix but the general layout will be
similar.
More information...
Your home directory
The home directory is unique for each user account on the system.
This directory can be managed completely by the user and will not
be accessible to other users. All user specific settings for
various applications are stored in the home directory usually in hidden
files. It is intended for the user to store their personal data
files in this location.
When a user logs into a Unix system their shell will have its
working directory set to the home directory by default.
The home directory can be referenced by the "~"
character.
|
|
mark@platypus:~> echo $HOME
/home/mark
mark@platypus:~> cd ~
mark@platypus:~> pwd
/home/mark
mark@platypus:~>
|
Symbolic links
Symbolic links are part of the Unix file system. They function
merely as a pointer to another file or directory on the file
system.
Symbolic links have not permissions of their own. The target file
or directory permissions will determine the access priveledges.
The link itself has a name on the file system which does not have
to be the same as the target it points to. For all practical
purposes the link can be operated on with all unix commands just
as any other file. Deleting a symbolic link will only delete the
link, not the file that the link points to.
Below is a long listing of the file ~/.cshrc which is a symbolic
link.
|
|
mark@platypus:~> ls -l .cshrc
lrwxrwxrwx 1 mark users 25 2004-10-29 13:43 .cshrc -> /mnt/homes/00links/.cshrc
mark@platypus:~>
|
Symbolic links are created with the ln command with
the "-s" option.:
|
|
tuckerm@apollo:/mnt/homes/CLASSES/MET489/lab04> ln -s thing.txt one.dat
tuckerm@apollo:/mnt/homes/CLASSES/MET489/lab04> ls -l thing.txt one.dat
lrwxrwxrwx 1 tuckerm tuckerm 9 Jan 26 15:48 one.dat -> thing.txt
-rw-rw-r-- 1 tuckerm tuckerm 57 Jan 26 15:47 thing.txt
tuckerm@apollo:/mnt/homes/CLASSES/MET489/lab04>
|
The ln command takes two arguments: the first is the name of the
target file or directory that the link will point to. The second
argument is the name of the link.
You must use the "-s" option to create symbolic links. ln
by itself will create a hard link which creates a second name for
the file. These can be very difficult to manage and generally
should not be created unless you know what you are doing.
Hidden Files
In Unix files whose names begin with the dot character, ".", are
considered hidden. Most commands will not display these files by
default. The ls command with the "-a" option will
display all hidden files.
|
|
tuckerm@apollo:~> ls
BG/ TEST/ files/ mcidas/ test/
Desktop/ btvnws_id_dsa.pub fish/ public_html/ unix/
GNUstep/ docs/ foo/ scripts/ web/
OpenOffice.org1.1/ dotfiles/ html/ src/ z-drive@
PERL/ elisp/ mail/ start-vnc.sh*
tuckerm@apollo:~> ls -a
./ .gconfd/ .mysql_history .xscreensaver
../ .gimp-1.2/ .nautilus/ .xsession*
.ICEauthority .gimp-1.3/ .nedit/ .xsession-errors
.Trash/ .gkrellm2/ .netscape/ .xvpics/
.Xauthority .gnome/ .netscape6/ BG/
.Xresources .gnome2/ .nfs074bc1b600000005 Desktop/
.acrobat/ .gnome2_private/ .phoenix/ GNUstep/
.adobe/ .gstreamer-0.8/ .pinerc OpenOffice.org1.1/
.bash_history .gtkrc-1.2-gnome2 .profile PERL/
.bash_profile@ .gxine/ .qt/ TEST/
.bashrc@ .history .recently-used btvnws_id_dsa.pub
.cache/ .home_pw .rhosts docs/
.config/ .htaccess .sane/ dotfiles/
.cshrc@ .icons/ .screen/ elisp/
.dmrc .java/ .screenrc files/
.elinks/ .kde/ .scribus/ fish/
.emacs .kderc .sh_history foo/
.emacs.d/ .links/ .shrc html/
.emacs.mark .local/ .ssh/ mail/
.emacs_backups/ .login_conf .sversionrc* mcidas/
.esd_auth .mail_aliases .themes/ public_html/
.eshell/ .mailcap .thumbnails/ scripts/
.fishsrv.pl .mailrc .tramp_history src/
.fluxbox/ .mcidasrc@ .user.cshrc start-vnc.sh*
.fonts.cache-1 .mcop/ .vmware/ test/
.fonts.conf .mcoprc .vnc/ unix/
.forward .mctmp/ .xcdroast/ web/
.fte-history .metacity/ .xfce4/ z-drive@
.fullcircle/ .metapps/ .xine/
.gaim/ .mime.types .xinitrc@
.gconf/ .mozilla/ .xmms/
tuckerm@apollo:~>
|
A coulple of the hidden files worth mentioning are the .cshrc, or
.tcshrc files found in the user's home directory. .cshrc sets the
default environment variables that particular user's shell. You
may view the contents of .cshrc with the command:
less ~/.cshrc
In out lab configuration this file contains many setenv commands
and some conditionals that determine how the shell should be
configured.
The "." and ".." Directories
Two special hidden directories listed within each directory are
named "." and "..". The "." directory refers to the working
directory.
|
|
tuckerm@apollo:~> ls
BG/ TEST/ files/ mcidas/ test/
Desktop/ btvnws_id_dsa.pub fish/ public_html/ unix/
GNUstep/ docs/ foo/ scripts/ web/
OpenOffice.org1.1/ dotfiles/ html/ src/ z-drive@
PERL/ elisp/ mail/ start-vnc.sh*
tuckerm@apollo:~> ls .
BG/ TEST/ files/ mcidas/ test/
Desktop/ btvnws_id_dsa.pub fish/ public_html/ unix/
GNUstep/ docs/ foo/ scripts/ web/
OpenOffice.org1.1/ dotfiles/ html/ src/ z-drive@
PERL/ elisp/ mail/ start-vnc.sh*
tuckerm@apollo:~>
|
Items within the working directory can be specified explicitly with
a relative path as shown below:
|
|
tuckerm@apollo:~> ls -lh start-vnc.sh
-rwxr-x--- 1 tuckerm tuckerm 777 Nov 7 14:09 start-vnc.sh*
tuckerm@apollo:~> ls -lh ./start-vnc.sh
-rwxr-x--- 1 tuckerm tuckerm 777 Nov 7 14:09 ./start-vnc.sh*
tuckerm@apollo:~>
|
The ".." directory always refers to the directory above the
working directory. An example of how this can be used:
|
|
tuckerm@apollo:~> pwd
/mnt/homes/tuckerm
tuckerm@apollo:~> cd ..
tuckerm@apollo:/mnt/homes> pwd
/mnt/homes
tuckerm@apollo:/mnt/homes> cd ../..
tuckerm@apollo:/> pwd
/
tuckerm@apollo:/>
|
Local Versus Remote File Systems
Unix has the capability of accessing data on other networked
hosts. The files and directories stored on another Unix host are
referred to as a remote file system. Files and directories
physically located on the same machine as the user logged in on
are considered local. In normal use the difference is seldom
noticed. When dealing with large volumes of data a remote file
system will often be slower to work with.
The df command
The df command is used to report how much of the file
systems are in use. With no arguments the it will output the
usage statistics for each file system currently mounted on the
host. An example:
|
|
mark@platypus:~> df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda1 4883572 4583848 299724 94% /
/dev/hda2 4883604 1427548 3456056 30% /mnt/upgrade
/dev/hda6 28329724 2116336 26213388 8% /software
/dev/hdb1 120050028 72931572 47118456 61% /data
omega:/var/data/ldm 186754074 81406970 90406780 48% /mnt/data
vertex:/export/homes 195352432 41565736 153786696 22% /mnt/homes
vertex:/export/metadmin
48844104 18142012 30702092 38% /mnt/metadmin
vertex:/export/arch 195263012 77880876 117382136 40% /mnt/arch
cluster01:/scratch_net
195352432 87537420 107815012 45% /scratch_net
/dev/sda1 127716 45754 81962 36% /mnt/usbkey
mark@platypus:~>
|
The first column of output lists the device that the file system
is on. This can be a local file system (the items beginning with
/dev/) or a remove file system. Remote filesystems will list the
name or network address of the host where they are served from.
The second column lists the total size of the file system. The
third column is a total of the disk space being used by files on
the file system. The fourth column displays how much space is
available or free on the file system. The fifth column shows the
used disk space as a percentage value. The final column shows the
directory where the file system is mounted, or attached, to the
Unix file system.
df can also take an argument of which file systems to
report on rather than listing all file systems:
|
|
mark@platypus:~> df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 4.7G 4.4G 293M 94% /
mark@platypus:~> df -h /mnt/data
Filesystem Size Used Avail Use% Mounted on
omega:/var/data/ldm 179G 78G 87G 48% /mnt/data
mark@platypus:~>
|
Below are a few commonly used options (on Linux) which can modify
the output of df:
-k, --kilobytes
Print sizes in 1024-byte blocks.
-h, --human-readable
Append a size letter such as M for binary megabytes
(`mebibytes') to each size.
-l, --local
Limit the output to local filesystems only. (New
in fileutils-4.0.)
The du command
The du command is used to report approximately how
much disk space a directory uses. With no arguments
du will report usage for the current directory.
Perhaps more commonly a directory is specified.
|
|
mark@platypus:~> du ~/temp
4 /home/mark/temp/usr/lib/menu
4 /home/mark/temp/usr/lib
396 /home/mark/temp/usr/X11R6/bin
4 /home/mark/temp/usr/X11R6/man/man1
4 /home/mark/temp/usr/X11R6/man
400 /home/mark/temp/usr/X11R6
24 /home/mark/temp/usr/share/doc/xfishtank
24 /home/mark/temp/usr/share/doc
24 /home/mark/temp/usr/share
428 /home/mark/temp/usr
654 /home/mark/temp/TclTutor
405 /home/mark/temp/WRF_NCL
1638 /home/mark/temp
mark@platypus:~>
|
Note that usage for each subdirectory will be listed. A
total for the specified directory will be listed last in the
output. The summary output can be specified by adding the "-s"
option to the command:
|
|
mark@platypus:~> du -s ~/temp
1638 /home/mark/temp
mark@platypus:~>
|
See the man page for more options to modify the output from
du.
The mount and umount commands
Unix does not use drive letters or names to identify file
systems. New storage devices must be attached to the Unix file
system with the mount command. mount will
"attach", or mount, the device to a directory on the
file system. This directory is called the "mount point"
and must exist before attempting to mount a file system.
Typically only the super-user (AKA: administrator, root) has the
ability to mount file systems. Below is the command an
administrator would use to mount a cdrom on a linux host:
|
|
root@vertex:~# mount -t iso9660 /dev/cdrom -o ro /mnt/cdrom
root@vertex:~#
|
Some hosts have the system configured so that a user can mount
certain file systems as defined by the file /etc/fstab. (The name
and location of this file may vary depending on the version of
Unix). In our lab the command to mount a cdrom would be as follows:
|
|
tuckerm@annex05:~> df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 4.7G 3.0G 1.8G 63% /
/dev/hda2 4.7G 33M 4.7G 1% /mnt/upgrade
/dev/hda6 28G 13G 15G 46% /software
tuckerm@annex05:~> mount /mnt/cdrom
tuckerm@annex05:~> df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 4.7G 3.0G 1.8G 63% /
/dev/hda2 4.7G 33M 4.7G 1% /mnt/upgrade
/dev/hda6 28G 13G 15G 46% /software
/dev/hdc 696M 696M 0 100% /mnt/cdrom
tuckerm@annex05:~>
|
The mount command only needs the argument of what
directory to mount. To remove a mounted file system the
umount command is used:
|
|
tuckerm@annex05:~> df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 4.7G 3.0G 1.8G 63% /
/dev/hda2 4.7G 33M 4.7G 1% /mnt/upgrade
/dev/hda6 28G 13G 15G 46% /software
/dev/hdc 696M 696M 0 100% /mnt/cdrom
tuckerm@annex05:~> umount /mnt/cdrom
tuckerm@annex05:~> df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 4.7G 3.0G 1.8G 63% /
/dev/hda2 4.7G 33M 4.7G 1% /mnt/upgrade
/dev/hda6 28G 13G 15G 46% /software
tuckerm@annex05:~>
|