




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
21Unix實務Ka-Lok Ng (吳家樂)Department of BioinformaticsTaichung Healthcare and Management U.tw(O)04-23323456 x1856圖資大樓 3408 室教學目標Teach the student how to use Linux system using TEXT mode and set up a secure computing environment.課程大綱Red Hat Linux operating system, basic Unix command: file and directory, vi editor, Shell的種類, system performance, system security, firewall (iptables, SQUID)評量方式專題分數佔30%,平常分數10% (習題繳交和學習勤惰考核),期中考分數佔30,期末考分數佔30。193/02/1593/02/21History of Unix, Simple UNIX command293/02/2293/02/28File system393/02/2993/03/06File and Directory Permission493/03/0793/03/13Pipe and Filter593/03/1493/03/20sort排序693/03/2193/03/27萬用字元 (Wild card 或 Metacharacter)、正規表示法、搜尋指令grep793/03/2893/04/03工作控制(Process Control)893/04/0493/04/10vi 編輯器993/04/1193/04/17Mid-term1093/04/1893/04/24Shell的種類, Unix的環境設定檔1193/04/2593/05/01Linux平台安全技術, Linux防火牆(iptables, SQUID)1293/05/0293/05/08資訊安全技術及標準, 對稱式金鑰,非對稱式金鑰, PHP and MySQL1393/05/0993/05/15專題分組報告1493/05/1693/05/22專題分組報告1593/05/2393/05/29專題分組報告1693/05/3093/06/05專題分組報告1793/06/0693/06/12專題分組報告1893/06/1393/06/19Final examinationTERM PAPER TOPICS 專題題目例如:Apache+PHP+MySQL, Samba server, Firewall (iptables), E-mail server, FTP server, Proxy server, system performance (benchmark) 。 評分:l Powerpoint及word書面報告一份 。l 分組口頭報告約30分鐘,每組最多三人。l 書面報告一份 (報告需有班級、題目、目錄、內容、總結、參考文獻)l 不可全部抄襲他人結果(如論文,網頁內容),多用自己的文字寫。參考文獻l 吳佳諺工作室,Red Hat Linux 8玩家寳典,文魁出版 NT 690l 翁仲岳編著,Unix完全參考指南,文魁出版 NT 6901.1History of Unix- 1978 AT&T, Bell Lab. /- by Ken Thompson and Dennis Ritchie- Resource sharing, open system- Two versions of Unix : BSD (Berkeley), SVR4 (System V Release 4, AT&T) - TCP/IP protocol- Commercial Unix : IBM AIX, HP HP-UX, Silicon Graphics IRIX, Sun Microsystem Solaris, DEC - Ultrix- Free Unix Linux (L. Torvalds), FreeBSD- Free Softwares (Richard Stallman), GNU= GNUs Not Unix, 自由軟體基金會, GPL =General Public LicenseSome peoples home pages/unix/1.2The uniqueness of UNIXThe features that made UNIX a hit from the start are: Multitasking capability Multi-users capability Portability UNIX programs Library of application software Multitasking capabilityLets a computer do several things at once.Multi-usersThe same design that permits multitasking permits multiple users to use the computer. The computer can take the commands of a number of users System portabilityA major contribution of the UNIX system was its portability, permitting it to move from one brand of computer to another with a minimum of code changes. UNIX tools-UNIX comes with hundreds of programs -UNIX e-mail-UNIX systems around the world were linked into a world wide web decades before the development of todays World Wide Web.Applications librariesToday there are hundreds of UNIX applications that can be purchased from third-party vendors, in addition to the applications that come with UNIX.1.3How UNIX is organizedThe UNIX system is functionally organized at three levels: The kernel, which schedules tasks and manages storage; The shell, which connects and interprets users commands, calls programs from memory, and executes them; and The tools and applications that offer additional functionality to the operating system UserUserUserReferences/history/unix/tutorial.htmlUnix/Linux commandHow to login in ?Software : Netterm, Netscape or IEIP address : 192.168.xxx.xxx 0Username : testPassword : 111111Use the delete key, not backspace key to correct typo error.Terminal type 查詢你用的Shell程式及終端機型態Unix指令皆小寫,參數皆大寫$ env|more$ echo $SHELL$ echo $TERM$ setenv TERM vt100 (In Unix, every object is a file !)Commandn 查詢有關自己的資料n 查詢系統使用狀況$ mkdir your-seat-number.dir (mkdir means make directory, for example mkdir 05.dir)$ whoamialbert$ who am Iroot pts/1 Oct 3 16:18$ iduid=503(albert) gid=0(root) 群組=0(root)$ users (何人在線上 ?)albert$ who (何人在線上 ? )albert pts/1 Oct 3 16:18 (41)$ w (何人在線上 ? )4:26pm up 3 days, 4:41, 1 user, load average: 0.00, 0.00, 0.00USER TTY FROM LOGIN IDLE JCPU PCPU WHATalbert pts/1 41 4:18pm 1.00s 0.40s 0.08s wThe JCPU time is the time used by all processes attached to the tty. It does not include past background jobs, but does include currently running background jobs.The PCPU time is the time used by the current process, named in the what field.$ man w$ finger$ users$ tty (終端機名稱)$ dateFile system/ means the root directoryother directoriesbin/ dev/ home/ lost+found/ proc/ sbin/ usr/boot/ etc/ lib/ mnt/ root/ tmp/ var/(根目錄, root directory)bin/boot/dev/etc/home/libproc/ .albert/st3c/file1, file2 n 關於directory 及file 的事實n 系統中有那些目錄, 目錄中有多少個檔案, 檔案的名稱, date of creation, size (in block or in Bytes), file type (executable, text, symbolic link), access permission (存取權限, read, write, executable), 檔案擁有人, 檔案所屬群組, 檔案壓縮commandmeaning$ pwdpresent working directory$ cd /change directory$ lslist files and directories$ ls -aCF* means executable files, means symbolic link, / means directory, empty means file$ cd /bin$ ls -alist all the files, include hidden files。 . 代表目前的目錄 , . 代表上一層目錄The ls command $ ls a $ ls a /$ ls a /home$ ls t*( * 萬用字元, wild card)$ ls -aF$ cd /bin; ls l(long list, files rwxrwxrwx, directory drwxrwxrwx, symbolic link lrwxrwxrwx)$ ls s( s means count the file block size, 1 block = 1024 Bytes)$ ls -sF$ ls CF( list file names in column )$ ls a /home$ ls ar(r means reversing the alphabetic order)$ ls artl(rt means reversing the time order)$ ls R(R means recursive遞迴地列出)$ ls -R /etc(ls R /bin 或 ls-R /home)$ touch test( 產生一檔案,大小為 0 byte)$ cd( change to the default working directory, /home/st3c/ )ExerciseStep 1cd 座號.dirStep 2use the touch command to create files : file1 then file2.Step 3Use ls t and other option, list file1 and file2 in sequential order (time and alphabetic order).n du(present working directory & sub-directories usage, same as du k, in block = 1kB = 1024 Bytes)$ du -s .(s means total size in blocks, . means the current directory)$ du b .(b means size in Bytes)$ du s /etc(permission denied)(do not try du s / , because it may take a long time !)$ du /etc(some of the files have no permission, 不能給出沒有讀取權限的檔案)$ df( disks free磁碟空間, same as df k, in block = 1kB = 1024 Bytes)Filesystem 1k-blocks Used Available Use% Mounted on/dev/hda8 257598 29278 215016 12% /dev/hda1 19485 2278 16201 12% /boot/dev/hda6 909178 306460 555747 36% /home/dev/hda5 909178 352616 509591 41% /usr/dev/hda7 257598 9792 234502 4% /var|disk devicetotal sizeused可用百分比mount pointFile compression$ compress v today( v means 列出壓縮百分比)today: - replaced with today.Z Compression: 44.64%$ compress d today.Z( d means decompress 解壓縮)$ gzip v todaytoday: 63.3% - replaced with today.gz$ gzip d filename.gz( d means decompress 解壓縮)File and Directory Permissionalbertimlinux $ ls -ltotal 4drwxr-xr-x 2 albert root 1024 Sep 18 11:32 J Builer-rw-r-r- 1 albert adm 605 Sep 5 14:54 Xrootenv.0-rwxrwxrwx 共十個欄位12345678910-rwxrwxrwxd,l,-,b,c,p,sownergroupothers檔案類型擁有人, 所屬群組其它使用者d means directory, l means symbolic link, - means file, b means 區塊式特殊檔, c means字元式特殊檔, p means pipe, s means socket變更檔案存取權限u=user, g=group, o=others, a=all, +=add, -=remove, = =set, r = read, w = write, x = execute,$ chmod ugo+rwx filename ( chmod = change mode, 即變更檔案存取權限, ugo+rwx = 檔案開放給所有使用者使用)$ ls -l$ chmod ugo-rwx filename$ ls lPermission type存取權限PermissionBinaryBase 10- - -0000- - x0011- w -0102- w x0113r - -1004r x1015r w -1106r w x1117$ chmod 755 filename(存取權限 rwxr-xr-x)$ chmod 744 filename(存取權限 rwxr-r-)umask指令設定初始檔案和目錄存取權$ umask22binary representation of umask value : 022022000010010+777+111111111755111101101in terms of rwx初始目錄存取權rwxr-xr-x022000010010+666+110110110644110100100初始檔案存取權rw-r - -r- -File and directory make, copy, rename, delete, readn 目錄與檔案 - 產生、拷貝、重新命名、刪除及閱讀$ mkdir mydir.dir$ mkdir /tmp/mydir.dir$ cp .login login.copy$ ls al$ cp .cshrc cshrc.copy$ cp login.copy cshrc.copy dir2.dir$ ls l dir2.dir$ mv login.copy new.login$ ls l $ mkdir test.dir$ rm test.dir$ rm file1 file2( 小心使用 rm 指令 !)$ rm i file1(interactive mode)Unix commandOptionmkdir -m 744 cp cp options source file target file cp options source dir. target dir.例cp vR sfile tfile cp vR sdir tdirmv mv v sdir tdirrm rm vi filename閱讀檔案內容$ head 4 .cshrc(head n filename)$ tail n file1 file2$ cat file1$ more file1$ more /etc/passwdFile type$ cd /usr$ ls -F$ file tmp$ cd lib練習:使用 file查詢lib內檔案類型Pipe and Filter管線與過濾器 (, , , | )input append or test(將ls l輸出至檔案 test)$ more test$ wc wc-cshrc$ cat wc-cshrc$ wc l .cshrc(計算 .cshrc檔案行數, lines)$ wc w .cshrc(計算 .cshrc檔案字數, words)$ wc c .cshrc(計算 .cshrc檔案字元數, characters)Q. Find the total number of files in a directory. 目前目錄內有多少個檔案 ?$ ls l $ ls l |wc -lQ. Find the total number login users . 系統目前有多少個使用者連線 ?$who$who|wc lQ.Find the total number of users account. 系統內有多少個帳號 ?$cat /etc/passwd練習題:Find the total number of symbolic link files under /lib. _個。sort排序 - 按資料的字母排序規則 :字母大寫字母小寫數字排序$sort-bomit blank-d以字典排序-f忽略大小寫-n以數字由小至大排序-r顛倒排序$cd /$ls lCF$ls lCF | sort fQ. 目錄中那一個檔案最大 ?$cd /home$ls s$ls s | sort n$ls s | sort nr | head 10( sort the top 10 files )練習題:請將/boot目錄下的檔案及檔案夾按英文字母(不分大小寫)順序排列。 使用指令為: _。查詢Unix 指令使用之方法 說明頁aproposwhatisman man kman fSystem V Unix說明維護頁組織節區號碼範圍指令*1使用者命令ls, chmod1M系統維護命令infocmp2系統呼叫umask3程式庫TclCommandWriting4維護用檔案fd5雜項groff_font6遊戲intro7I/O及特殊檔Samba8維護命令bdflush*使用 apropos disk, apropos device, apropos game, apropos io, apropos 7, apropos 1m 查詢練習題:請寫出ls 的說明頁(man page)行數、字數及字元數。使用之指令: _,行數 _,字數 _,字元數 _。萬用字元 (Wild card 或 Metacharacter)、正規表示法、搜尋指令grep1. 萬用字元使用方法 ( ? * )2. 搜尋指令grep及正規表示法(Regular Expression)1.萬用字元使用方法*表示配到任何長度字串或數字?表示配到任何單一字元$ cd /$ ls $ cd h*$ cd b*(有error,因為bin及boot兩個目錄均為b開始 )$ echo *$ echo h*$ ls ?lan(輸出 flan plan )$ ls plan?(輸出 plane plans )$ ls ?a?d(輸出 card land )$ ls arrow*(輸出 arrow arrows )$ ls a*ow (輸出 allow arrow )$ ls b* c*(輸出 bon boot c )$ ls d b* d*$ ls d bd*( 對單一字元範圍配對)$ ls d bd *(不能有空格)$ ls d a-z*(對a到z字元範圍配對)$ ls d a-m*(對a到m字元範圍配對)$ ls -d *+*特殊符號 Special character ( $ ; () )$ echo $shell($ 代表輸出變數值)$ echo $shell (英文稱謂Quotes,代表輸出的內容,包括空白及不理會特殊符號)$ echo * *shell$ echo Your dir is pwd(英文稱謂Back Primes或 grave symbols,代表輸出內的指令內容)$ ls; ls a; ls A(; 代表連續執行多個指令)$ (echo my home directory; pwd; ls)home.txt(英文稱謂Parentheses,()把多個指令組合在一起,通常把結果的內容,輸出至一檔案儲存)$ echo *( 英文稱謂Backslash,代表不理會特殊符號的正常功能)$ echo $shell2. 搜尋指令grep及正規表示法(Regular Expression)grep 用來搜尋檔案內某些字串使用語法: grep 選項(n 代表列出行數) 搜尋之字串 檔案名先查看 /etc/passwd內容標記法意義例A如A, Agrep A /etc/passwd/ 或 : 或 !如 ./. 或 .:. 或 .!.grep n / /etc/passwd:2如 :2grep n :2 /etc/passwd特殊符號 grep n /etc/passwd*特殊符號 *grep n * /etc/passwd | wc特殊符號 grep n /etc/passwd$特殊符號 $grep n $ /etc/passwd特殊符號 grep n /etc/passwd特殊符號 grep n /etc/passwdst行首字為st開頭(必需完全相同)grep n st /etc/passwdot:$行尾字為ot:結尾(必需完全相同)grep n ot:$ /etc/passwdc*c出現0次或以上grep n 9* /etc/passwd列出所有的,因為9可以出現0次 搜尋指令egrep尋找多種樣式,egrep = expression grep標記法意義例a|ba或begrep y|z /etc/passwda|b|ca或b 或cegrep x|y|z /etc/passwdc+c出現一次或以上egrep 9+ /etc/passwd搜尋結果等於grep 99* /etc/passwd練習題:用grep搜尋檔案。 於ls 的說明頁內user這個字曾出現於多少行中? _行。又請問符號*共出現於ls 的說明頁多少次? _次。工作控制(Process Control)$ jobs$ ps終止及啟動工作$ vi testctrlz$ jobs(there are suspended jobs)$ fg(foreground)$ jobs(no more jobs)$ ls allsal.txt&(& means background jobs)$ vi test1 及ctrlz$ vi test2及ctrlz$ vi test3及ctrlz$ jobs(three suspended jobs)$ %1 或 fg%1正在執行的工作 (Process Status, ps, BSD選項:a,x)$ ps(顯示連上此系統之terminal user所有正在執行的工作)PID TTY TIME CMD 10702 pts/0 00:00:00 csh10863 pts/0 00:00:00 psPID = Process IDTTY = 正在執行此工作的TerminalTIME = 此工作至目前所需執行的時間CMD = 指令$ ps x(列出user透過或不透過terminal連線之工作狀態及正在執行的工作等資訊)$ ps u(usage, 列出user名字、CPU、RAM、工作狀態等資訊)USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDalbert 28663 0.0 3.5 2824 1100 pts/0 S 16:01 0:00 -cshalbert 28702 0.0 2.8 2512 876 pts/0 R 16:26 0:00 ps u工作狀態STAT意義RRunning執行中SSleeping暫停執行TTraced or stopped停止執行ZZombies已被結束之工作,但其父工作未正常停止此工作$ ps a(all, 顯示連上此系統之terminal user及其它users正在執行的工作)$ ps ax| more(此系統所有正在執行的工作)$ ps e| more(此系統所有正在執行的工作)$ ps el | more(long list 此系統所有正在執行的工作)$F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD100 S 0 1 0 0 60 0 - 274 do_sel ? 00:00:04 init040 S 0 2 1 0 60 0 - 0 bdflus ? 00:00:04 kflushd040 S 0 3 1 0 60 0 - 0 kpiod ? 00:00:00 kpiodPPID = Parent Process IDPRI = PriorityNI = Nice Value$ nice -5 wc l filename移除正在執行的工作$ ps(先查詢正在執行的工作)$ kill PID$ kill 9 PID資訊及檔案搜尋 (find)$ find . name string print(從現在的目錄開始搜尋csh出現於那個檔案夾,並顯示結果)$ find / -name csh print(從/目錄開始搜尋csh出現於那個檔案夾,並顯示結果)$ find . mtime 7 print(搜尋exactly 7天前被更改的檔案)$ find . mtime -7 print(搜尋 less than 7天前被更改的檔案)$ find . mtime +7 print(搜尋 longer than 7天前被更改的檔案)比較兩個檔案的差異 diff$ diff filename1 filename2檢查拼字 spell$ spell v filename(顯示所有拼錯的字)別名alias (execute in the present shell only)使用別名定義新命令完成你要達成的工作$ alias(查詢系統已定義的別名)$ alias lsa=ls a ( for bash, need = sign)$ alias lscf=ls CF$ alias(查詢新增的別名)$ unalias lscf(刪除已定義的別名lscf)vi 編輯器兩種模式1. 命令模式(command mode)2. 插入模式(insert mode),可開始編輯文件內容使用字母選項插入模式命令$ vi 進入 Esc鍵$ ls l demo$ vi demo離開vi、冒號(:)的配合指令、透過!與Unix溝通vi 編輯時並不是直接修改文件內容,而是把檔案拷貝至系統的進行buffer修改,直到要儲存編輯的內容時,才把buffer內容寫入檔案。 故此你可以不作修改,使檔案維持原貌。指令結果:w 儲存檔案:w file1儲存至file1檔案:q離開vi,不作任何自上次使用w後的更改:q!離開vi,不作任何更改:wq儲存檔案及離開vi:set nu顯示文件中的每一行的號碼:set nonu不顯示文件中的每一行的號碼:r file1在目前位置加入file1所有內容:e filename開啟另一檔案編輯:!ls /暫時離開vi,使用單一Unix指令查詢,如列出/ 的檔案:sh完成後按Ctrl+d暫時離開vi,可使用多個Unix指令查詢,完成後按Ctrl+d回到vi:n,k w file1將文件中第n行至第k行儲存至file1新檔案:n,k w! file1將文件中第n行至第k行儲存至file1已存在檔案:n,k wfile1將文件中第n行至第k行附加至file1檔案移動游標 使用keyboard的箭頭移動游標。在頁間移動游標$ ls l output$ vi output按鍵結果Ctrl+fForward游標向下移動一個畫面Ctrl+bBackward游標向上移動一個畫面Ctrl+uUp游標向下移動半個畫面Ctrl+dDown游標向上移動半個畫面nG游標移至第n行G游標移至檔案尾端w游標移至下一個字的開頭b游標移至上一個字的開頭或0游標移至行首$游標移至行尾編輯檔案及刪除文字指令結果iInsert游標前插入文字aAppend游標後插入文字oOpen a new line游標下方開一新行OOpen a new line游標上方開一新行rreplace取代字元r 檔名游標下方加入另一檔案內容至本檔案cwchange word更改字串cc更改一整行的內容JJoin游標所在的一行與下一行合併x刪除游標所在字元#x刪除游標所在及之後3個字元dwDelete word刪除一個字(word)DDelete刪除自游標行尾所有文字dd刪除一整行3dd配合ppaste 刪除三整行在游標下方貼上三整行內容(搬移)3yy配合pYank, Copy 3 lines拷貝三整行在游標下方貼上三整行內容uundo回復剛才修改的一個動作U回復游標所在一整行的更改動作搜尋與取代指令結果/hello再按n 代表nextN往後搜尋檔案中hello一字搜尋檔案中下一個hello一字搜尋檔案中前一個hello一字?hello再按n代表nextN往前搜尋檔案中hello一字搜尋檔案中前一個hello一字搜尋檔案中下一個hello一字:1,$ s/a/A/g從第一行至最後一行的所有”a”取代為”A”,g代表global即全部:!sed s/在每一行行首加入”$ vi r filename(file recover)$ vi +3 filename(move vi to the 3rd line)$ vi +$ filename(move vi to the last line)$ vi Rfilename(read only, cannot edit)$ vi +/usr filename(move to /usr)練習題:先切換至你的目錄,然後使用vi建立下列內容的檔案(可用中文或英文)。Name : ? ? ?student ID: ?I am a year three student at Ling Tung College, major in Information Management.I am a year three student at Ling Tung College, major in Information Management.I am a year three student at Ling Tung College, major in Information Management.I am a year three student at Ling Tung College, major in Information Management.I am a year three student at Ling Tung College, major in Information Management.Name :Sex :Birthday :Education :Working Experience :.在此處加入ls l / 檔案內容至本檔案。註:利用yy及p兩個指令拷貝及貼上其它基本指令 ( # 代表 root 的權限)$ whereis ls /bin/ls$ tree directory_name list contents of directories in a tree-like format$ uname -aprint system information (Linux kernel information)$ dmesg|more
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- DB6103T 49-2023 中华蜜蜂养殖技术规范
- 2025年护士节知识竞赛考试练习题完整及答案解析
- 2025年主管护师考试必考点试题及答案
- 防火门及防火卷帘的施工方案
- 2025年市场监督管理局工作人员招聘考试笔试试题(附答案)
- 李清照诗词高中课件
- 清远展位工程方案(3篇)
- 李清照的渔家傲课件
- 机电安装工程空白合同4篇
- 辞职员工补偿协议格式内容4篇
- 2024年绍兴职业技术学院军训动员大会校长发言稿9000字
- 泌尿科膀胱灌注护理课件
- 脊柱区课件教学课件
- 人证考试题库及答案广州
- 2025医养结合笔试题及答案
- 烧结基础理论课件
- 《家庭教育学》全套教学课件
- 村集体经济培训课件
- 文明礼貌课件模板
- 直流输电技术试题及答案
- 医院清洁消毒灭菌与隔离无菌操作技术
评论
0/150
提交评论