Notes: Unix Lab 04

  1. Unix File System Organization
  2. Your home directory
  3. Symbolic links
  4. Hidden files
  5. The "." and ".." directories
  6. Local versus remote file systems
  7. The du command
  8. The df command
  9. The mount and umount commands
  1. 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:
     
    [loriotg@l-dl-asac31601 xcd] cd /
    [loriotg@l-dl-asac31601 /] ls -F
    bin/	etc/		 lib32/       opt/   selinux/	usr/
    boot/	home/		 lib64/       proc/  software/	var/
    cdrom/	initrd.img@	 lost+found/  root/  srv/	vmlinuz@
    data/	initrd.img.old@  media/       run/   sys/	vmlinuz.old@
    dev/	lib/		 mnt/	      sbin/  tmp/
    [loriotg@l-dl-asac31601 /] 
     

    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 (often but not at LSC/ATM Linux network)
    mnt/homes - contains the user's home directories at the LSC/ATM network)
    lib  - contains system libraries for 32- bit applications
    lib64  - contains system libraries for 64- bit applications
    lost+found  - ignore
    mnt  - used to hold mount point directories for removable storage 
    opt  - contains optional applications 
    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
    software - contains site-specific software
    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...

  2. 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.
     
    [loriotg@l-dl-asac31601 /] echo $HOME
    /mnt/homes/loriotg
    [loriotg@l-dl-asac31601 /] cd 
    [loriotg@l-dl-asac31601 ~] pwd
    /mnt/homes/loriotg
    [loriotg@l-dl-asac31601 ~] 
     

  3. 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 ~/.bashrc which is a symbolic link.
     
    [loriotg@l-dl-asac31601 ~] ls -la .bashrc
    lrwxrwxrwx 1 root root 26 Jul 15  2008 .bashrc -> /mnt/homes/00links/.bashrc*
    [loriotg@l-dl-asac31601 ~] 
     

    Symbolic links are created with the ln command with the "-s" option.:
     
    [loriotg@l-dl-asac31601 ~] ln -s /mnt/homes/CLASSES/CIS2101 ./unix-class
    [loriotg@l-dl-asac31601 ~] ls -l unix-class
    lrwxrwxrwx 1 loriotg loriotg 26 Sep 17 20:05 unix-class -> /mnt/homes/CLASSES/CIS2101/
    [loriotg@l-dl-asac31601 ~]
     

    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.

  4. 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:~>
     

    An important hidden file worth mentioning is the .bashrc file found in the user's home directory. .basrc sets the default environment variables for that particular user's shell. You may view the contents of .bashrc with the command:

    less ~/.bashrc
    In our lab configuration this file contains many export commands and some conditionals that determine how the shell should be configured.

  5. 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:/>
     

  6. 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.

  7. 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:
     
    [loriotg@l-dl-asac31601 ~] df
    Filesystem                 1K-blocks       Used  Available Use% Mounted on
    /dev/sda5                   19228276    8672928    9578600  48% /
    udev                         1523544          4    1523540   1% /dev
    tmpfs                         612940        820     612120   1% /run
    none                            5120          0       5120   0% /run/lock
    none                         1532344        372    1531972   1% /run/shm
    /dev/sda7                   96924872     192176   91809128   1% /data
    vertex:/export/software64 1865855488 1384274432  481581056  75% /software
    vertex:/export/homes      1865855488 1384274432  481581056  75% /mnt/homes
    vertex:/export/metadmin   1865855488 1384274432  481581056  75% /mnt/metadmin
    vertex:/export/facdata    1865855488 1384274432  481581056  75% /mnt/facdata
    vortex00:/export/data1    3612428800 2385511424 1043416576  70% /mnt/data1
    vortex00:/export/data4    3612428800 2385511424 1043416576  70% /mnt/data4
    omega:/var/data/ldm        442382848  236278784  183632384  57% /mnt/data
    vortex00:/export/vortex2  3612428800 2385511424 1043416576  70% /mnt/vortex2
    vertex:/export/arch       1865855488 1384274432  481581056  75% /mnt/arch
    vortex00:/export/data5    3612428800 2385511424 1043416576  70% /mnt/data5
    vortex00:/export/wrfdata  3612428800 2385511424 1043416576  70% /mnt/wrfdata
    vortex00:/export/data3    3612428800 2385511424 1043416576  70% /mnt/data3
    vortex00:/export/data2    3612428800 2385511424 1043416576  70% /mnt/data2
    vortex00:/export/data6    3612428800 2385511424 1043416576  70% /mnt/data6
    vortex00:/export/data7    3612428800 2385511424 1043416576  70% /mnt/data7
    [loriotg@l-dl-asac31601 ~] 
     

    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 remote 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. Here is a list of the current file system (with the human-readable option):
     
    [loriotg@l-dl-asac31601 ~] df -h .
    Filesystem            Size  Used Avail Use% Mounted on
    vertex:/export/homes  1.8T  1.3T  460G  75% /mnt/homes
    [loriotg@l-dl-asac31601 ~] 
     

    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.)
        

  8. 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.
     
    [loriotg@l-dl-asac31601 ~] du ~/temp/RIP4
    2238	/mnt/homes/loriotg/temp/RIP4/Doc
    13880	/mnt/homes/loriotg/temp/RIP4/src
    65	/mnt/homes/loriotg/temp/RIP4/sample_infiles
    17700	/mnt/homes/loriotg/temp/RIP4
    [loriotg@l-dl-asac31601 ~] 
     

    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:
     
    [loriotg@l-dl-asac31601 ~] du -s ~/temp/RIP4
    17700	/mnt/homes/loriotg/temp/RIP4
    [loriotg@l-dl-asac31601 ~] 
     

    See the man page for more options to modify the output from du.

  9. 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:~>