UNIX

Document Sample
UNIX Powered By Docstoc
					        UNIX

Working with Directories
               Unix Files
• Unix files are ________ of data under a
  given name. Can be text, binary, a link, or
  a directory.
• Directories are files that contain ________
  ________.
               UNIX Directories
•   the directory structure
•   the home directory (~)
•   the root directory (/)
•   changing directories (cd)
•   display the working directory (pwd)
•   displaying files in a directory (ls)
•   making a directory (mkdir)
•   changing directory permissions (chmod)
•   copying directories (cp)
•   moving directories (mv)
•   removing a directory (rmdir)
      Unix Directory Structure
• Directories are similar to the folders in a
  ____________ environment.
  – inverted tree format (root on top)
  – devices (C:, D:, etc.) not specified
Unix Sample Directory Structure
              / (root)




 bin   etc     dev         lib      home




       java              zabc123   zdef456   zghi789
                Unix/Windows
           Sample Directory Structure
/ (root)

              bin

              etc

                             java

              dev

              lib

            home

                          zabc123

                           zdef456

                           zghi789

    Unix Directory Structure                      Windows Directory Structure
    note: Unix does not precede pathnames
    with device identifiers (e.g. c:, D:, etc.)
     Some Standard Directories
• / (root)   Base of the file system hierarchy
• bin        _________ images of some UNIX
             commands
•   dev      Filenames that correspond to _______
•   etc      System administrator files
•   lib      Library files
•   tmp      Temporary files - some UNIX
             commands
• home       _____ portion of file system (may also
             be called _____ on some systems)
       File/Directory Naming
• Up to _____ characters in length
• ________ sensitive (jan not same as Jan)
• Recommended characters are:
  – Upper/lower case (A-Z, a-z)
  – Numbers (0-9)
  – Underscore (_)
  – Period (.)
  – Comma (,)
        The root directory (/)
• The root directory (/) is the _______
  location for all directories in Unix
  Caution: if a directory name is preceded
  by the root directory (/), Unix assumes that
  we wish to specify the _______ directory
  path!
       The Home Directory
• The _____ directory becomes the ______
  directory when logging on (not the root
  directory (/)).
• May be referenced using:
  – system variable HOME (try echo $HOME)
  – the tilda (try echo ~)
          Directory symbols
• Unix provides ________ symbols to refer
  to certain directories.
• Examples:
  – / (forward slash) – the ______ directory
  – ~ (tilda) – your ______directory
  – . (period) – the _______ directory
  – ..(double period) – the ________directory
    (one up in the tree)
     Unix Directory Navigation
•Absolute – Always begins with the ___ directory.
  Example:
             /home/zabc123/public_html
•Relative – begins with the ______ directory (do
not start with a slash(/) as that means absolute)
  Example:
                  public_html
     assuming we are in the /home/zabc123 directory,
     public_html refers to the absolute directory name:
               /home/zabc123/public_html
  Relative Directory Navigation
• May use the double period (..) to move ___ the
  tree relative from the current directory.
• Cannot use ___ in the root directory. Why not?
• Example:
  Assuming we are in directory:
     /home/zabc123/public_html
  ../myprog will refer to directory /home/zabc123/myprog
  since .. means /home/zabc123/
               Change Directories (cd)
 • Format: cd [directory]
 • If the directory is _______ the user is returned
   to his/her home directory, directory may be
   either an absolute or relative directory name
 • Examples:
                      type
     command                                                   comments
                   directory
cd /home           absolute    go to directory: /home
cd zabc123         relative    go to directory zabc123 from current directory (e.g. if in /home directory
                               would end up in /home/zabc123 directory)
cd ..              relative    go to parent directory if in /home/zabc123 directory would end up in
                               /home directory)
cd                             go to your personal home directory
cd ~/public_html   relative    go to the public_html directory within your home directory
cd ../def456       relative    go up one directory and down to the def456 subdirectory of the parent
  Identifying the Working directory
                (pwd)
• On occasion the user may forget where he
  or she may be in the directory _________.
• The pwd (present/print working directory)
  command will display the current directory
  on the screen.
    Displaying contents of a directory
                   (ls)
•   Format: ls [-options] [directoryname]
•   If directoryname is omitted, current directory is listed.
•   Popular options (recall Unix is case sensitive):
     – -a Shows you all files, even files that are hidden (these files begin with a dot.)
     – -l will list each of the files in the current directory giving:
          • permissions (d-directory, l - link, r-read, w-write, x-execute or access from internet). The
            permissions will be repeated for the three types of accessibilities: user (you only);
            group; other (basically the world).
          • The number of links or directories within the directory.
          • username
          • group name
          • file size in bytes
          • date and time of the last modification,
          • the file name or directory.
     – -R             Recursive, shows listings of subdirectories
     – -F             List directories with /; executables with *
     – -q             Print non-graphic invisible control chars
                   ls –l Example
                                      file type (d=directory,   = file)
                                      permissions
                                      links
                                      owner
                                      group


