Operating Systems, Unix Files and Commands SEEM

Similar documents
More on Unix Shell SEEM

Introduction to Process in Computing Systems SEEM

CSC UNIX System, Spring 2015

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

Lecture 2b. Pathnames, files, special characters in filenames, and file permissions. COP 3353 Introduction to UNIX, FALL 2013

Files

CS246 Spring14 Programming Paradigm Notes on Linux

commandname flags arguments

CSCI 2132 Software Development. Lecture 4: Files and Directories

UNIX File Hierarchy: Structure and Commands

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

CS Fundamentals of Programming II Fall Very Basic UNIX

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

5/20/2007. Touring Essential Programs

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

Permission and Ownership

Mills HPC Tutorial Series. Linux Basics I

Unix and C Program Development SEEM

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

5/8/2012. Encryption-based Protection. Protection based on Access Permission (Contd) File Security, Setting and Using Permissions Chapter 9

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Introduction to the Linux Command Line

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

Linux & Shell Programming 2014

Introduction to Linux

Chapter-3. Introduction to Unix: Fundamental Commands

CHAPTER 2 THE UNIX SHELLS

Unix Introduction to UNIX

CSE II-Sem)

5/8/2012. Creating and Changing Directories Chapter 7

System Programming. Unix Shells

Welcome to Linux. Lecture 1.1

CHAPTER 1 UNIX FOR NONPROGRAMMERS

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Oxford University Computing Services. Getting Started with Unix

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Introduction to Linux

AC109/AT109 UNIX & SHELL PROGRAMMING DEC 2014

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Operating System Interaction via bash

Review of Fundamentals

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

CISC 220 fall 2011, set 1: Linux basics

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

The Unix Shell & Shell Scripts

PROGRAMMAZIONE I A.A. 2015/2016

Introduction to Unix: Fundamental Commands

Chapter 1 - Introduction. September 8, 2016

Exploring UNIX: Session 3

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

A Brief Introduction to Unix

User Commands ls ( 1 )

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Essentials for Scientific Computing: Bash Shell Scripting Day 3

5/8/2012. Specifying Instructions to the Shell Chapter 8

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

CS4350 Unix Programming. Outline

Introduction to Linux Workshop 1

Assignment clarifications

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

The Online Unix Manual

Files and Directories

Introduction to Linux

Outline. Structure of a UNIX command

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

Introduction to Linux

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Basic File Attributes

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

Getting Started with UNIX

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction to Linux

Introduction to Linux Basics

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script

Exercise Sheet 2. (Classifications of Operating Systems)

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

CSN08101 Digital Forensics. Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak

Introduction: What is Unix?

Hardware. Ahmet Burak Can Hacettepe University. Operating system. Applications programs. Users

9.2 Linux Essentials Exam Objectives

Unix Basics. UNIX Introduction. Lecture 14

CHAPTER 3 SHELL PROGRAMS: SCRIPTS

CENG 334 Computer Networks. Laboratory I Linux Tutorial

ACS Unix (Winter Term, ) Page 21

The UNIX File System

Operating System Security

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Unix Workshop Aug 2014

Goals for This Lecture:

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Standard. Shells. tcsh. A shell script is a file that contains shell commands that perform a useful function. It is also known as shell program.

INF322 Operating Systems

Lab #0 Getting Started Due In Your Lab, August 25, 2004

Basics. I think that the later is better.

Transcription:

Operating Systems, Unix Files and Commands SEEM 3460 1

Major Components of Operating Systems (OS) Process management Resource management CPU Memory Device File system Bootstrapping SEEM 3460 2

Programs and Processes One way to describe the hardware of a computer system is to say that it provides a framework for executing programs and storing files. A file is a collection of data that is usually stored on disk, although some files are stored on tape. UNIX treats peripherals as special files, so that terminals, printers, and other devices are accessible in the same way as disk-based files. A program is a collection of bytes representing code and data that are stored in a file. When a program is started, it is loaded from disk into the main memory (RAM). When a program is running, it is called a process. Most processes read and write data from files. SEEM 3460 3

Processes The concept of process A program in execution The animated spirit of a program The entity that can be assigned to and executed on a processor The life of a process is bounded by its creation and termination. In a typical computer system, it may be running thousands of processes at the same time. SEEM 3460 4

Owner of Processes and Files Processes and files have an owner and may be protected against unauthorized access. UNIX supports a hierarchical directory structure. Files and processes have a location within the directory hierarchy. A process may change its own location or the location of a file. The figure below is an illustration of a tiny UNIX directory hierarchy that contains four files and a process running the sort utility. SEEM 3460 5

