A Small UNIX Tutorial by ozb45831


									A Small UNIX Tutorial

    By CGS3063 staff
             What’s UNIX?

 An operating system claimed to be
  “standard” “from microcomputers to
 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,
          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
      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.


           What is a Directory?

A file cannot hold a directory or a file!



              What is directory?

Directories can hold files and other directories

                          users    tmp
  bin       etc                               backup

                  user2                         file1
    user1                   … … public_html

         What’s a directory?

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

 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
                  Specifying Paths

What is the absolute path to index.html?

                          users    tmp
  bin       etc                               backup

                  user2                         file1
    user1                   … … public_html

                  Specifying Paths

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

  bin       etc           users                 backup

                  user2                           file1
    user1                   ……    public_html

            More UNIX commands

 pwd –let you know the absolute pathname of your
  current working directory (Print Working
 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
           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
         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
 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).

 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

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?

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

                         links owner                                       File name
                                               size   Modification date/time

            Group          Other
          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

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

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

        7                      5                        4

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

 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
     mkdir public_html
 Go to this directory
     cd public_html
 Use pico to create a new file named
                        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
  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
Thank you and good luck!

To top