A Small UNIX Tutorial by ozb45831

VIEWS: 4 PAGES: 28

									A Small UNIX Tutorial

    By CGS3063 staff
             What’s UNIX?

 An operating system claimed to be
  “standard” “from microcomputers to
  supercomputers”
 Invented by AT&T Bell Labs in late 60’s
 Currently there are different versions of
  UNIX such as SunOS, Linux, DEC OSF/1,
  AIX, HP-UX 10, Solaris, IRIX, SCO UNIX,
  etc.
          Why we need UNIX?

 For this class you need to work from your
  class grove account to finish your homework
  and/or submit your term paper
 Knowing basic UNIX commands is essential
  to finish your homework
            UNIX Commands

   ls [names] – list files contained in a directory name or
    that match a file name. If no name is given list those
    files in current directory.
      ls –a list all files including hidden files
      ls –l list in long format (including details like
        permissions, owner, size, etc.), works very much
        like dir
      ls –al list all files (including hidden files) in long
        format
      ls –dl dir_name lists information about the
        directory, “dir_name”.
            What is a Directory?

Your home directory might contain a public_html
 directory. Your public_html directory might
 contain an “index.html” file.
                    c3063xxx



                   public_html




                    index.html
           What is a Directory?

A file cannot hold a directory or a file!
                     c3063xxx



                    public_html



                     index.html



                 New_file_or_directory
              What is directory?

Directories can hold files and other directories
                            /


                          users    tmp
  bin       etc                               backup
                                   usern

                  user2                         file1
    user1                   … … public_html

                                           index.html
         What’s a directory?

 Files are grouped in the directory
  structure. The file-system is
  arranged like hierarchical tree
  (inverted)structure.
 The top of the tree is called “root”
  which usually contains several sub-
  directories. In UNIX “/”(forward
  slash) is used to present the “root”.
                      Pathnames

 Absolute Pathnames  Relative pathnames
     In the previous tree       If you are already in
      /users/usern/file1 is       the users directory,
      an absolute                 the relative
      pathname.                   pathname for file1 is
                                  usern/file1.
                  Specifying Paths

What is the absolute path to index.html?
                            /


                          users    tmp
  bin       etc                               backup
                                   usern

                  user2                         file1
    user1                   … … public_html

                                           index.html
                  Specifying Paths

What is the relative path to index.html
 (assuming that usern is your pwd)?
                             /

                                   tmp
  bin       etc           users                 backup
                                   usern

                  user2                           file1
    user1                   ……    public_html

                                           index.html
            More UNIX commands

 pwd –let you know the absolute pathname of your
  current working directory (Print Working
  Directory)
 cd [dir] – change directory

     cd .. –go back to parent directory. “   ..” is the relative
      pathname to the parent directory.
     “.” -stands for current (working) directory.
     “~” – the tilde ~ character can refer your home
      directory
           More UNIX commands

 mkdir directories – create one or more
  directories. You can specify them by
  absolute or relative pathnames.
 cp
     cp file1 file2 – copy file1 to file2. If there’s
      already a file2, the old one will be overwritten.
     cp file(s) directory – file(s) will be copied to the
      directory.
         More UNIX commands

 mv sourcefile targetfile – basically mv
  renames sourcefile to targetfile. If there’s a
  file with the same name as targetfile, it will
  be overwritten. mv works for directories in a
  similar fashion.
          More UNIX commands

 rm file(s) – delete file(s).
 rmdir directories – delete one or more empty
  directories.
 rm –r directories – can be used to delete non empty
  directories. !!!WARNING!!! This will DELETE
  EVERYTHING in that directory!!!
 You can not recover your files after you removed
  them (unlike Windows OS).
                     Permissions

 There are three types of file access supported
  by UNIX.
     r – read, view the contents of a file or a directory
     w –write, edit file/directory contents
     x –execute, run executable file
                      Permissions

Here’s an example
     Suppose you type in ls -l and the result is

      -   rwx r-x r-- 1 hans doc 858 Aug 22 22:28 hw1


      What do all these symbols mean?
                          Permissions


        - rwx r-x r-- 1 hans doc 858 Aug 22 22:28 hw1


                         links owner                                       File name
type
                                               size   Modification date/time
                                       group
    User
 permissions

            Group          Other
          permissions   Permissions
                    Permissions

 User – the person who created the file.
 Group – the group owns the file.
 Other – the rest of the world
 “754” is a decimal number. But you can
  represent each digit with a binary number.
     4 => read permission, 2 => write permission,
     1=> execute permission
                      Permissions

    read=4;write= 2;execute=1
        rwx                   r-x                   r--




4   +   2     +   1   4   +   0     +   1   4   +   0       +   0



        7                      5                        4
                 Permissions

rwx r-x r-- is a symbolic way to specify file modes,
while 754 is a numeric way (remember 7  111, 5
101, 4100 ? ). How would you represent this
file mode numerically?
                 --x --x –wx
How would you represent this bit string
symbolically?
                      614
                       Permissions

 chmod mode file(s) – another UNIX
  command! Change the access mode of one or
  more files. Examples:
      chmod 751 my_file – the owner of my_file has rwx(7)
      permission, the group has r-x(5) permission, others have
      --x permission.
     Tell me what the following command will do?
      chmod u=rwx, g=r, o=wr my_file
      Remember user, group and others?
                       Get started

 Create a new directory in your grove account
  named public_html by using the following
  command,
     mkdir public_html
 Go to this directory
     cd public_html
 Use pico to create a new file named
  index.html
                        Editor in UNIX

Some short cuts for the pico editor
      ^G Get Help
       ^O WriteOut
      ^R Read File
      ^Y Prev Pg
      ^K Cut Text
      ^C Cur Pos
      ^X Exit
       ^J Justify
       ^W Where is
       ^V Next Pg
       ^U UnCut Text
       ^T To Spell
                   Get started

After you save the file index.html, change the
 mode of this file by using the following
 command,
  chmod 644 index.html
  (u=rw-, g=r--, o=r--)
Check whether you did it right
  ls –l or dir
  (What result should be displayed?)
                   Get started

Then go back to parent directory
  cd ..
Change the mode of public_html directory
  chmod 755 public_html
  ( What’s the meaning of this command?)
Check if you got the mode set right
  ls –dl public_html
            Where to get help?

 Come to see us during the office hours
 The CGS3063 tutorial available on line
  (technical info)
 man subject(s) – the UNIX help command.
  e.g.: to get help info about mv command you can
    type man mv to get detailed manual of mv
    command.
Thank you and good luck!

								
To top