The File System. (continued)




  1. Links.
    When the file name is too long or inconvenient you can create a link to the file. A symbolic link is used to create a new path to another file or directory. The general format of the link command :

    $ln -s source target
    1. An example of a link:
      $ ls -al Xstuff/rolo/mrolo/rolo
      -rwxr-xr-x   1 ask      staff    30 Dec  5 1994  Xstuff/rolo/mrolo/rolo
      $ ln  -s Xstuff/rolo/mrolo/rolo dex
      $ ls -al dex
      lrwxrwxrwx   1 ask      staff    22 Sep  5 07:50 dex ->Xstuff/rolo/mrolo/rolo
      
    2. Soft or symbolic link.
      $ cat fileX
      This is file X
      
      $ ln -s fileX fileY
      
      $ ls -al
      total 24
      drwxr-xr-x   2 ask  staff     512 Jan 27 07:27 .
      drwxr-xr-x   6 ask  staff     512 Jan 27 07:25 ..
      -rw-r--r--   1 ask  staff      15 Jan 27 07:26 fileX
      lrwxrwxrwx   1 ask  staff       5 Jan 27 07:27 fileY -> fileX
      
      $ cat fileY
      This is file X
      $ rm fileX
      $ cat fileY
      cat: cannot open fileY
      
    3. Hard Link
      $ cat fileX
      This is file X
      
      $ ln fileX fileY
      $ ls -il
      total 16
       8262 -rw-r--r--   2 ask  staff      15 Jan 27 07:32 fileX
       8262 -rw-r--r--   2 ask  staff      15 Jan 27 07:32 fileY
      
      $ cat fileY
      This is file X
      
      $ rm fileX
      $ cat fileY
      This is file X
      


  2. File name generation.
    One very powerful feature of UNIX that is handled by the shell is file name generation.

    The shell has certain meta-characters to allow expansion of file names.
    1. *
      The * matches zero or more characters. * by itself will match the entire directory.

    2. ?
      The ? matches any single character. So d?t matches dot and dit, but not deet.

    3. Sets
      Sets may be expressed by using the [] notation. For example [ab]* matches any file name that starts with a or b.
      Ranges may be specified like [a-h] for a through h.
      An ! in the set means invert the set.

    4. Examples
      $ ls
      feb96           jan26.96        jan94           mar96           
      memo2           jan12.96        jan5.96         jan95           
      memo1           memo2.sv        jan19.96        jan93           
      jan96           memo10
      

      $ ls *
      feb96           jan26.96        jan94           mar96           
      memo2           jan12.96        jan5.96         jan95           
      memo1           memo2.sv        jan19.96        jan93           
      jan96           memo10
      

      $ ls m[a-df-g]*
      mar96
      

      $ ls ?????
      feb96   jan93   jan94   jan95   jan96   mar96   memo1   memo2
      
      $ ls jan?? feb?? mar??
      feb96   jan93   jan94   jan95   jan96   mar96
      

      $ ls *[!0-9]
      memo2.sv
      

      $ ls [A-Z]*
      [A-Z]* not found
      

      $ ls *.*
      jan12.96   jan19.96    jan26.96     jan5.96      memo2.sv
      

      $ ls *96
      feb96           jan19.96        jan5.96         mar96
      jan12.96        jan26.96        jan96
      

      $ ls [fjm][ae][bnr]*
      feb96           jan19.96        jan5.96         jan94           
      jan96           jan12.96        jan26.96        jan93           
      jan95           mar96
      


  3. File Ownership and Protection

    1. Classes of users
      For every file and directory there are three classes of users who may access a file.
      1. User (or Owner)
      2. Group.
      3. Other (Public).


    2. Types of permission.
      There are also three types of permission.
      1. read
      2. write
      3. execute

    3. Displaying permission.
      The ls -l command will display the owner and permissions.
      
      $ls -l
      total 368
      -rwxr-xr-x   1 ask    staff      3354 Oct 30 1997  a.out
      -rw-r--r--   1 ask    staff     53521 Mar 24 1997  content.html
      -rw-r-----   1 ask    staff      9903 May  8 1997  eduquote.htm
      -rw-r--r--   1 ask    staff     11475 Oct 30 1997  form.html
      -rw-r--r--   1 ask    staff     12308 Oct 30 1997  gains.html
      -rw-r-----   1 ask    staff     42601 Oct 30 1997  index.html
      -rw-r--r--   1 ask    staff      9054 Oct 30 1997  inst.html
      -rw-r--r--   1 ask    staff      7113 Oct 30 1997  junk.html
      -rw-r--r--   1 ask    staff       282 Oct 30 1997  linefix.c
      -rwxr-xr-x   1 root   staff      1924 Mar 24 1997  little
      -rw-r--r--   1 ask    staff       147 Mar 26 1997  little.c
      -rwxr-xr-x   1 ask    staff      2726 May  8 1997  outline
      -rw-r--r--   1 ask    staff      2530 Oct 30 1997  timeline.html
      


    4. Flag bits
      The flag bit meaning are:
      1. 1st Character
        • d directory flag
        • - plain file
        • b block file
        • c character serial file
        • l link
        • s socket

      2. Other chararacters
        • r read permission
        • w write permission
        • x execute permission
        • - no permission
        • permissions
          PermissionMnemonic FilesDirectories
          Readr Examine the contents of the file List directory contents
          Writew Wrtie to or change the file
          also remove the file.
          Create and remove files in the directory
          Executex Run the file as a process Change to the directory

      3. Grouping
        The grouping of the flags bits:
        • The first triplet is for the user.
        • The second triplet for the group.
        • The last triplet is for others.


    5. Setting permissions
      Permissions may be reset using the chmod command.
      $ ls -l subtest
      -rw-------  1 kochis       468 Mar 12 09:57 subtest
      
      $ chmod o+r subtest
      $ ls -l subtest
      -rw----r--  1 kochis       468 Mar 12 09:57 subtest
      
      $ chmod 644 subtest
      $ ls -l subtest
      -rw-r--r--  1 kochis       468 Mar 12 09:57 subtest
      


  4. Common UNIX Directories.
    In 1993, the Linux community formed a project to provide a standardized filesystem layout. This has evolved into the Filesystem Hiearchy Standard or FHS.
    1. Data Types
      1. Data Sharing. - the scope of data in a networked environment.
        1. Sharable
          Can be used by multiple host systems on a network
        2. Non-sharable
          Unique to a single host such as a passwd file.
      2. Data modification
        How the data changes.
        1. Variable
          Changed by natural, frequent processes.
        2. Static
          Left alone for the most part, such as configuration files
      3. FHS Data Types
        . Sharable Non-sharable
        Static /usr
        /usr/local
        /etc
        /boot
        Variable /var/mail
        /home
        /var/log
        /proc
    2. The filesystem
      1. / (root)
        The root directory is present in all UNIX system file structures. It is the ancestor of all files in the filesystem.
      2. /bin
        Public commands are stored in this directory.
      3. /lib
        System libraries such as the standard C library.
      4. /etc
        Administrative and management commands and area. System configuaration files are kept here.
      5. /mnt
        Mount points for temporary partitions for cdrom etc.
      6. /dev
        All Unix devices are treated as files. This directory list the special file associated with every device on the system. Devices fall into two categories character serial and block structure.
        1. Character serial devices
          Those devices from which characters can be read or written only in a serial fashion such as terminals, printers and magnetic tapes. The UNIX system attempts to make serial devices look like ordinary files to the users.
        2. Blocked structured devices
          These devices used in the file system, allow the movement of the read/write heads. These are available to the users through file input/output requests.
        3. Viewing the devices
          An ls -l of /dev will show a c or b in the first position to denote either character or blocked device.
          brw-r-----  1 root       7,  80 Oct 13  1990 sd10a
          brw-r-----  1 root       7,  81 Oct 13  1990 sd10b
          brw-r-----  1 root       7,  82 Oct 13  1990 sd10c
          crw-rw-rw-  1 root      20,  38 Oct 13  1990 ttyr6
          crw-rw-rw-  1 root      20,  39 Oct 13  1990 ttyr7
          crw-rw-rw-  1 root      20,  40 Oct 13  1990 ttyr8
          
      7. /home
        Home directories for system users.
      8. /opt
        Intended for software other than that packaged with the operating system.
      9. /tmp
        Temporary storage. The contents are deleted upon every system boot.
      10. /usr
        A hierarchy od executable programs.
        1. /usr/X11R6 - X windows
        2. /usr/bin - primary location for user commands.
        3. /usr/games - older text games
        4. /usr/include - Header files for C and C++.
        5. /usr/lib -Shared libraries, such as perl support.
        6. /usr/local - Intended for use by the sysadmin.
        7. /usr/sbin - Primary location for sysadmin commands.
        8. /usr/share - Static daa such as GNU info system files.
        9. /usr/src - Linux source code
        10. Binaries
          . User Commands Sysadmin Commands
          Vendor supplied
          essential
          (root filesystem)
          /bin /sbin
          Vendor Supplied
          no-essential
          (/usr)
          /usr/bin /usr/sbin
          Locally suppied
          non essential
          /usr/local/bin /usr/local/sbin
      11. /var Data that varies over time such as logs, mail and spools.
        1. /var/cache - temporary storage intermediate data
        2. /var/account - accounting data
        3. /var/crash - crash dumps for OS.
        4. /var/lock - lock files.
        5. /var/log - logs
        6. /var/mail
        7. /var/spool

© Allan Kochis Last revision 9/05/2001