-rw-r--r--   1 zucker faculty          18 Jan 31 11:02 sordid
-rwx--x--x   1 zucker faculty          42 Sep 24 13:23 temp
drwx--x--x   3 zucker faculty        4096 Jan 24 10:40 test



                      size (bytes)
                   modified date
                    modified time
             file/directory name
                    ls –l permissions
                                                   file type (d=directory,     = file)
                                                   user
                                                   group
                                                   other
-rw-r--r--        1 zucker faculty                18 Jan 31 11:02 sordid
drwx--x--x        3 zucker faculty              4096 Jan 24 10:40 test
               Permission types:
                   r – Read (persons may view the file)
                   w – Write (persons may modify or delete file)
                   x – Execute (persons may be able to execute
                   the file or if the file is a directory, the directory may
                   be accessed)
In this example:
• file sordid may be read and modified by the owner (zucker), read only by
the group (faculty), and read only by the world.
• directory test may be read, written, and accessed by the owner (zucker)
and accessed by the group (faculty) and the world
   Creating a Directory (mkdir)
• mkdir [options] directory name
• Short for Make a Directory
• Creates a ________ of the existing
  directory
• May want to use upper-case letters for
  directory names (to distinguish from files,
  discussed later)
         File/Directory Naming
                 (review)
• Up to _____ characters in length
• Case sensitive (jan not same as Jan)
• Recommended characters are:
  – Upper/lower case (A-Z, a-z)
  – Numbers (0-9)
  – Underscore (_)
  – Period (.)
  – Comma (,)
 chmod [options] mode directory
•Changes the ________ mode for a given directory; only
 the owner of the directory or the SuperUser can change
 its access _________.
•Options
    –-R recursively
•Can use octal permission numbers
    –r – 4 : read permission
    –w – 2 : write permission
    –x – 1 : execute permission*
     * For directories execute permission allows users to access a
      directory without reading it. This is important for creating html
      directories, allowing web users to view web content within a
      directory, but not be able to read the directory itself.
           Octal Permissions
Octal value equation Permissions
    0         0     none
    1         1     execute
    2         2     write
    3       _____   write and execute
    4         4     read
    5       _____   read and execute
    6       _____   read and write
    7       _____   read, write, and execute
           chmod Examples
• using octal permissions
                    give user read (4), write (2), and execute (1)
                    (4+2+1=7) permission
                   give group read (4) and execute (1)
                   (4+1=5) permission

                   give everyone execute (1) permission



  – chmod 751 mydir
• mydir permissions would show as drwxr-x--x


                                               {
                                                     {
                                                     {
                            directory                            other
                               user                              group
  chmod [options] mode directory
• Class of user:
   – u          User (you)
   – g          Group
   – o          Other (all others)
   – a          All u, g, and o
• Permission Values:
   – r          Read
   – w          Write
   – x          Execute
• Operations:
   – + add permission
   – - remove permission
   – = set permission (replace existing)
                 chmod Examples
• Using options
permission       meaning
u=rwx,g=rw,o=r   user has read, write, and execute; group has read
                 and write, others have read
g-w,o-r          remove write permission from group, remove read
                 permission from other (leave all other permissions
                 alone)
o+r              add write permission to others
a-w              remove write permissions for all (user, group, and
                 others)
       Copying Directories (cp)

• cp -r sourcedirectory destinationdirectory
• Copies an entire directory _________
  If destination directory exists before
  issuing cp command, the cp command
  creates a __________ within the directory
  otherwise it makes a new copy
• Options (required for directory copying)
  – -R or –r Copy directories recursively
 Move/Rename Directories (mv)
1. mv sourcedirectory nonexistentdirectory
2. mv sourcedirectory existingdirectory
________ or moves the source directory to:
  – 1. the nonexistent directory
  – 2. a subdirectory of the existing directory
    Remove/Delete a Directory
            (rmdir)
• rmdir directoryname
  Directory must be _________
  Current working directory ________ be the
   directory you are removing
  Does not ask for confirmation, be careful
               UNIX Directories
•   the directory structure
•   the home directory (~)
•   the root directory (/)
•   changing directories (cd)
•   display the working directory (pwd)
•   displaying files in a directory (ls)
•   making a directory (mkdir)
•   changing directory permissions (chmod)
•   copying directories (cp)
•   moving directories (mv)
•   removing a directory (rmdir)
              Next Time
• Please review the following file commands
  in the text:
  – touch
  – cat
  – chmod
  – rm
  – cp
  – mv

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:13
posted:8/1/2012
language:English
pages:30