unix talk 2007 for ceg y07 tang wai chung, matthew (mafai) date: 27th aug, 2007
Post on 20-Dec-2015
215 views
TRANSCRIPT
UNIX Talk 2007UNIX Talk 2007
For CEG Y07For CEG Y07Tang Wai Chung, Matthew (MaFai)Tang Wai Chung, Matthew (MaFai)
Date: 27th AUG, 2007Date: 27th AUG, 2007
Page Page 22
OverviewOverview
CSE working environmentCSE working environment UNIX basicsUNIX basics UNIX file systemUNIX file system Process ManagementProcess Management Common UNIX utilitiesCommon UNIX utilities Internet ApplicationsInternet Applications Text Editor: Text Editor: VIMVIM
Page Page 33
undergrad.
CSE Student LaboratoriesCSE Student Laboratories
SHB 122
SHB 924 SHB 904
7 x 24 hrs
postgrad.
You are here
Page Page 44
User AccountUser Account
1 GB Storage
username: tmchan7password: i_love_u2* use the same p/w for
XP and UNIX.
samba server
Page Page 55
Connect to UNIX Connect to UNIX WorkstationsWorkstations
username: tmchan7
password: *********
ssh
ssh
sparc??
linux?
Page Page 66
User Account (Cont)User Account (Cont)
Personal HomepagePersonal Homepagehttp://www.cse.cuhk.edu.hk/~[username]http://www.cse.cuhk.edu.hk/~[username]ororhttp://appsrv.cse.cuhk.edu.hk/~[username]http://appsrv.cse.cuhk.edu.hk/~[username] Put your webpages under directory Put your webpages under directory wwwwww & &
allow world readable permission (discuss later)allow world readable permission (discuss later)
Email address:Email address:[username]@cse.cuhk.edu.[username]@cse.cuhk.edu.hkhk
Page Page 77
Printers & PrintingPrinters & Printing
Run out of quota?Run out of quota? Quota transferQuota transfer Purchase more quotaPurchase more quotaMore detailshttp://www.cse.cuhk.edu.hk/corner/tech/account
LocLoc 122122 904904 924924
B/W (1 Q)B/W (1 Q) ps4ps4 ps3ps3 ps,ps2ps,ps2
Colour (5 Colour (5 Q)Q)
cpscps n/an/a cps1,2cps1,2
Page Page 88
Etiquette in LabsEtiquette in Labs
Chan Tai Man
07123456 / tmchan7
31-Aug-2010
Page Page 99
Why UNIX?Why UNIX?
Accessible account everywhere
Convenient programming environment
Efficient manipulation (regexp, batch, scripting)
Page Page 1010
UNIX BasicsUNIX Basics
Users issue commands to the OS.
Page Page 1111
CommandsCommands Users type in commands to execute their jobs.Users type in commands to execute their jobs. Predefined Predefined mnemonicsmnemonics with known meanings with known meanings
e.g. ls = list, cp = copy, rm = remove, etc…e.g. ls = list, cp = copy, rm = remove, etc… Case-sensitiveCase-sensitive Basic syntaxBasic syntax
[[commandcommand] –[] –[option(s)option(s)] [] [argument(s)argument(s)]]
Target to act on
Instruction for how it acts
Page Page 1212
More About CommandsMore About Commands Multiple commands can be separated wiMultiple commands can be separated wi
th a semicolon (;)th a semicolon (;)Example: Example: [command 1]; [command 2]; [command 3][command 1]; [command 2]; [command 3]
Enter command in several lines using baEnter command in several lines using backslash (\)ckslash (\)Example: Example: [a very long command 1]; \[a very long command 1]; \ (enter) (enter)[a very long command 2][a very long command 2]
Page Page 1313
TerminalTerminal
Ctrl
u+
clear lineclear line
Ctrl
l+
clear screenclear screen
Ctrl
c+
break a commandbreak a command
Ctrl
d+
disconnect / logoutdisconnect / logout
Page Page 1414
Prompt & ShellPrompt & Shell You will find a prompt for you to type coYou will find a prompt for you to type co
mmands.mmands.e.g. e.g. sparc1:/uac/y07/tmchan6>sparc1:/uac/y07/tmchan6>
Shell: command interpreterShell: command interpreterReview command historyReview command history
Auto-completeAuto-complete
Ctrl
Machine Name Machine Name Current directory Current directory
Page Page 1515
Lab Exercise 1: StartupLab Exercise 1: StartupSetup your own UNIX environment.Setup your own UNIX environment.
1.1. Login the PCLogin the PC2.2. Start “SSH Secure Shell Client”Start “SSH Secure Shell Client”3.3. Edit Edit Settings Settings Global Settings: Appearance: C Global Settings: Appearance: C
olors olors Foreground: White; Background: Black Foreground: White; Background: Black4.4. Quick Connect – Host Name = sparcXX; Quick Connect – Host Name = sparcXX;
login using your own accountlogin using your own account5.5. lsls
6.6. /uac/gds/wctang/bin/startup.script/uac/gds/wctang/bin/startup.script
7.7. source .cshrcsource .cshrc
8.8. lsls (this time the listing should be colourful!)(this time the listing should be colourful!)
Page Page 1616
Page Page 1717
UNIX File SystemUNIX File System Multi-leveled hierarchy: directory treeMulti-leveled hierarchy: directory treePath
uac usr
y07
/uac /usr
/uac/y07
/ /
Page Page 1818
UNIX File SystemUNIX File System Filename: max. length 256 characters – Filename: max. length 256 characters –
numbers, alphabets, {_ . [ ]} or other synumbers, alphabets, {_ . [ ]} or other symbolsmbols
Hidden file began with ‘.’Hidden file began with ‘.’ Directory: a special file which stores a grDirectory: a special file which stores a gr
oup of other files (incl. directory).oup of other files (incl. directory). Every user has a Every user has a home directoryhome directory.. PathPath
Absolute (relative to /)Absolute (relative to /)Relative (current directory)Relative (current directory)
Page Page 1919
UNIX File SystemUNIX File System
Special directoriesSpecial directories . = current directory. = current directory .. = parent directory (one level up).. = parent directory (one level up)~ = home directory~ = home directory~[userA] = home directory of “userA”~[userA] = home directory of “userA”
Page Page 2020
cdcd
lsls
cpcp
rmrm
mvmv
mkdirmkdirrmdirrmdir
Commands (File Manipulations)Commands (File Manipulations)
Demo 1Demo 1
File & DirectoryFile & DirectoryRedirection & PipeRedirection & Pipe
Page Page 2222
Lab Exercise 2: Save File Listing in a fileLab Exercise 2: Save File Listing in a file1.1. mkdir utalkmkdir utalk
create a new directory called “utalk”create a new directory called “utalk”2.2. cd utalkcd utalk
go into the new directorygo into the new directory3.3. ls –l ~ > home.ls.txtls –l ~ > home.ls.txt
list the home directory and save the output in “holist the home directory and save the output in “home.ls.txt”me.ls.txt”
4.4. more home.ls.txtmore home.ls.txtread back the contentread back the content
5.5. rm home.ls.txtrm home.ls.txt remove the fileremove the file
6.6. cd ..cd ..go up one levelgo up one level
7.7. rmdir utalkrmdir utalkdelete the directorydelete the directory
Page Page 2323
File PermissionFile Permission
• r: read• w: write
• x: execute
rwxrwxrwx\u/\g/\o/
y07
others(o
)
grou
p(g)
user(u)
Page Page 2424
Changing PermissionChanging Permission Basic SyntaxBasic Syntaxchmodchmod [ [permission_triads/modepermission_triads/mode] [] [filenamefilename]]
permission_triadspermission_triads := [ := [whowho][][actionaction][][permissiopermissionsns]]whowho = {u, g, o, a} = {u, g, o, a} actionaction = {+, -} = {+, -}permissionspermissions = {r, w, x} = {r, w, x}e.g. e.g. chmod a+r allcanread.txtchmod a+r allcanread.txt
modemode := [ := [uu][][gg][][oo]]r = 4, w = 2, x = 1r = 4, w = 2, x = 13=w+x; 5 = r+x; 7=r+w+x3=w+x; 5 = r+x; 7=r+w+xe.g.1: e.g.1: chmod 640 a.txtchmod 640 a.txte.g.2: e.g.2: chmod 751 mydirchmod 751 mydir
Page Page 2525
Archive & Backup: gtarArchive & Backup: gtar Very often we would like store an archive Very often we would like store an archive
of your files (source codes, reports).of your files (source codes, reports). gtar is an utility to compress a set of files gtar is an utility to compress a set of files
to an archive (or vice versa).to an archive (or vice versa). Compress: Compress: gtar zcvf [archive name] [file list]gtar zcvf [archive name] [file list]
Expand: Expand: gtar zxvf [archive name]gtar zxvf [archive name]
Page Page 2626
Managing Print QueuesManaging Print Queues
You can check and remove print jobs You can check and remove print jobs onlyonly on UNIX (even jobs from XP) on UNIX (even jobs from XP)
Check print queue & find print job IDCheck print queue & find print job IDlpq –P[printer name]lpq –P[printer name]
Remove the job from the queueRemove the job from the queuelprm –P[printer name] [job ID]lprm –P[printer name] [job ID]
Print a postscript file directlyPrint a postscript file directlylpr –P[printer name] [postscript file]lpr –P[printer name] [postscript file]
Check print quotasCheck print quotasprintquotaprintquota
Page Page 2727
Using “man”Using “man”
The command The command manman will display the manu will display the manual of other commands.al of other commands.e.g. e.g. man lsman lsexplains the details & options with explains the details & options with lsls
dd,,ff: Forward; : Forward; bb,,Ctrl+bCtrl+b: back: back //: search for keywords in the manual: search for keywords in the manual
nn: next matched items: next matched items qq: quit: quit
Page Page 2828
Email Client: PineEmail Client: Pine
Pine is a fast, simple and easy-to-use Pine is a fast, simple and easy-to-use email client on UNIX systems.email client on UNIX systems.
With a simple terminal, you can check and With a simple terminal, you can check and send emails everywhere.send emails everywhere.
You will never be afraid of being infected You will never be afraid of being infected by unknown attachment from emails!by unknown attachment from emails!
You can also edit your own email filter You can also edit your own email filter script for efficient categorization. (ref: script for efficient categorization. (ref: procmail)procmail)
Page Page 2929
Pine: InterfacePine: Interface
Page Page 3030
Pine: Compose EmailPine: Compose Email
Page Page 3131
Pine: Read EmailPine: Read Email
Page Page 3232
Pine: Read AttachmentPine: Read Attachment
Demo 2Demo 2
File PermissionFile PermissionEmail: PineEmail: Pine
Page Page 3434
Powerful Editor: VIMPowerful Editor: VIM
VIM is one of the most powerful text editoVIM is one of the most powerful text editor in which you can enter the most letters r in which you can enter the most letters with less number of keystrokeswith less number of keystrokes
Syntax highlight is available in nearly all lSyntax highlight is available in nearly all languages you will use hereanguages you will use here(C, C++, Java, Pascal, HTML, PHP, SQL)(C, C++, Java, Pascal, HTML, PHP, SQL)
Automatic backup (.swp file)Automatic backup (.swp file) Highly customizableHighly customizable Strong support communityStrong support community
including
Page Page 3535
Modes in VIMModes in VIM
In normal mode of VIM, you issue commIn normal mode of VIM, you issue commands instead of inserting letters.ands instead of inserting letters.
You can enter to insert mode by pressinYou can enter to insert mode by pressing <i>, <a>, <o>, etc ..g <i>, <a>, <o>, etc ..
Insert mode, you can type as you do in nInsert mode, you can type as you do in notepad.otepad.
Return to normal mode by pressing <EscReturn to normal mode by pressing <Esc>>
Page Page 3636
Modes in VIM (Cont)Modes in VIM (Cont)
INSERT
visual
COMMAND<i>, <a>, <o><i>, <a>, <o>
<Esc><Esc>
type your codes
edit your text
copy & paste
formatting
Page Page 3737
Move around (Command Mode)Move around (Command Mode)
You can use cursor keys or You can use cursor keys or <h> = left; <l> = right; <h> = left; <l> = right; <j> = down; <k> = up<j> = down; <k> = up
<Ctrl-u> = <Ctrl-u> = uup half pagep half page<Ctrl-d> = <Ctrl-d> = ddown half pageown half page<Ctrl-b> = <Ctrl-b> = bback 1 pageack 1 page<Ctrl-f> = <Ctrl-f> = fforward 1 pageorward 1 page
Page Page 3838
Move around (Command Mode)Move around (Command Mode)
<$>: end of line; <^>: beginning of line; <<$>: end of line; <^>: beginning of line; <0>: first position.0>: first position.
<{no}G>: go to line {no}<{no}G>: go to line {no} <gg>: beginning of file<gg>: beginning of file <G>: end of file<G>: end of file
Page Page 3939
Save & QuitSave & Quit
<ZZ>: write file and exit (time to sleep!)<ZZ>: write file and exit (time to sleep!) <:w>: save with same name<:w>: save with same name <:q>: quit<:q>: quit <:wq>: save and quit<:wq>: save and quit When you add ‘!’ at the end of w or q, When you add ‘!’ at the end of w or q,
you force to execute the command.you force to execute the command. <:sav {filename}>: save as.<:sav {filename}>: save as.
Page Page 4040
Deleting ... Undo / RedoDeleting ... Undo / Redo <d{type}>: delete 1 object of {type}<d{type}>: delete 1 object of {type} <dd>: delete a line<dd>: delete a line <dw>: delete one word<dw>: delete one word <d3w>: delete 3 words<d3w>: delete 3 words <y{type}>: yank (copy) 1 object<y{type}>: yank (copy) 1 object <yy>: copy a line to buffer<yy>: copy a line to buffer <p>: paste the buffer content<p>: paste the buffer content <u>: undo<u>: undo <Ctrl-r>: redo<Ctrl-r>: redo
Page Page 4141
NNTP News Reader: TinNNTP News Reader: Tin
Most of our courses have newsgroup Most of our courses have newsgroup in the NNTP server.in the NNTP server.
Tin is fast, simple and easy-to-use Tin is fast, simple and easy-to-use news reader on UNIX.news reader on UNIX.
Tin keeps you with the latest news Tin keeps you with the latest news from courses (hints? delay?).from courses (hints? delay?).
Check and post your news Check and post your news everywhere with a terminal.everywhere with a terminal.
Page Page 4242
Pin: NG SubscriptionPin: NG Subscription
Page Page 4343
Tin: Reading NewsTin: Reading News
Page Page 4444
Tin: Posting News (VIM)Tin: Posting News (VIM)
Demo 3Demo 3
Powerful Editor: VIMPowerful Editor: VIMNews Reader: TINNews Reader: TIN
Page Page 4646
Lab Exercise 3: Internet UtilitiesLab Exercise 3: Internet Utilities1.1. Use Use pinepine to send an email to me ( to send an email to me (wctangwctang) usin) usin
g the subject “Y07 [g the subject “Y07 [usernameusername]”]”2.2. Use Use tintin to subscribe the newsgroup to subscribe the newsgroup cuhk.tecuhk.te
stst Use VIM to edit and post in this group.Use VIM to edit and post in this group.
Q & A / Free Chat Q & A / Free Chat
Thank you for your attention!Thank you for your attention!
See you all again in ERG2020B!