Process Management One major operating system (OS) function is the sharing of limited resources among competing processes. Limited resources in a typical computer system include CPUs, memory, disk space, and peripherals such as printers. OS shares CPUs among processes By dividing each second of CPU time into equalsized slices (typically 1/10 second) and then allocating them to processes on the basis of a priority scheme. SEEM 3460 6

Process Management The operating system usually interleaves the execution of all processes to maximize processor utilization while providing reasonable response time. Process A Process B Process C CPU Time Slice SEEM 3460 7

Sharing Resources OS shares memory among processes By dividing the main memory up into thousands of equal-sized chunks of memory and then allocating them to processes The chunks of a process are called pages and chunks of memory are called frames SEEM 3460 8

Sharing Memory - Paging SEEM 3460 9

Sharing Memory - Paging SEEM 3460 10

Sharing Resources Only those portions of a process that actually need to be in the main memory are ever loaded from disk. Pages that are not accessed for a while are saved back to disk so that the memory may be reallocated to other processes. This is called swapping SEEM 3460 11

Sharing Memory Page Tables for Paging Operating system maintains a page table for each process contains the frame location for each page in the process memory address consist of a page number and offset within the page SEEM 3460 12

Sharing Memory Page Tables for Paging SEEM 3460 13

Sharing Resources OS shares disk space among users by dividing the disks into thousands of equal-sized blocks and then allocating them to users according to a quota system. A single file is built out of one or more blocks. SEEM 3460 14

Unix File Attributes We can use ls to obtain a long listing of a file. For example: cuse93:> ls -ls heart.final 1 -rw-r--r-- 1 glass cs 213 Jan 31 00:12 heart.final Field # 1 2 3 4 5 6 7 8 Field value 1 -rw-r--r-- 1 glass cs 213 Jan 31 00:12 heart.final File Attribute Meaning the number of blocks of physical storage occupied by the file the type and permission mode of the file, which indicates who can read, write, and execute the file the hard link count the username of the owner of the file the group name of the file the size of the file, in bytes the time that the file was last modified the name of the file SEEM 3460 15

Unix File Attributes File Storage The number of blocks of physical storage is shown in field 1 and is useful if you want to know how much actual disk space a file is using. It s possible to create sparse files that seem to be very large in terms of field 6, but actually take up very little physical storage. SEEM 3460 16

Unix File Attributes - Filenames The name of the file is shown in field 8. A UNIX filename may be up to 255 characters in length. You may use any printable characters you want in a filename except the slash (/) You avoid the use of any character that is special to a shell (like <,>, *,?, or the tab), as these can confuse both the user and the shell. There is no requirement that a file end in an extension such as.c and.h, although many UNIX utilities (e.g., the C compiler) will accept only files that end with a particular suffix. Thus, the filenames heart and heart.final are valid The only filenames that you definitely can t choose are (..) and (.) as these are predefined filenames that correspond to your current working directory and its parent directory, respectively. SEEM 3460 17

Unix File Attributes File Modification Time Field 7 shows the time that the file was last modified and is used by several utilities. The find utility may be used to find files on the basis of their last modification time. SEEM 3460 18

Unix File Attributes File Owner Field 3 tells you the owner of the file. Every UNIX process has an owner, which is typically the same as the username of the person who started it. For example, my login shell is owned by glass, which is my username. Whenever a process creates a file, the file s owner is set to the process owner. This means that every file that I create from my shell is owned by glass, the owner of the shell itself. SEEM 3460 19

Unix File Attributes File Owner Note that while the text string known as the username is typically how we refer to a user, internally UNIX represents this as an integer known as the user ID. The username is easier for humans to understand than a numeric ID. We will refer to the textual name as username and use user ID to refer to the numeric value itself. SEEM 3460 20

Unix File Attributes File Group Field 5 shows the file s group. Every UNIX user is a member of a group. This membership is initially assigned by the system administrator and is used as part of the UNIX security mechanism. For example, my group name is cs Every UNIX process also belongs to a specific group, usually the same as that of the user which started the process. My login shell belongs to the group name cs. Because each file created by a process is assigned to the same group as that of the process that created the file, every file that I create from my shell has the group name cs. SEEM 3460 21

Unix File Attributes File Group As with the user ID, the group is usually referenced by the text string name, but is represented internally as an integer value called the group ID. We will refer to the textual name as group name and use group ID to refer to the numeric value itself. SEEM 3460 22

Unix File Attributes File Type Field 2 describes the file s type and permission settings. For convenience, here s the output from the previous ls example: 1 -rw-r--r-- 1 glass cs 213 Jan 31 00:12 heart.final The first character of field 2 indicates the type of the file, which is encoded as shown below. In the example, the type of heart.final is indicated as a regular file. Character - d b c l p s File type regular file directory file buffered special file (such as a disk drive) unbuffered special file (such as a terminal) symbolic link pipe socket SEEM 3460 23

