Successfully reported this slideshow.
Introduction to Linux (I) Prof. Chung-Ta King Department of Computer Science National Tsing Hua University CS1103  電機資訊工程實...
Outline <ul><li>Overview of Unix System </li></ul><ul><li>Basic Commands </li></ul><ul><li>Relative  and  Absolute Path </...
What Is Linux? <ul><li>Linux  是一套自由、開放、免費的作業系統 </li></ul><ul><ul><li>開放源碼  (open source) :可以任意的修改  Linux -從最底層的核心以至於上層的應用程...
Linux Distributions <ul><li>許多 Linux 發行版本 :  SuSe, Gentoo, Fedora, Debian , Ubuntu, … </li></ul><ul><ul><li>核心都是 Linux ker...
Why Linux? <ul><li>Used in many servers and embedded systems </li></ul><ul><ul><li>Web servers, mail servers, firewalls, p...
Installing Linux <ul><li>Traditional way: installing Linux from CD ROM on hard disk partitions  </li></ul><ul><li>Use virt...
Linux 系統結構 <ul><li>Linux 作業系統由以下幾個部分所組成: </li></ul>Hardware Applications X-window Apps 電腦硬體 系統層級的應用程式與管理工具 這裡又可以區分成專門作為網路服...
Linux from Users’ Perspective <ul><li>Underneath the windows GUI system, users interact with Linux kernel through  shell <...
Directory Structure <ul><li>Linux 統一由 / (root) 作為根目錄,系統內所有的目錄都依附在 /  底下 </li></ul><ul><ul><li>不同的硬碟或分割區  (partition) ,也都在 ...
Directory Structure
Important Directories <ul><li>/bin :  contains files that are essential for correct operation of the system </li></ul><ul>...
Other Things to Know <ul><li>Normal user and  s uper user : </li></ul><ul><ul><li>T here is one special user for administr...
Basic Commands <ul><li>When you  interact with shell , you will see s the prompt, something like king@my_pc:~$ </li></ul><...
Basic Commands <ul><li>ls show files in current position </li></ul><ul><li>cd change directory </li></ul><ul><li>cp copy f...
Basic Commands <ul><li>su switch  to super user </li></ul><ul><li>passwd  change password </li></ul><ul><li>mount mount fi...
Relative  and  Absolute Path <ul><li>Path means a position in the directory tree </li></ul><ul><li>T w o  ways to  express...
Other Features of Shell <ul><li>Take bash as an example: </li></ul><ul><ul><li>It supports h istory, command line editing,...
Other Features of Shell <ul><li>Wildcard: </li></ul><ul><ul><li>? : a single character </li></ul></ul><ul><ul><li>*  : zer...
Redirect and Append <ul><li>Redirect and append </li></ul><ul><ul><li>Output of command is displayed on screen </li></ul><...
Pipe <ul><li>Pipe </li></ul><ul><ul><li>Some commands require input from a file or other commands </li></ul></ul><ul><ul><...
Permission  <ul><li>All of files and directories have owner and permission  </li></ul><ul><ul><li>T hree types of permissi...
Permission  <ul><li>Command : </li></ul><ul><ul><li>c hmod :  change file mode, add or remove   permission  </li></ul></ul...
Process Management <ul><li>Process is a unit of running program </li></ul><ul><li>Each process has some information, like ...
Process Management <ul><li>k ill : s top a program </li></ul><ul><ul><li>The program is   specified by process ID </li></u...
Foreground and Background <ul><li>Running job has two modes, “foreground” and “background” </li></ul><ul><li>B ackground  ...
Remote Login  and  File Transfer <ul><li>rshd, telnetd, ftpd, sshd are server program to provide remote login and file tra...
Text Editor : vi <ul><li>vi  共分為三種模式: </li></ul><ul><ul><li>一般模式 </li></ul></ul><ul><ul><li>編輯模式 </li></ul></ul><ul><ul><l...
Text Editor : vi 切換回『一般模式』 [ESC] 在『游標位置』建立空白行 [ O ] 產生『下一行』空白行 [ o ] 從『行尾』開始編輯 [ A ] 從『下個字元』開始編輯 [ a ] 從『行首』開始編輯 [ I ] 從『目...
Text Editor : vi 刪除『游標前一個字元』 [ X ] 刪除『目前游標字元』 [ x ] 跳到『下一個字』 [ w ] 到『檔尾』 [ G ] 到『行尾』 [ $ ] 到『檔頭』 [ 1G ] 到『行首』 [ 0 ] 一般模式
Text Editor : vi 刪除至『行尾』 [ d ] [ $ ] 刪除至『行首』 [ d ] [ 0 ] 刪除一整行 [ d ] [ d ] 刪除 [ d ] 複製一整行 [ y ] [ y ] 複製 [ y ] 跳到『 NUM 』行 ...
Text Editor : vi 『復原』上一個動作 [ u ] 貼上 [ p ] 剪下  /  刪除 [ x ] 取代『一個』字元 [ r ] [d] + [3] + [w]  刪除三個字 [..] + [ NUM ] + [..] [3] ...
Text Editor : vi 『強制』不儲存離開 [ : ] [ q ] [ ! ] 不儲存離開 [ : ] [ q ] 『強制』儲存檔案後離開 [ : ] [ w ] [ q ] [ ! ] 儲存檔案後離開  ( 『 :x 』或『 ZZ ...
Text Editor : vi 將每行的開頭都往後移四個空白 :1,$s/^/  /g 將『整個檔案』的  [old]  替換成  [new] :1,$s/[old]/[new]/g 將『第一行』至『第三十行』的  [old]  替換成  [...
Install Software <ul><li>Unix system has a “de facto standard” way to install a software : configure     make    make in...
Install Software <ul><li>gzip compress a file </li></ul><ul><li>gunzip uncompress a file </li></ul><ul><li>tar archive or ...
Upcoming SlideShare
Loading in …5
×

Chapter 1

860 views

Published on

  • Be the first to comment

  • Be the first to like this

Chapter 1

  1. 1. Introduction to Linux (I) Prof. Chung-Ta King Department of Computer Science National Tsing Hua University CS1103 電機資訊工程實習 (Contents from 陳晏瑨 (http://yenjinc.info), Dr. Sven Hessler, Prof. Cédric Notredame)
  2. 2. Outline <ul><li>Overview of Unix System </li></ul><ul><li>Basic Commands </li></ul><ul><li>Relative and Absolute Path </li></ul><ul><li>Redirect, Append and Pipe </li></ul><ul><li>Permission </li></ul><ul><li>Process Management </li></ul><ul><li>Install Software </li></ul><ul><li>Text Editor </li></ul><ul><li>Foreground and Background Jobs </li></ul>
  3. 3. What Is Linux? <ul><li>Linux 是一套自由、開放、免費的作業系統 </li></ul><ul><ul><li>開放源碼 (open source) :可以任意的修改 Linux -從最底層的核心以至於上層的應用程式 </li></ul></ul><ul><li>Linux 的由來 </li></ul><ul><ul><li>UNIX : 1970 年代由 Bell Lab 發展出來,並廣泛使用於當時的 minicomputers 和 workstations 上 </li></ul></ul><ul><ul><li>但當時的 UNIX 只能在特定的主機上運行,並且有版權的問題 </li></ul></ul><ul><ul><li>Andrew Tanenbaum 為了 OS 之教學,根據 UNIX 重新撰寫一套可在 PC 上運行的系統 Minix (1986) </li></ul></ul><ul><ul><li>1991 年 Linus Torvalds 又改寫 Minix 成為 Linux </li></ul></ul><ul><ul><li>GNU 又為 Linux kernel 加上許多公用程式 </li></ul></ul>
  4. 4. Linux Distributions <ul><li>許多 Linux 發行版本 : SuSe, Gentoo, Fedora, Debian , Ubuntu, … </li></ul><ul><ul><li>核心都是 Linux kernel ,而公用程式也大都是 GNU 軟體及其他開放源碼軟體 (Open Source Software) </li></ul></ul><ul><ul><li>最主要的差別在於專屬工具及套件管理方式 </li></ul></ul>Applications/Open Source Software 套件管理 / 系統層級軟體 除了『系統層級』的軟體會有所不同以外,系統的核心及最上層的應用程式,基本上都是一樣的。 Linux Kernel Linux Distribution 簡單示意圖
  5. 5. Why Linux? <ul><li>Used in many servers and embedded systems </li></ul><ul><ul><li>Web servers, mail servers, firewalls, printer servers, wifi access points, disk servers </li></ul></ul><ul><ul><li>Google phone (Android), OpenMoko </li></ul></ul><ul><ul><li>Note: Many do not have GUI, but text mode interface </li></ul></ul><ul><li>Penetrating into desktops and notebooks with easy-to-use GUI: eeePC, OS X </li></ul>
  6. 6. Installing Linux <ul><li>Traditional way: installing Linux from CD ROM on hard disk partitions </li></ul><ul><li>Use virtualization software: VMware, QEMU, virtual box, XEN </li></ul><ul><ul><li>x86 virtualization : the method by which x86-based &quot;guest&quot; OS are run under another &quot;host&quot; x86 OS, with little or no modification of the guest OS (wiki) </li></ul></ul><ul><ul><li>For example: on Windows </li></ul></ul><ul><ul><li>ubuntu (http://www.ubuntu-tw.org) ubuntu-8.10-desktop-i386.iso </li></ul></ul><ul><ul><li>virtual box (http://www.virtualbox.org) </li></ul></ul>
  7. 7. Linux 系統結構 <ul><li>Linux 作業系統由以下幾個部分所組成: </li></ul>Hardware Applications X-window Apps 電腦硬體 系統層級的應用程式與管理工具 這裡又可以區分成專門作為網路服務的伺服器程式以及專為桌面應用的 X-window 程式,還有不隸屬上述兩種的其他程式 Server Apps 作業系統的核心 Kernel OS Utilities/Applications
  8. 8. Linux from Users’ Perspective <ul><li>Underneath the windows GUI system, users interact with Linux kernel through shell </li></ul><ul><ul><li>Shell interprets user’s input as commands and pass them to kernel </li></ul></ul><ul><ul><li>O perates in a simple loop: </li></ul></ul><ul><ul><ul><li>accepts a command </li></ul></ul></ul><ul><ul><ul><li>interprets the command </li></ul></ul></ul><ul><ul><ul><li>executes the command </li></ul></ul></ul><ul><ul><ul><li>displays a ”prompt,” to notify user that it is ready to accept the next command </li></ul></ul></ul><ul><li>使用終端機程式 </li></ul>Kernel Shell User input
  9. 9. Directory Structure <ul><li>Linux 統一由 / (root) 作為根目錄,系統內所有的目錄都依附在 / 底下 </li></ul><ul><ul><li>不同的硬碟或分割區 (partition) ,也都在 / 底下,透過 mount ( 掛載 ) 的方式,掛載起來使用 </li></ul></ul><ul><ul><li>Windows 則是由 C:, D: 的順序編排而成 </li></ul></ul><ul><ul><li>All directories are in a hierarchical structure (tree structure) </li></ul></ul><ul><ul><li>Users have the own directory (home directory) </li></ul></ul><ul><ul><li>The path is the location of a file or directory within the tree, e.g. /usr/sbin/bzip2, . ./../john, /home/john </li></ul></ul><ul><ul><li>S upport access control by defining permissions for read, write, and execution </li></ul></ul>
  10. 10. Directory Structure
  11. 11. Important Directories <ul><li>/bin : contains files that are essential for correct operation of the system </li></ul><ul><ul><li>available for use by all users </li></ul></ul><ul><li>/home : stores user home directories </li></ul><ul><li>/var : stores files which change frequently, and must be available to be written to </li></ul><ul><li>/etc : contains v arious system configuration files </li></ul><ul><li>/dev : contains various devices as files, e.g. hard disk, CD-ROM drive, etc. </li></ul><ul><li>/tmp : t emporary files </li></ul>
  12. 12. Other Things to Know <ul><li>Normal user and s uper user : </li></ul><ul><ul><li>T here is one special user for administrator, which can do anything and is called root or superuser </li></ul></ul><ul><li>Case s ensitivity : </li></ul><ul><ul><li>Linux is case-sensitive </li></ul></ul><ul><li>Multi-user and m ulti-process : </li></ul><ul><ul><li>Many people can use a machine at the same time </li></ul></ul><ul><li>File and p rocess </li></ul><ul><ul><li>Almost everything (d ata, directory, process, hard disk) are expressed as a file </li></ul></ul><ul><ul><li>Process is an running program identified by a unique id (PID) </li></ul></ul>
  13. 13. Basic Commands <ul><li>When you interact with shell , you will see s the prompt, something like king@my_pc:~$ </li></ul><ul><li>A command consists of three parts, i.e. command name, options, arguments </li></ul><ul><li>king@my_pc:~$ command-name optionA optionB arg1 arg2 </li></ul><ul><ul><li>Options always start with “-” </li></ul></ul><ul><ul><li>Example: cd .. ls –l .bashrc mv fileA fileB </li></ul></ul>
  14. 14. Basic Commands <ul><li>ls show files in current position </li></ul><ul><li>cd change directory </li></ul><ul><li>cp copy file or directory </li></ul><ul><li>mv move file or directory </li></ul><ul><li>rm remove file or directory </li></ul><ul><li>pwd show current position </li></ul><ul><li>mkdir create directory </li></ul><ul><li>rmdir remove directory </li></ul><ul><li>less, more display file contents </li></ul><ul><li>man display online manual </li></ul>
  15. 15. Basic Commands <ul><li>su switch to super user </li></ul><ul><li>passwd change password </li></ul><ul><li>mount mount file system </li></ul><ul><li>umount unmount file system </li></ul><ul><li>df show disk space usage </li></ul><ul><li>ps show current processes </li></ul><ul><li>shutdown reboot or turn off machine </li></ul><ul><li>grep XXX s how lines matching pattern XXX in File </li></ul>
  16. 16. Relative and Absolute Path <ul><li>Path means a position in the directory tree </li></ul><ul><li>T w o ways to express a path </li></ul><ul><ul><li>R elative path expression : the path depends on the current directory </li></ul></ul><ul><ul><ul><li>. : the current directory </li></ul></ul></ul><ul><ul><ul><li>.. : the parent directory </li></ul></ul></ul><ul><ul><ul><li>pwd: gives the current path </li></ul></ul></ul><ul><ul><li>A bsolute path expression : the path is defined uniquely from the root /home/linux/ ~/linux (home directory/linux) </li></ul></ul>
  17. 17. Other Features of Shell <ul><li>Take bash as an example: </li></ul><ul><ul><li>It supports h istory, command line editing, customization </li></ul></ul><ul><ul><li>Start up: .bashrc, .cshrc </li></ul></ul><ul><ul><li>Environment variables: $PATH, $PS1, $SHELL, $TERM, $EDITOR, $HOME </li></ul></ul><ul><ul><li>Moving around :  ,  , Home, End </li></ul></ul><ul><ul><li>Previous commands: ↑,↓, !!, !1, !2, !x </li></ul></ul><ul><ul><li>TAB 鍵 : shell 會自動補齊指令名稱 </li></ul></ul><ul><ul><ul><li>如果按一下沒有作用時,連按兩下, shell 會自動將名稱開頭符合的指令統統列示出來 </li></ul></ul></ul><ul><ul><ul><li>可以用於檔案補全 </li></ul></ul></ul>
  18. 18. Other Features of Shell <ul><li>Wildcard: </li></ul><ul><ul><li>? : a single character </li></ul></ul><ul><ul><li>* : zero or more characters </li></ul></ul><ul><ul><li>[b - d] : either b, c, or d </li></ul></ul><ul><ul><li>{ fconf , locg } : either ’conf’ or ’loc’ </li></ul></ul><ul><ul><li>Example: ls -d /etc/*[b-h]??.{conf,loc}?? </li></ul></ul><ul><li>^c (ctrl-c): kill the command </li></ul><ul><li>^d (ctrl-d): end the input </li></ul>
  19. 19. Redirect and Append <ul><li>Redirect and append </li></ul><ul><ul><li>Output of command is displayed on screen </li></ul></ul><ul><ul><li>Use “>” to redirect the output from screen to a file </li></ul></ul><ul><ul><li>Use “>>” to append the output to bottom of the file </li></ul></ul><ul><li>Three types of input/output </li></ul><ul><ul><li>Standard input: 代碼為 0 ,符號為 < 或 << </li></ul></ul><ul><ul><li>Standard output: 代碼為 1 ,符號為 > 或 >> </li></ul></ul><ul><ul><li>Standard error: 代碼為 2 ,符號為 2> 或 2>> </li></ul></ul><ul><li>命令執行判斷依據 </li></ul><ul><ul><li>; : 命令與命令之間的分隔符號 </li></ul></ul><ul><ul><li>&&: 當左邊的命令為 ”真”,才會執行右邊的命令 </li></ul></ul><ul><ul><li>||: 當左邊的命令 “不為真”,才會執行右邊的命令 </li></ul></ul>
  20. 20. Pipe <ul><li>Pipe </li></ul><ul><ul><li>Some commands require input from a file or other commands </li></ul></ul><ul><ul><li>Use “|” to use output from another command as input to the command </li></ul></ul><ul><ul><li>Example: ls /etc/ | sort | nl > file1.txt </li></ul></ul>
  21. 21. Permission <ul><li>All of files and directories have owner and permission </li></ul><ul><ul><li>T hree types of permission : readable, writeable and executable </li></ul></ul><ul><ul><li>Permissions are given to three kinds of group : owner, group member and others </li></ul></ul><ul><li>Example: </li></ul><ul><ul><li>ls -l .bash_profile </li></ul></ul><ul><ul><li>-rw-r--r-- 1 cnotred 191 Jan 4 13:11 .bash_profile </li></ul></ul><ul><ul><li>r:readable, w:writable, x: executable </li></ul></ul>
  22. 22. Permission <ul><li>Command : </li></ul><ul><ul><li>c hmod : change file mode, add or remove permission </li></ul></ul><ul><ul><li>c hown : change owner of the file </li></ul></ul><ul><li>Example : </li></ul><ul><ul><li>chmod a+w filename </li></ul></ul><ul><ul><li>add writable permission to all users </li></ul></ul><ul><ul><li>chmod o-x filename </li></ul></ul><ul><ul><li>remove executable permission from others </li></ul></ul><ul><ul><li>chmod a+x </li></ul></ul><ul><ul><li>Gives permission to the user to execute a file </li></ul></ul><ul><ul><li>u: user (owner) ; g: group ; o: others ; a: all </li></ul></ul>
  23. 23. Process Management <ul><li>Process is a unit of running program </li></ul><ul><li>Each process has some information, like process ID, owner, priority, etc </li></ul><ul><li>Example : Output of “top” command </li></ul>
  24. 24. Process Management <ul><li>k ill : s top a program </li></ul><ul><ul><li>The program is specified by process ID </li></ul></ul><ul><li>k illall : s top a program </li></ul><ul><ul><li>The program is specified by command name </li></ul></ul><ul><li>p s : s how process status </li></ul><ul><li>t op : s how system usage statistics </li></ul>
  25. 25. Foreground and Background <ul><li>Running job has two modes, “foreground” and “background” </li></ul><ul><li>B ackground job: the program keeps running even after your session was closed </li></ul><ul><li>F oreground job: </li></ul><ul><ul><li>c trl- c: stop program </li></ul></ul><ul><ul><li>c trl- z: let program go into background </li></ul></ul><ul><li>To run programs in background mode : king @ my_pc:~ $ command & </li></ul><ul><li>To get background job back into foreground : king @ my_pc:~ $ fg </li></ul>
  26. 26. Remote Login and File Transfer <ul><li>rshd, telnetd, ftpd, sshd are server program to provide remote login and file transfer </li></ul><ul><li>Remote login and file transfer are based on server and client model. C lient program on your machine ask sever program certain service remote machine. </li></ul><ul><li>Sample client programs; </li></ul><ul><ul><li>WS FTP FTP client </li></ul></ul><ul><ul><li>Internet Exploror HTTP client </li></ul></ul><ul><ul><li>Eudora POP, SMTP client </li></ul></ul>
  27. 27. Text Editor : vi <ul><li>vi 共分為三種模式: </li></ul><ul><ul><li>一般模式 </li></ul></ul><ul><ul><li>編輯模式 </li></ul></ul><ul><ul><li>指令列命令模式 </li></ul></ul>
  28. 28. Text Editor : vi 切換回『一般模式』 [ESC] 在『游標位置』建立空白行 [ O ] 產生『下一行』空白行 [ o ] 從『行尾』開始編輯 [ A ] 從『下個字元』開始編輯 [ a ] 從『行首』開始編輯 [ I ] 從『目前位置』開始編輯 [ i ] 編輯 ( 插入 ) 模式
  29. 29. Text Editor : vi 刪除『游標前一個字元』 [ X ] 刪除『目前游標字元』 [ x ] 跳到『下一個字』 [ w ] 到『檔尾』 [ G ] 到『行尾』 [ $ ] 到『檔頭』 [ 1G ] 到『行首』 [ 0 ] 一般模式
  30. 30. Text Editor : vi 刪除至『行尾』 [ d ] [ $ ] 刪除至『行首』 [ d ] [ 0 ] 刪除一整行 [ d ] [ d ] 刪除 [ d ] 複製一整行 [ y ] [ y ] 複製 [ y ] 跳到『 NUM 』行 [ : ] + [ NUM ] 一般模式
  31. 31. Text Editor : vi 『復原』上一個動作 [ u ] 貼上 [ p ] 剪下 / 刪除 [ x ] 取代『一個』字元 [ r ] [d] + [3] + [w] 刪除三個字 [..] + [ NUM ] + [..] [3] + [d] + [d] 刪除三行 [ NUM ] + [..] + [..] 刪除至『檔頭』 [ d ] [ 1G ] 一般模式
  32. 32. Text Editor : vi 『強制』不儲存離開 [ : ] [ q ] [ ! ] 不儲存離開 [ : ] [ q ] 『強制』儲存檔案後離開 [ : ] [ w ] [ q ] [ ! ] 儲存檔案後離開 ( 『 :x 』或『 ZZ 』 ) [ : ] [ w ] [ q ] 儲存檔案 [ : ] [ w ] 編輯新檔 [ : ] [ e ] 指令列模式
  33. 33. Text Editor : vi 將每行的開頭都往後移四個空白 :1,$s/^/ /g 將『整個檔案』的 [old] 替換成 [new] :1,$s/[old]/[new]/g 將『第一行』至『第三十行』的 [old] 替換成 [new] :1,30s/[old]/[new]/g 將所有的 [old] 替換成 [new] : s/[old]/[new]/g 向下搜尋 (n 至下一個 ) [ / ] 搜尋與取代
  34. 34. Install Software <ul><li>Unix system has a “de facto standard” way to install a software : configure  make  make install </li></ul><ul><li>Typical software installation procedure as following : </li></ul><ul><ul><li>Download source code : Usually, it’s archived with tar command and compressed with gzip command </li></ul></ul><ul><ul><li>C onfigure command creates Makefile automatically which is used to compile the source </li></ul></ul><ul><ul><li>Program compilation is written in Makefile </li></ul></ul>
  35. 35. Install Software <ul><li>gzip compress a file </li></ul><ul><li>gunzip uncompress a file </li></ul><ul><li>tar archive or expand files </li></ul><ul><li>configure create Makefile </li></ul><ul><li>make compile and install software </li></ul><ul><li>Example: </li></ul><ul><ul><li>gunzip software.tar.gz </li></ul></ul><ul><ul><li>tar –xvf software.tar </li></ul></ul><ul><ul><li>cd software </li></ul></ul><ul><ul><li>./install OR make all OR … </li></ul></ul>

×