1 / 35

Chapter 3

Introduction to UNIX system. Chapter 3. Facilities. http://www.comp.nus.edu.sg/facilities.html. man policies sharing of computer account playing games during office hours misbehavior and eating in labs sending mass mails or chain mails running redundant or destructive processes

chico
Download Presentation

Chapter 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to UNIX system Chapter 3 Chapter 3: Introduction to UNIX system

  2. Facilities http://www.comp.nus.edu.sg/facilities.html Facilities

  3. man policies sharing of computer account playing games during office hours misbehavior and eating in labs sending mass mails or chain mails running redundant or destructive processes sending or posting distasteful, deragatory or prejudicial mails or messages Rules on computer usage Rules on computer usage

  4. Follow the steps given in chapter 3 of Preparatory Course for Programming. Logging in to and out ofNUSNET-III and UNIX machines Logging in and out

  5. Your password is important -- guard it! Change password regularly -- yppasswd Rules for password -- man passwd Use non-guessable password -- man password Password Password

  6. root / . . . home bin usr . . . . . . . . . stu98 stu99 . . . . . . garfield Garfield’s home directory doc prog my_file UNIX file system UNIX file system

  7. Basic UNIX commands Basic UNIX commands

  8. command <options> <arguments> validinvalid who w h o who -u who-u who - u ls -F lsFa ls -a ls- F ls -Fa ls -F-a ls -a -F Command format Command format

  9. Help facility -- man man <command> (eg: man who) man helpinfo man rules, man policies man printers, man printquota, man pusage man mailgroups, man mailinglists The ‘man’ command The ‘man’ command

  10. pwd, ls, mkdir, rmdir, cd pwd -- print working directory garfield@decunx:~[xx]$ pwd /home/stu99/garfield Organising directory Organising directory

  11. Full pathname: reference from root /home/stu99/garfield / /usr /home/stu99/garfield/prog ~/prog (~ = home dir) ~tantc/prep/index.html (= /home/staff/tantc/prep/index.html) / . . . home bin usr . . . . . . . . . stu98 stu99 . . . . . . garfield doc prog my_file Organising directory Organising directory

  12. Relative pathname: reference from curr. dir. (. = current dir; .. = parent dir) my_file ../../stu98 ./doc/hello garfield/my_file  ././.. bin  / . . . home bin usr . . . . . . . . . stu98 stu99 . . . . . . garfield curr. dir. doc prog my_file hello Organising directory Organising directory

  13. ls -- list directory garfield@decunx:~[xx]$ls c doc my_file garfield@decunx:~[xx]$ls -F c/ doc/ my_file garfield@decunx:~[xx]$ls -l drwx------ 1 garfield cpe99 512 May 10 09:39 c drwx------ 1 garfield cpe99 512 Jun 21 19:43 doc -rw------- 1 garfield cpe99 142 May 5 14:20 my_file Organising directory Organising directory

  14. mkdir -- make a new directory garfield@decunx:~[xx]$mkdir temp rmdir -- remove a directory (must be empty) garfield@decunx:~[xx]$rmdir temp Organising directory Organising directory

  15. cd -- change directory garfield@decunx:~[xx]$cd doc garfield@decunx:~/doc[xx]$ pwd /home/stu99/garfield/doc cd without argument -- return to home directory Organising directory Organising directory

  16. garfield@decunx:~[xx]$ls -l drwx------ 1 garfield cpe99 512 May 10 09:39 c d rwx --- --- d = directory - = file u g o File access permissions Access: r = read w = write x = execute/access File access permissions

  17. chmod -- change mode garfield@decunx:~[xx]$chmod g+rx . garfield@decunx:~[xx]$chmod g+rx c garfield@decunx:~[xx]$chmod g+r c/example1.c garfield Lower protection code for these directories and file . . . c prog example1.c File access permissions File access permissions

  18. Symbolic mode chmod g+w <filename> chmod o=rx <filename> chmod g+w,o=rx <filename> Octal mode chmod 504 <filename> r-x---r-- chmod 761 <filename> rwxrw---x File access permissions File access permissions

  19. cp -- copy file cp <source> <target> cp file1 file2 (what if there exists a file called file2? or there exists a directory called file2?) cp c/prog1.c  cp c/prog1.c . cp ~tantc/quiz/answers ans File manipulation • cp, mv, rm, cat (pr, pg, more, less) File manipulation

  20. mv -- move/rename file mv <source> <target> mv file1 file2 mv c/prog1.c . mv c/prog1.c ./prog2.c mv c/prog1.c prog2.c File manipulation File manipulation

  21. rm -- remove file rm file1 rm file1 file2 rm -i file1 File manipulation File manipulation

  22. cat -- catenate file; displays file’s content pr, pg, more, less cat file1 file2 pr file1 more file2 use cat for small files; use pg, more, less for big files File manipulation File manipulation

  23. man printers, man printquota, man pusage lpr -- send job to printer lpr -P<printerid> <filename> garfield@decunx:~[xx]$lpr -Ppsmr my_file Printing files Printing files

  24. lpq -- check printer queue garfield@decunx:~[xx]$lpq -Ppsmr Rank Owner Job Files Total Size active tantc 822 exercise1 38284 bytes 1st garfield 823 my_file 142 bytes lprm -- remove print job garfield@decunx:~[xx]$lprm –Ppsmr 823 Printing files Printing files

  25. Meta-characters for filename matching * (wildcard): matches any string ?: matches a single character [set]: matches a character in the set Assume files are part5, part6, part7, part10, part12, partA. cat part[4-6] cat part5 part6 rm part* rm part10 part12 part5 part6 part7 partA ls part? ls part5 part6 part7 partA Useful UNIX features Useful UNIX features

  26. I/O redirection <: input redirection >: output redirection >>: append date > file1 redirect output of date into file1 ls >> file1 append output of ls into file1 mailx dkiong <file1 send file1 to dkiong Useful UNIX features Useful UNIX features

  27. Pipe | Output of command sent as input to the next command in the piple who | wc -l count number of users logged in sort list | head | tail -3 extract 8th, 9th, 10th lines of list Useful UNIX features Useful UNIX features

  28. Follow the steps given in chapter 3 of Preparatory Course for Programming. Learn another more advanced editor: vi, vim, joe, emacs. Handy features for programming: search and replace, cut-and-paste, auto indentation, macros. Using the pico editor Using the pico editor

  29. Shell variables: system and user-defined. System shell variables: HOME home directory TERM terminal type PS1 primary prompt string SHELL shell type LOGNAME username Customising UNIX environment Customising UNIX environment

  30. $var represents the value stored in var: $HOME is '/home/stu99/garfield' $TERM is 'vt100' $PS1 is '$' $SHELL is 'bash' $LOGNAME is 'garfield’ to see value in variable, use echo: garfield@decunx:~[xx]$echo $HOME /home/stu99/garfield Customising UNIX environment Customising UNIX environment

  31. Changing a shell variable: garfield@decunx:~[xx]$PS1='Yes ! ' Yes! echo "what does PS1 contain? Ans: $PS1" what does PS1 contain? Ans: Yes! Yes! Customising UNIX environment Customising UNIX environment

  32. Creating/changing a user-defined variable: garfield@decunx:~[xx]$good="bad" garfield@decunx:~[xx]$echo $good bad garfield@decunx:~[xx]$xyz="$HOME" garfield@decunx:~[xx]$echo $xyz /home/stu99/garfield Customising UNIX environment Customising UNIX environment

  33. Alias: a synonym for command/statement. garfield@decunx:~[xx]$alias dir='ls' garfield@decunx:~[xx]$dir c/ doc/ my_file garfield@decunx:~[xx]$alias bye='exit' garfield@decunx:~[xx]$bye (log out…) unalias to remove alias: garfield@decunx:~[xx]$unalias bye Customising UNIX environment Customising UNIX environment

  34. .profile: automatically executed when you log in put aliases and other settings inside .profile to make them ‘permanent’ to activate definitions in .profile, type: garfield@decunx:~[xx]$. .profile Customising UNIX environment Customising UNIX environment

  35. Try exercises behind chapter 3. Homework Homework

More Related