Unix File Attributes File Type A file s type can often be determined by using the file utility. For example, when we ran file on heart.final, we can see this: cuse93:> file heart.final determine the file type heart.final: ascii text cuse93:> _ Utility: file { filename }+ The file utility attempts to describe the contents of the filename arguments, including the language that any text is written in. When using file on a symbolic link file, file reports on the file that the link is pointing to, rather than the link itself. SEEM 3460 24

Unix File Attributes File Permissions The next nine characters of field 2 indicate the file s permission settings. In the current example, the permission settings are rw-r--r-- : 1 -rw-r--r-- 1 glass cs 213 Jan 31 00:12 heart.final SEEM 3460 25

Unix File Attributes File Permissions (con t) These nine characters should be thought of as being arranged in three groups of three characters, as shown below, where each cluster of three letters has the same format. If a dash occurs instead of a letter, then permission is denied. rw- Read permission r User (owner) Group r-- Write permission w Others r-- Execute permission x (Note: While file permission is quite useful, it is not 100% accurate and can be fooled by some file formats. ) SEEM 3460 26

Read Write Execute Unix File Attributes File Permissions (con t) The meaning of the read, write, and execute permissions depends on the type of the file, as shown below. Regular file The process may read the contents. The process may change the contents. The process may execute the file (which makes sense only if the file is a program) Directory file The process may read the directory (i.e., list the names of the files that it contains). The process may add files to or remove files from the directory. The process may access files in the directory or any of its subdirectories. Special file The process may read from the file using the read() system call. The process may write to the file, using the write() system call. No meaning. SEEM 3460 27

Changing A File s Permissions : chmod The chmod utility is used to change the permission of files. For example, to remove read permission from others: cuse93:> ls l heart.final before -rw-r--r-- 1 glass music 213 Jan 31 00:12 heart.final cuse93:> chmod o-r heart.final remove read for others cuse93:> ls l heart.final after -rw-r----- 1 glass music 213 Jan 31 00:12 heart.final cuse93:> _ SEEM 3460 28

Changing A File s Permissions : chmod (con t) The table below shows some other examples of the use of chmod. Requirement Add group write permission. Remove user read and write permission. Add execute permission for user, group, and others. Give others read permission. Add write permission for user, and remove read permission from group. Change parameters g+w u-rw a+x o+r u+w, g-r SEEM 3460 29

Changing A File s Permissions : chmod (con t) Another example of chmod: cuse93:> cd change to home directory cuse93:> ls ld. list attributes of home dir drwxr-xr-x 45 glass 4096 Apr 29 14:35. cuse93:>chmod o-rx. update permissions cuse93:> ls ld. confirm drwxr-x--- 45 glass 4096 Apr 29 14:35. cuse93:> _ Note that the -d option of ls is used to ensure that the attributes of the directory, rather than the attributes of its files, were displayed. SEEM 3460 30

Changing A File s Permissions : chmod (con t) The chmod utility allows you to specify the new permission setting of a file as an octal number. Each octal digit represents a permission triplet. For example, if you wanted a file to have the permission settings rwxr-x--- then the octal permission setting would be 750, calculated as shown below. User Group Others setting rwx r-x --- binary 111 101 000 octal 7 5 0 SEEM 3460 31

Changing A File s Permissions : chmod (con t) The octal permission setting would be supplied to chmod as follows: cuse93:> chmod 750. update permissions cuse93:> ls ld. confirm drwxr-x--- 45 glass 4096 Apr 29 14:35. cuse93:> _ SEEM 3460 32

Determining Your Terminal s Type: tset Several UNIX utilities, including the two standard editors vi (or vim) and emacs, need know what kind of terminal you re using so that they can control the screen correctly. The type of your terminal is stored by your shell in something called an environment variable. You may think of environment variables as being global variables for the shell and they can hold strings. SEEM 3460 33

Determining Your Terminal s Type: tset (con t) Before vi, vim or emacs can work correctly, your shell s TERM environment variable must be set to your terminal type. Common settings for this variable include vtl00 and vt52. There are several ways to set TERM: Your shell start-up file can set TERM directly by containing a line of the form setenv TERM vtl00 (C shell) or TERM=vtl00; export TERM (for Bourne, Korn, and Bash shells). This method of setting TERM is practical only if you know the type of your terminal in advance and you always log into the same terminal. Your shell start-up file can invoke the tset utility, which looks at the communications port that you re connected to and then set TERM accordingly. Consult the online manual for tset. You can manually set TERM from a shell. e.g. cuse93:> setenv TERM vt100 SEEM 3460 34

Filename Substitution (Wildcards) All shells support a wildcard facility that allows you to select files from the file system that satisfy a particular name pattern. Any word on the command line that contains at least one of the wildcard metacharacters is treated as a pattern and is replaced by an alphabetically sorted list of all the matching filenames. This act of pattern replacement is called globbing. SEEM 3460 35

