1 / 48

Understanding Unix Operating System Basics

Learn about the organization of a computer system, Unix operating system layers, file system structure, file referencing, and input/output concepts. Dive into processes and more. Helpful for beginners in Unix.

khastings
Download Presentation

Understanding Unix Operating System Basics

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. CSc 352: Basic Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson debray@cs.arizona.edu

  2. Organization of a computer system applications users shell graphical user interface (GUI) operating system hardware (or software acting like hardware: “virtual machine”)

  3. Organization of a computer system “The Internet” user computer network server lectura.cs.arizona.edu

  4. Organization of a computer system applications users Easier to use. Not so easy to program with or automate interactive actions (click, drag, tap, …) shell graphical user interface (GUI) system calls operating system hardware (or software acting like hardware: “virtual machine”)

  5. Organization of a computer system applications Easier to program with and automate. Not so convenient to use (maybe) users typed commands shell graphical user interface (GUI) system calls operating system hardware (or software acting like hardware: “virtual machine”)

  6. Organization of a computer system applications users this class shell graphical user interface (GUI) operating system hardware (or software acting like hardware: “virtual machine”)

  7. Reading • Chapter 1: • Upto “Background Jobs” (page 17)

  8. What is Unix? • Unix is an operating system • sits between the hardware and the user/applications • provides high-level abstractions (e.g., files, processes) and services (e.g., multiprogramming) • Linux: • a “Unix-like” operating system: user-level interface very similar to Unix • code base is different from original Unix code

  9. Layers of a Unix system users applications shell commands system calls shell Unix operating system kernel hardware

  10. The file system • A file is basically a sequence of bytes • Collections of files are grouped into directories ( folders) • A directory is itself a file • file system has a hierarchical structure (i.e., like a tree) • the root is referred to as “/” / bb cc dd ff ee …

  11. “Everything is a file” • In Unix, everything looks like a file: • documents stored on disk • directories • inter-process communication • network connections • devices (printers, graphics cards, interactive terminals, …) • They are accessed in a uniform way: • consistent API (e.g., read, write, open, close, …) • consistent naming scheme (e.g., /home/debray, /dev/cdrom)

  12. Referring to files: Absolute Paths • An absolute path specifies how to get to a file starting at the file system root • list the directories on the path from the root (“/”), separated by “/” / bb cc dd ff ee gg

  13. Referring to files: Absolute Paths • An absolute path specifies how to get to a file starting at the file system root • list the directories on the path from the root (“/”), separated by “/” / bb cc dd ff ee absolute path: /dd/ee/gg gg

  14. Referring to Files: Relative Paths • Typically we have a notion of a “current directory” • A relative path specifies how to get to a file starting from the current directory • ‘..’ means “move up one level” • ‘.’ means current directory • list the directories on the path separated by “/” / bb cc dd ff ee gg

  15. Referring to files: Relative Paths • Typically we have a notion of a “current directory” • A relative path specifies how to get to a file starting from the current directory • ‘..’ means “move up one level” • ‘.’ means current directory • list the directories on the path separated by “/” / bb cc dd ff ee gg • Example: • ff relative to ee is: ../ff

  16. Referring to files: Relative Paths • Typically we have a notion of a “current directory” • A relative path specifies how to get to a file starting from the current directory • ‘..’ means “move up one level” • ‘.’ means current directory • list the directories on the path separated by “/” / bb cc dd ff ee gg • Example: • cc relative to ee is: ../../cc

  17. Home directories • Each user has a “home directory” • specified when the account is created • given in the file /etc/passwd • When you log in, your current directory is your home directory • can then start a shell and issue commands • Notational shorthand: • one’s own home directory: ~ • some other user joe’s home directory: ~joe A shell is just an interpreter for Unix commands

  18. Input and output • Data are read from and written to i/o streams • There are three predefined streams: stdin : “standard input”  usually, keyboard input stdout : “standard output”  usually, the screen stderr : “standard error”  for error messages (usually, the screen) Other streams can be created using system calls (e.g., to read or write a specific file)

  19. Processes • Programs are executed via processes • a process is the unit of execution • consists of: • the code that is executed • the data this code manipulates • Different processes execute concurrently • each process has its own address space, stdin, stdout, etc. • their execution is managed by the operating system • Common tasks are carried out using a set of system-provided programs called commands • the shell is also a system-provided program

  20. Unix Commands • Each command performs [variations of] a single task • “options” can be used to modify what a command does • different commands can be “glued together” to perform more complex tasks • Syntax: command options arguments Examples: Options can (usually) be combined together: these are equivalent

  21. Unix Commands • Each command performs [variations of] a single task • “options” can be used to modify what a command does • different commands can be “glued together” to perform more complex tasks • Syntax: command options arguments Examples: Not always required: may have default values • typical defaults: • input: stdin • output: stdout • directory: current defaults to current directory

  22. Examples of Unix commands I • Figuring out one’s current directory: pwd • Moving to another directory: cd targetdir Examples:

  23. Examples of Unix commands II • Command: ls — lists the contents of a directory • Examples:

  24. Combining commands • The output of one command can be fed to another command as input. • Syntax: command1 | command2 Example: “pipe” • How this works: • ls writes its output to its stdout • more’s input stream defaults to its stdin • the pipe connects ls’sstdout to more’sstdin • the piped commands run “in parallel”

  25. Finding out about commands I Figuring out which command to use aproposkeyword man –k keyword “searches a set of database files containing short descriptions of system commands for keywords” • Helpful, but not a panacea: • depends on appropriate choice of keywords • may require trial and error • may return a lot of results to sift through • pipe through more

  26. Finding out about commands II Figuring out how to use a command mancommand “displays the on-line manual pages” • Provides information about command options, arguments, return values, bugs, etc.

  27. Example: “man ls” items within square brackets are optional

  28. Example: “man man”

  29. Example: “man man” we can specify what kind of information we want

  30. Some other useful commands • wc [file] • word count: counts characters, words, and lines in the input • greppattern [file] • select lines in the input that match pattern • head –n [file] • show the first n lines of the input • tail –n [file] • show the last n lines of the input • cpfile1file2 • copy file1 to file2 • mvfile1file2 • move file1 to file2

  31. Example: Deleting a file Figuring out which command to use: • apropos delete • produces many screenfuls of output that go by too quickly • apropos delete | more • many screenfuls of output, but shown one screenful at a time • most of the commands shown aren’t relevant

  32. Example: Deleting a file… (1) a lot fewer results; nothing relevant Idea 1: filter out irrelevant stuff man –k delete | grep file

  33. Example: Deleting a file…(2) Idea 2: try a different keyword man –k remove | grep file

  34. Example: Deleting a file… (3) these are the only commands that refer to removing files Idea 2: try a different keyword man –k remove | grep file

  35. Example: Deleting a file… (4) this is the only user command that refers to removing files Idea 2: try a different keyword man –k remove | grep file

  36. Example: Deleting a file… (5) Confirm that this is the appropriate command: “man rm” strongly suggest making this your default

  37. Setting defaults for your commands • Create an “alias” for your command • syntax different for different shells • bash: aliasaliasName=“cmdName” e.g.: alias rm=“rm –i” • see “man alias” for details • To have this alias in force whenever you log in, add this line to the file ~/.bashrc // assuming your login shell is “bash” • To find out your login shell, run the command echo $0

  38. Pattern matching: grep

  39. Pattern matching: grep… (1) print the current directory show the contents of this file print out the lines that match “nation”

  40. Pattern matching: grep… (2) “print all lines in the input that match the string er”

  41. Pattern matching: grep… (3) “print all lines in the input that match the string eror re print all lines in the input that begin with the string eror re

  42. Pattern matching in the shell • We can also use patterns in shell commands, e.g.: Example:

  43. I/O Redirection • Default input/output behavior for commands: • stdin: keyboard; stdout: screen; stderr: screen • We can change this using I/O redirection:

  44. Getting more information about files • ls –l : provides additional info about files

  45. Getting more information about files… (1) owner group size last-modified time file name no. of hard links access permissions file type

  46. File access permissions access permissions for others (o) access permissions for group (g) access permissions for owner (u)

  47. Changing file access permissions Command: chmod whowhat file1 file2 … filen Example: ∈ {r, w, x} ∈ {a, u, g, o}

  48. Foreground and Background Processes • Multiple processes can run concurrently • at any point, there is exactly one process that you can interact with through the keyboard (“foreground process”) • remaining processes execute “in the background” • A process can be started in the background: processName & • The execution of the current foreground process can be paused via ctrl-z • “bg” will then start it executing in the background • “fg” will bring it to the foreground

More Related