350 likes | 405 Views
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
E N D
Introduction to UNIX system Chapter 3 Chapter 3: Introduction to UNIX system
Facilities http://www.comp.nus.edu.sg/facilities.html Facilities
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
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
Your password is important -- guard it! Change password regularly -- yppasswd Rules for password -- man passwd Use non-guessable password -- man password Password Password
root / . . . home bin usr . . . . . . . . . stu98 stu99 . . . . . . garfield Garfield’s home directory doc prog my_file UNIX file system UNIX file system
Basic UNIX commands Basic UNIX commands
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
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
pwd, ls, mkdir, rmdir, cd pwd -- print working directory garfield@decunx:~[xx]$ pwd /home/stu99/garfield Organising directory Organising directory
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
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
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
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
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
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
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
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
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
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
rm -- remove file rm file1 rm file1 file2 rm -i file1 File manipulation File manipulation
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
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
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
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
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
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
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
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
$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
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
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
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
.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
Try exercises behind chapter 3. Homework Homework