Filename Substitution (Wildcards) The wildcards and their meaning are shown in the following table Wildcard *? [..] Meaning Matches any string, including the empty string. Matches any single character. Matches any one of the characters between the brackets. A range of characters may be specified by separating a pair of characters by a dash. SEEM 3460 36

Filename Substitution (Wildcards) The Some examples of wildcard usage cuse93:> ls *.c file1.c axe.c go.c queue.c KIT.c on.c cuse93:> ls??.c go.c on.c cuse93:> ls [ac]* any pattern beginning with a or c axe.c c.txt abc cuse93:> ls [a-z]* any pattern beginning with small letter file1.c axe.c c.txt abc axe.c go.c on.c SEEM 3460 37

Shell Operations When a shell is invoked automatically during a login (or manually from a keyboard or script), it follows a preset sequence: 1. It reads a special start-up file, typically located in the user s home directory, that contains some initialization information. Each shell s start-up sequence is different. 2. It displays a prompt and waits for a user command. 3. If the user enters a Control-D character on a line of its own, this is interpreted by the shell as meaning end of input and causes the shell to terminate; otherwise, the shell executes the user s command and returns to step 2. SEEM 3460 38

Shell Operations (con t) Commands range from simple utility invocations, such as cuse93:> ls to complex-looking pipeline sequences, such as cuse93:> ps -ef sort ul -tdumb lp SEEM 3460 39

Shell Operations (con t) If you ever need to enter a command that is longer than a line on your terminal, you may terminate a portion of the command with a backslash (\) character, and the shell then allows you to continue the command on the next line: cuse93:> echo this is a very long shell command and needs to \ be extended with the line continuation character. Note \ that a single command may be extended for several lines. this is a very long shell command and needs to be extended with the line continuation character. Note that a single command may be extended for several lines. cuse93:> _ SEEM 3460 40

Executable Files Versus Built-in Commands Most UNIX commands invoke utility programs that are stored in the directory hierarchy. Utilities are stored in files that have execute permission. For example, when you type cuse93:> ls the shell locates the executable program called ls, which is typically found in the /bin directory, and executes it. In addition to its ability to locate and execute utilities, the shell contains several built-in commands, such as echo and cd, which it recognizes and executes internally. SEEM 3460 41

Special Local Variables of a Shell Every shell has a set of predefined environment variables that have special meanings to the shell Name $HOME $PATH $MAIL $USER $SHELL $TERM Meaning the full pathname of your home directory a list of directories to search for commands the full pathname of your mailbox your username the full pathname of your login shell the type of your terminal SEEM 3460 42

Finding A Command When a shell processes a command, it first checks to see whether the command is a built-in; if it is, the shell executes it directly. echo is an example of a built-in shell command: cuse93:> echo some commands are executed directly by the shell some commands are executed directly by the shell cuse93:> _ SEEM 3460 43

Finding A Command : $PATH If the command in question isn t a built-in command, the shell checks whether it begins with a / character. If it does, the shell assumes that the first token is the absolute pathname of a command and tries to execute the file with the stated name. If the file doesn t exist or isn t an executable file, an error occurs: cuse93:> /usr/bin/ls full pathname of the ls utility abc.txt program.cpp cuse93:> /usr/bin/nsx a non-existent filename /usr/bin/nsx: not found cuse93:> /etc/passwd... the name of the password file /etc/passwd: Permission denied it s not executable cuse93:> _ SEEM 3460 44

Finding A Command : $PATH (con t) If the command in question isn t a built-in command or a full pathname, the shell searches the directories whose names are stored in the PATH environment variable. To display the content of an environment variable: cuse93:> echo $PATH /sbin:/usr/bin:/usr/local/bin Each directory in the PATH variable is searched (from left to right) for an executable file matching the command name. If a match is found, the file is executed. If a match isn t found in any of the directories, or if the file that matches is not executable, an error occurs. Here is an example: cuse93:> echo $PATH /sbin:/usr/bin:/usr/local/bin cuse93:> ls abc.txt program.cpp cuse93:> nsx nsx: not found cuse93:> _ directories searched located in /usr/bin not located anywhere SEEM 3460 45

Finding A Command : $PATH (con t) If PATH is not set or is equal to the empty string, then only the current directory is searched. The contents of the PATH variable may be changed thereby allowing you to tailor the search path to your needs. The original search path is usually initialized by the shell s start-up file (e.g. ~/.cshrc) and typically includes all of the standard UNIX directories that contain executable utilities. SEEM 3460 46

Finding A Command : $PATH (con t) The which utility can show the current path of a certain utility used by the shell. cuse93:> which ls /usr/bin/ls SEEM 3460 47