1 / 35

Introduction to Linux (I)

CS1103 電機資訊工程實習. Introduction to Linux (I). Prof. Chung-Ta King Department of Computer Science National Tsing Hua University. (Contents from 陳晏瑨 (http://yenjinc.info), Dr. Sven Hessler, Prof. Cédric Notredame). Outline. Overview of Unix System Basic Commands

caelan
Télécharger la présentation

Introduction to Linux (I)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS1103 電機資訊工程實習 Introduction to Linux (I) Prof. Chung-Ta King Department of Computer Science National Tsing Hua University (Contents from 陳晏瑨 (http://yenjinc.info), Dr. Sven Hessler, Prof. Cédric Notredame)

  2. Outline • Overview of Unix System • Basic Commands • Relative and Absolute Path • Redirect, Append and Pipe • Permission • Process Management • Install Software • Text Editor • Foreground and Background Jobs

  3. What Is Linux? • Linux 是一套自由、開放、免費的作業系統 • 開放源碼 (open source):可以任意的修改 Linux-從最底層的核心以至於上層的應用程式 • Linux的由來 • UNIX:1970年代由Bell Lab發展出來,並廣泛使用於當時的minicomputers和workstations上 • 但當時的 UNIX只能在特定的主機上運行,並且有版權的問題 • Andrew Tanenbaum為了OS之教學,根據 UNIX重新撰寫一套可在PC上運行的系統Minix (1986) • 1991年Linus Torvalds又改寫Minix成為Linux • GNU又為Linux kernel加上許多公用程式

  4. Linux Distributions • 許多Linux發行版本: SuSe, Gentoo, Fedora, Debian, Ubuntu, … • 核心都是Linux kernel,而公用程式也大都是GNU 軟體及其他開放源碼軟體 (Open Source Software) • 最主要的差別在於專屬工具及套件管理方式 Linux Distribution 簡單示意圖 除了『系統層級』的軟體會有所不同以外,系統的核心及最上層的應用程式,基本上都是一樣的。 Applications/Open Source Software 套件管理/系統層級軟體 Linux Kernel

  5. Why Linux? • Used in many servers and embedded systems • Web servers, mail servers, firewalls, printer servers, wifi access points, disk servers • Google phone (Android), OpenMoko • Note: Many do not have GUI, but text mode interface • Penetrating into desktops and notebooks with easy-to-use GUI: eeePC, OS X

  6. Installing Linux • Traditional way: installing Linux from CD ROM on hard disk partitions • Use virtualization software: VMware, QEMU, virtual box, XEN • x86 virtualization: the method by which x86-based "guest" OS are run under another "host" x86 OS, with little or no modification of the guest OS (wiki) • For example: on Windows ubuntu (http://www.ubuntu-tw.org) ubuntu-8.10-desktop-i386.iso virtual box (http://www.virtualbox.org)

  7. Linux系統結構 • Linux作業系統由以下幾個部分所組成: 這裡又可以區分成專門作為網路服務的伺服器程式以及專為桌面應用的X-window 程式,還有不隸屬上述兩種的其他程式 Applications Server Apps X-window Apps 系統層級的應用程式與管理工具 OS Utilities/Applications Kernel 作業系統的核心 Hardware 電腦硬體

  8. User input Shell Kernel Linux from Users’ Perspective • Underneath the windows GUI system, users interact with Linux kernel through shell • Shell interprets user’s input as commands and pass them to kernel • Operates in asimple loop: • accepts a command • interprets the command • executes the command • displays a ”prompt,” to notify userthat it is ready toaccept thenext command • 使用終端機程式

  9. Directory Structure • Linux統一由/ (root)作為根目錄,系統內所有的目錄都依附在/ 底下 • 不同的硬碟或分割區 (partition),也都在/ 底下,透過mount (掛載)的方式,掛載起來使用 • Windows則是由C:\, D:\的順序編排而成 • All directories are in a hierarchical structure (tree structure) • Users have the own directory (home directory) • The path is the location of a file or directory within the tree,e.g. /usr/sbin/bzip2, ../../john, /home/john • Support access control by defining permissions for read,write, and execution

  10. Directory Structure

  11. Important Directories • /bin: contains files that are essential for correct operation of the system • available for use by all users • /home:stores user home directories • /var:stores files which change frequently, and must be available to be written to • /etc:contains various system configuration files • /dev: contains various devices as files, e.g. harddisk, CD-ROM drive, etc. • /tmp: temporary files

  12. Other Things to Know • Normal user and super user: • There is one special user for administrator, which can do anything and is called root or superuser • Case sensitivity: • Linux is case-sensitive • Multi-user andmulti-process: • Many people can use a machine at the same time • File and process • Almost everything (data, directory, process, hard disk) are expressed as a file • Process is an running program identified by a unique id (PID)

  13. Basic Commands • When you interact with shell, you will sees the prompt, something likeking@my_pc:~$ • A command consists of three parts, i.e. command name, options, arguments king@my_pc:~$ command-nameoptionA optionB arg1 arg2 • Options always start with “-” • Example:cd ..ls –l .bashrcmv fileA fileB

  14. Basic Commands • ls show files in current position • cd change directory • cp copy file or directory • mv move file or directory • rm remove file or directory • pwd show current position • mkdir create directory • rmdir remove directory • less,moredisplay file contents • man display online manual

  15. Basic Commands • su switch to superuser • passwd change password • mount mount file system • umount unmount file system • df show disk space usage • ps show current processes • shutdown reboot or turn off machine • grep XXX show lines matching patternXXX in File

  16. Relative and Absolute Path • Path means a position in the directory tree • Two ways to express a path • Relative path expression: the path depends on the current directory • . : the current directory • .. : theparent directory • pwd: gives the current path • Absolute path expression: the path is defined uniquely from the root/home/linux/~/linux (home directory/linux)

  17. Other Features of Shell • Take bash as an example: • It supports history, command line editing, customization • Startup: .bashrc, .cshrc • Environment variables: $PATH, $PS1, $SHELL, $TERM, $EDITOR, $HOME • Moving around: , , Home, End • Previous commands: ↑,↓, !!, !1, !2, !x • TAB 鍵: shell 會自動補齊指令名稱 • 如果按一下沒有作用時,連按兩下,shell 會自動將名稱開頭符合的指令統統列示出來 • 可以用於檔案補全

  18. Other Features of Shell • Wildcard: • ? : a single character • * : zero or more characters • [b-d] : either b, c, or d • {fconf, locg} : either ’conf’ or ’loc’ • Example:ls -d /etc/*[b-h]??.{conf,loc}?? • ^c (ctrl-c): kill the command • ^d (ctrl-d): end the input

  19. Redirect and Append • Redirect and append • Output of command is displayed on screen • Use “>” to redirect the output from screen to a file • Use “>>” to append the output to bottom of the file • Three types of input/output • Standard input: 代碼為 0,符號為 < 或 << • Standard output: 代碼為 1,符號為 > 或 >> • Standard error: 代碼為 2,符號為 2> 或 2>> • 命令執行判斷依據 • ;: 命令與命令之間的分隔符號 • &&: 當左邊的命令為 ”真”,才會執行右邊的命令 • ||: 當左邊的命令 “不為真”,才會執行右邊的命令

  20. Pipe • Pipe • Some commands require input from a file or other commands • Use “|” to use output from another command as input to the command • Example: ls /etc/ | sort | nl > file1.txt

  21. Permission • All of files and directories have owner and permission • Three types of permission: readable, writeable and executable • Permissions are given to three kinds of group: owner, group member and others • Example: ls -l .bash_profile -rw-r--r-- 1 cnotred 191 Jan 413:11 .bash_profile • r:readable, w:writable, x: executable

  22. Permission • Command: • chmod: change file mode, add or removepermission • chown: change owner of the file • Example: chmod a+w filename • add writable permission to all users chmod o-x filename • remove executable permission from others chmod a+x • Gives permission to the user to execute a file • u: user (owner); g: group; o: others; a: all

  23. Process Management • Process is a unit of running program • Each process has some information, like process ID, owner, priority, etc • Example: Output of “top” command

  24. Process Management • kill: stop a program • The program isspecified by process ID • killall: stop a program • The program isspecified by command name • ps: show process status • top:show system usage statistics

  25. Foreground and Background • Running job has two modes, “foreground” and “background” • Background job: the program keeps running even after your session was closed • Foreground job: • ctrl-c: stop program • ctrl-z: let program go into background • To run programs in background mode:king@my_pc:~$ command & • To get background job back into foreground:king@my_pc:~$ fg

  26. Remote Login and File Transfer • rshd, telnetd, ftpd, sshd are server program to provide remote login and file transfer • Remote login and file transfer are based on server and client model. Client program on your machine ask sever program certain service remote machine. • Sample client programs; • WS FTP FTP client • Internet Exploror HTTP client • Eudora POP, SMTP client

  27. Text Editor: vi • vi 共分為三種模式: • 一般模式 • 編輯模式 • 指令列命令模式

  28. Text Editor: vi

  29. Text Editor: vi

  30. Text Editor: vi

  31. Text Editor: vi

  32. Text Editor: vi

  33. Text Editor: vi

  34. Install Software • Unix system has a “de facto standard” way to install a software:configure make  make install • Typical software installation procedure as following: • Download source code: Usually, it’s archived with tar command and compressed with gzip command • Configure command creates Makefile automatically which is used to compile the source • Program compilation is written in Makefile

  35. Install Software • gzip compress a file • gunzip uncompress a file • tar archive or expand files • configure create Makefile • make compile and install software • Example: gunzip software.tar.gz tar –xvf software.tar cd software ./install OR make all OR …

More Related