Notes: Unix Lab 03

  1. Description of the Unix file system
  2. The root directory
  3. Comparison with Windows
  4. Files and Directories
  5. The pwd command
  6. The cd command
  7. Absolute and Relative Paths
  8. The ls command
  1. description of the Unix file system

    A file system is an organized data structure for storing files and directories on a disk or other storage device. The Unix file system is organized in a hierarchical manner with the root directory, "/" as the top level of the hierarchy. There is a general organization of the files and directories that is common among most all versions of unix. We will look at this organization more in the next lab.

  2. The / (root) directory

    In unix all available storage is referenced from the root directory, "/". There are no drive letters designating additional storage decices such as secondary hard drives, CDROM drives, or floppy disks.

  3. Comparison with windows

    In Windows the file manager, Explorer, graphically displays the file system as a tree which can be navigated with the mouse. The path to the "hds" directory is shown in each image. Note that Unix does not use letters to designate the drive but just references its locations from the root directory, "/". So for the Unix command-line the "hds" directory would be referenced by the path /mnt/data/gempak/hds, this is the "path". As show above, under windows it would referenced as K:\gempak\hds. Note that DOS/Windows uses the back-slash character, "\", to separate directory entries where Unix uses the forward slash character, "/".

    Another significant difference is the use of drive letters. With windows each additional storage device is assigned a "drive letter". The system disk is usually C:, floppy disks are typically A: and B:. CDROM drives, network drives and other media will be assigned other letters. In Unix additional storage devices are attached to a directory under the root file system as determined by the system administrator. This will be discussed in more detail in the next lab.

  4. Files and directories

    The file is a unit of information. It can store any type of data. Directories are a type of file which can contain references to other regular files or directories. In Windows this is called a "folder". There are a couple of other types of files on a unix system but you will not typically deal with them as a regular user of a system.

  5. There are many, many commands on a Unix system to navigate the file system and to manipulate files. Next we will look at few commands for navigation and information.
  6. The pwd command

    The pwd command simply prints the name of the current (or working) directory to standard output (the terminal).

    mark@platypus:~> pwd

  7. The cd command

    The cd command is used to change the working directory. It takes only one argument, the path to which the user wishes to change the working directory to.

    mark@platypus:~> pwd
    mark@platypus:~> cd /mnt/data/
    mark@platypus:/mnt/data> pwd
    mark@platypus:/mnt/data/wxdata> pwd

    The cd command issued without arguments will return the user to their home directory.
    mark@platypus:/mnt/data/wxdata> cd
    mark@platypus:~> pwd

  8. Absolute and relative paths

    The cd command, along with most other unix commands can use absolute or relative paths in their arguments. An absolute path is the complete path to a file or directory relative to the root directory. An absolute path will always start with the root directory, "/".

    The path /mnt/homes/tuckerm is the absolute path to the directory tuckerm.

    An example of changing directory with an absolute path:
    mark@platypus:~> pwd
    mark@platypus:~> cd /mnt/homes
    mark@platypus:/mnt/homes> pwd
    A relative path is the path to a file or directory relative to the working directory for a given shell. A relative path will not begin with the root directory.

    An example of changing directory with a relative path:
    mark@platypus:~> pwd
    mark@platypus:~> cd temp
    mark@platypus:~/temp> pwd

  9. The ls command (-a,l,F,t,r options)

    The ls command is used to list files and directories. Without any options or arguments it will list the contents of the working directory:

    mark@platypus:~/temp> pwd
    mark@platypus:~/temp> ls
    TclTutor  WRF_NCL  usr

    ls can also take one or more arguments which will be the absolute or relative paths to the files or directories to list.

    Listing files using an absolute path:
    mark@platypus:~> pwd
    mark@platypus:~> ls /home/mark/temp
    TclTutor  WRF_NCL  usr

    Listing the same files using a relative path:
    mark@platypus:~> pwd
    mark@platypus:~> ls temp
    TclTutor  WRF_NCL  usr

    Some commonly used options for ls:

    -a lists all files (including hidden files or directories)
    -d     List  names of directories like other files, rather
                  than listing their contents.
    -l     Write  (in single-column format) the file mode, the
                  number of links to the file, the  owner  name,  the
                  group  name,  the  size of the file (in bytes), the
                  timestamp, and the filename.
    -F     Suffix each directory name with `/', each link name
                  with  `@', and each name of an executable with `*'.
    -t     Sort by the timestamp shown.
    -S     Sort by filesize.
    -r     Reverse the order of the sort.
    The -l option provides quite a bit of additional information about the listed files or directories.

    An ls example with the -l option:
    mark@platypus:~> ls -l temp
    total 154
    drwxr-xr-x  2 mark users   1640 2000-05-09 00:50 TclTutor
    drwxr-xr-x  2 mark users    952 2004-05-18 17:04 WRF_NCL
    -rw-r--r--  1 mark users 153541 2005-01-25 12:53
    drwxr-xr-x  5 mark users    120 2001-09-05 01:07 usr

    The first character in the listing indicates what type of file the file is. "d" designates directories, "-" designates regular files, "l" will designate symbolic links (more on that later). The string of characters that follow (r,w,x,-) are used to show the access permissions for the file. Those will be explained in detail in future lab. The next column shows the number of links to the file or directory. Following that is the username of the owner of the file. Next is the name of the group for that file. The fifth column shows the size of the file, usually in bytes. The sixth column shows the date that the file was last modified followed by the time. The final column is the name of the file or directory.