470 likes | 675 Views
UNIX Talk 2007. For CEG Y07 Tang Wai Chung, Matthew (MaFai) Date: 27th AUG, 2007. Overview. CSE working environment UNIX basics UNIX file system Process Management Common UNIX utilities Internet Applications Text Editor: VIM. You are here. SHB 122. SHB 924. SHB 904. 7 x 24 hrs.
E N D
UNIX Talk 2007 For CEG Y07 Tang Wai Chung, Matthew (MaFai) Date: 27th AUG, 2007
Overview • CSE working environment • UNIX basics • UNIX file system • Process Management • Common UNIX utilities • Internet Applications • Text Editor: VIM
You are here SHB 122 SHB 924 SHB 904 7 x 24 hrs CSE Student Laboratories undergrad. postgrad.
1 GB Storage User Account samba server username: tmchan7 password: i_love_u2 * use the same p/w for XP and UNIX.
Connect to UNIX Workstations ssh sparc?? ssh linux? username: tmchan7 password: *********
User Account (Cont) Personal Homepagehttp://www.cse.cuhk.edu.hk/~[username]orhttp://appsrv.cse.cuhk.edu.hk/~[username] • Put your webpages under directory www &allow world readable permission (discuss later) Email address:[username]@cse.cuhk.edu.hk
Printers & Printing Run out of quota? • Quota transfer • Purchase more quota More detailshttp://www.cse.cuhk.edu.hk/corner/tech/account
Chan Tai Man 07123456 / tmchan7 31-Aug-2010 Etiquette in Labs
Why UNIX? Efficient manipulation (regexp, batch, scripting) Accessible account everywhere Convenient programming environment Java C C++
UNIX Basics Users issue commands to the OS.
Commands • Users type in commands to execute their jobs. • Predefined mnemonics with known meaningse.g. ls = list, cp = copy, rm = remove, etc… • Case-sensitive • Basic syntax[command] –[option(s)] [argument(s)] Instruction for how it acts Target to act on
More About Commands • Multiple commands can be separated with a semicolon (;) • Example: [command 1]; [command 2]; [command 3] • Enter command in several lines using backslash (\) • Example: [a very long command 1]; \ (enter)[a very long command 2]
u Ctrl + clear line l Ctrl + clear screen d c Ctrl Ctrl + + disconnect / logout break a command Terminal
Prompt & Shell • You will find a prompt for you to type commands.e.g. sparc1:/uac/y07/tmchan6> • Shell: command interpreter • Review command history • Auto-complete Ctrl Machine Name Current directory
Lab Exercise 1: Startup Setup your own UNIX environment. • Login the PC • Start “SSH Secure Shell Client” • Edit Settings Global Settings: Appearance: Colors Foreground: White; Background: Black • Quick Connect – Host Name = sparcXX; login using your own account • ls • /uac/gds/wctang/bin/startup.script • source .cshrc • ls(this time the listing should be colourful!)
y07 uac usr / UNIX File System • Multi-leveled hierarchy: directory tree Path /uac/y07 /uac /usr /
UNIX File System • Filename: max. length 256 characters – numbers, alphabets, {_ . [ ]} or other symbols • Hidden file began with ‘.’ • Directory: a special file which stores a group of other files (incl. directory). • Every user has a home directory. • Path • Absolute (relative to /) • Relative (current directory)
UNIX File System • Special directories • . = current directory • .. = parent directory (one level up) • ~ = home directory • ~[userA] = home directory of “userA”
Demo 1 File & Directory Redirection & Pipe
Lab Exercise 2: Save File Listing in a file • mkdir utalkcreate a new directory called “utalk” • cd utalkgo into the new directory • ls –l ~ > home.ls.txtlist the home directory and save the output in “home.ls.txt” • more home.ls.txtread back the content • rm home.ls.txtremove the file • cd ..go up one level • rmdir utalkdelete the directory
File Permission y07 user(u) others(o) group(g) • r: read • w: write • x: execute rwxrwxrwx\u/\g/\o/
Changing Permission • Basic Syntaxchmod [permission_triads/mode] [filename] • permission_triads := [who][action][permissions]who = {u, g, o, a} action = {+, -}permissions = {r, w, x}e.g. chmod a+r allcanread.txt • mode := [u][g][o]r = 4, w = 2, x = 13=w+x; 5 = r+x; 7=r+w+xe.g.1: chmod 640 a.txte.g.2: chmod 751 mydir
Archive & Backup: gtar • Very often we would like store an archive of your files (source codes, reports). • gtar is an utility to compress a set of files to an archive (or vice versa). • Compress: gtar zcvf [archive name] [file list] • Expand: gtar zxvf [archive name]
Managing Print Queues • You can check and remove print jobs only on UNIX (even jobs from XP) • Check print queue & find print job IDlpq –P[printer name] • Remove the job from the queuelprm –P[printer name] [job ID] • Print a postscript file directlylpr –P[printer name] [postscript file] • Check print quotasprintquota
Using “man” • The command man will display the manual of other commands.e.g. man lsexplains the details & options with ls • d,f: Forward; b,Ctrl+b: back • /: search for keywords in the manualn: next matched items • q: quit
Email Client: Pine • Pine is a fast, simple and easy-to-use email client on UNIX systems. • With a simple terminal, you can check and send emails everywhere. • You will never be afraid of being infected by unknown attachment from emails! • You can also edit your own email filter script for efficient categorization. (ref: procmail)
Demo 2 File Permission Email: Pine
Powerful Editor: VIM • VIM is one of the most powerful text editor in which you can enter the most letters with less number of keystrokes • Syntax highlight is available in nearly all languages you will use here(C, C++, Java, Pascal, HTML, PHP, SQL) • Automatic backup (.swp file) • Highly customizable • Strong support community including
Modes in VIM • In normal mode of VIM, you issue commands instead of inserting letters. • You can enter to insert mode by pressing <i>, <a>, <o>, etc .. • Insert mode, you can type as you do in notepad. • Return to normal mode by pressing <Esc>
Modes in VIM (Cont) <i>, <a>, <o> COMMAND copy & paste formatting INSERT type your codes edit your text <Esc> visual
Move around (Command Mode) • You can use cursor keys or <h> = left; <l> = right; <j> = down; <k> = up • <Ctrl-u> = up half page<Ctrl-d> = down half page<Ctrl-b> = back 1 page<Ctrl-f> = forward 1 page
Move around (Command Mode) • <$>: end of line; <^>: beginning of line; <0>: first position. • <{no}G>: go to line {no} • <gg>: beginning of file • <G>: end of file
Save & Quit • <ZZ>: write file and exit (time to sleep!) • <:w>: save with same name • <:q>: quit • <:wq>: save and quit • When you add ‘!’ at the end of w or q, you force to execute the command. • <:sav {filename}>: save as.
Deleting ... Undo / Redo • <d{type}>: delete 1 object of {type} • <dd>: delete a line • <dw>: delete one word • <d3w>: delete 3 words • <y{type}>: yank (copy) 1 object • <yy>: copy a line to buffer • <p>: paste the buffer content • <u>: undo • <Ctrl-r>: redo
NNTP News Reader: Tin • Most of our courses have newsgroup in the NNTP server. • Tin is fast, simple and easy-to-use news reader on UNIX. • Tin keeps you with the latest news from courses (hints? delay?). • Check and post your news everywhere with a terminal.
Demo 3 Powerful Editor: VIM News Reader: TIN
Lab Exercise 3: Internet Utilities • Use pine to send an email to me (wctang) using the subject “Y07 [username]” • Use tin to subscribe the newsgroup cuhk.testUse VIM to edit and post in this group.
Q & A / Free Chat Thank you for your attention! See you all again in ERG2020B!