CSC UNIX System, Spring 2015

Similar documents
Operating Systems, Unix Files and Commands SEEM

5/20/2007. Touring Essential Programs

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

Unix Processes. What is a Process?

Review of Fundamentals

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

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

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

Files

Introduction to Linux

Introduction: What is Unix?

Introduction to Linux Organizing Files

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

Basics. I think that the later is better.

Introduction to Linux

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Introduction to UNIX. Introduction EECS l UNIX is an operating system (OS). l Our goals:

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Week 5 Lesson 5 02/28/18

Introduction to UNIX Shell Exercises

A shell can be used in one of two ways:

Files and Directories

UNIX and Linux Essentials Student Guide

Introduction to the shell Part II

Linux shell programming for Raspberry Pi Users - 2

Chapter-3. Introduction to Unix: Fundamental Commands

Lecture # 2 Introduction to UNIX (Part 2)

Utilities. September 8, 2015

UNIX Essentials Featuring Solaris 10 Op System

CMU MSP 36602: Intro to UNIX and Scripting: Part 1

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

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

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Introduction to Linux. Roman Cheplyaka

UNIX System Programming Lecture 3: BASH Programming

Linux Command Line Interface. December 27, 2017

Lab 2: Linux/Unix shell

Useful Unix Commands Cheat Sheet

CSE 15L Winter Midterm :) Review

CSC209. Software Tools and Systems Programming.

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

CSCI 2132 Software Development. Lecture 4: Files and Directories

Introduction to Unix: Fundamental Commands

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

Linux Refresher (1) 310/ Fourth Workshop on Distributed Laboratory Instrumentation Systems (30 October - 24 November 2006)

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Shells and Shell Programming

Shell Programming Overview

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

5/8/2012. Exploring Utilities Chapter 5

CSCI2467: Systems Programming Concepts

Introduction to UNIX. Introduction. Processes. ps command. The File System. Directory Structure. UNIX is an operating system (OS).

Introduction to UNIX. CSE 2031 Fall November 5, 2012

1Z Oracle Linux Fundamentals (Oracle Partner Network) Exam Summary Syllabus Questions

Filesystem and common commands

System Programming. Introduction to Unix

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

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

Unix Tools / Command Line

Quick Start Guide. by Burak Himmetoglu. Supercomputing Consultant. Enterprise Technology Services & Center for Scientific Computing

Introduction to the Shell

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

CSC209. Software Tools and Systems Programming.

Lecture 4. Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions?

FREEENGINEER.ORG. 1 of 6 11/5/15 8:31 PM. Learn UNIX in 10 minutes. Version 1.3. Preface

Bash Programming. Student Workbook

(a) About Unix. History

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell.

commandname flags arguments

Name: Peter Lemieszewski Venue: Education

I/O and Shell Scripting

CS 460 Linux Tutorial

S E C T I O N O V E R V I E W

Introduction to remote command line Linux. Research Computing Team University of Birmingham

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

A Brief Introduction to the Linux Shell for Data Science

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Sperimentazioni I LINUX commands tutorial - Part II

Introduction to the Linux Command Line January Presentation Topics

unix intro Documentation

Unix Introduction to UNIX

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

Mills HPC Tutorial Series. Linux Basics I

Shells and Shell Programming

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

Welcome to Linux. Lecture 1.1

UNLV Computer Science Department CS 135 Lab Manual

Basic Linux (Bash) Commands

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

CST Algonquin College 2

A Brief Introduction to Unix

Environment Variables

S E C T I O N O V E R V I E W

Week 2 Lecture 3. Unix

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Transcription:

CSC 352 - UNIX System, Spring 2015 Study guide for the CSC352 midterm exam (20% of grade). Dr. Dale E. Parson, http://faculty.kutztown.edu/parson We will have a midterm on March 19 on material we have covered through spring break except for any Shell programming we might start on March 5. The purpose of this study guide is to limit the amount of material that you need to try to memorize. The UNIX commands and related system information go both deep and wide. We need to limit the scope of an exam. Major topics appear by number below. 1. Files, directories, and related commands. Know about the various types of files: regular files, directories, symbolic links, named pipes, character I/O devices (such as a terminal that reads or writes one character at a time) and block I/O devices (such as a disk that can transfer a block of data at a time). Below are some examples from running ls ld on respective files of those types. The first field in each line shows the type of file referenced by that directory entry. -rw-r--r-- 1 parson faculty 93 Mar 14 2010 bignum.py (regular file) drwxr-xr-x 6 parson faculty 512 Feb 20 19:12 unix (directory) lrwxrwxrwx 1 parson faculty 52 Jan 9 19:40 threadwait -> /export/home/faculty/parson/multip/csc580/threadwait (a symbolic link) prw-r--r-- 1 parson faculty 0 Feb 7 17:08 mypipe (named pipe created via mknod) crw--w---- 1 parson tty 24, 1 Feb 21 10:42 /devices/pseudo/pts@0:1 (character I/O, this is a terminal) brw-r----- 1 root sys 32, 16 Feb 21 10:44 /devices/pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,2/storage@2/disk@0,0:a (block I/O, here a disk) Know about the ls command and its options for inspecting the contents of a directory. Here are the options to know. You can combine multiple options together, such as ls alrtr. -l (create a long listing the option letter is ell the above listings are long listing) -a (show all entries including the ones whose names begin with a period) -t (sort the output according to modification time, most recent at the top) -r (reverse the direction of the sort; ls lrt places the oldest at the top) -i (print the inode number every file has an inode number, and multiple hard links may refer to the same, single inode number. The inode number is the actual file ID.) -R (apply this ls command and its options recursively to every subdirectory below) -d (list a directory entry without showing that directories contents. This option shows the directory s entry in its parent, rather than showing what is in that directory.) If you give ls a command line of file names, it will list those. If you give it files names with wildcards such as * without quoting those wildcards, the shell will expand the wildcards before running ls. If any of those names is a directory, it will show the contents of that directory unless you use the d option. You can give absolute paths to ls or any command requiring a file name; and absolute path starts at /, which is the root directory. You can give a relative path as well; a relative path does not have a leading /, and it starts in the current directory. CSC 352, UNIX midterm preparation, page 1 of 6, Spring 2015

The file command shows you what kind of contents are in files. This command looks into the files. Here are some outputs for the file command from the above listed files and some others. -bash-3.00$ file bignum.py bignum.py: ascii text -bash-3.00$ file unix unix: directory -bash-3.00$ file threadwait threadwait: directory (It follows the symbolic link to its target directory or file.) -bash-3.00$ file mypipe mypipe: fifo (A first-in-first-out FIFO is another name for a pipe.) -bash-3.00$ file /devices/pseudo/pts@0:1 /devices/pseudo/pts@0:1: character special (24/1) -bash-3.00$ file /devices/pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,2/storage@2/disk@0,0:a /devices/pci@0/pci@0/pci@1/pci@0/pci@1/pci@0/usb@0,2/storage@2/disk@0,0:a: block special (32/16) -bash-3.00$ file TwoDimensionalBoardGame.java TwoDimensionalBoardGame.java: ascii text -bash-3.00$ file TwoDimensionalBoardGame.class TwoDimensionalBoardGame.class: java class file -bash-3.00$ file seeargs.c seeargs.o seeargs seeargs.c: c program text seeargs.o: ELF 32-bit MSB relocatable SPARC Version 1 seeargs: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped Note that the java class file and the ELF SPARC files above hold executable binary data for compiled Java and C programs respectively. The grep command is good for searching through textual files. We will get to regular expression wildcard patterns later this semester. Here is what you need to know for now. grep STRING FILENAMES grep -i STRING FILENAMES grep STRING -bash-3.00$ ls grep make makefile makejar makelib (Search for STRING in one or more files.) (A case-insensitive version search STRING in upper or lower case.) (Without file names it searches lines in stdin for the STRING.) Example of this last one: Here are some other commands relating to files that you should know about. cat more less wc Concatenate one or more files and send their contents to standard out. Scroll the contents of a file to the terminal. Scroll the contents of a file to the terminal. Count lines, words and characters in a file. Example: CSC 352, UNIX midterm preparation, page 2 of 6, Spring 2015

-bash-3.00$ wc seeargs.c 31 181 1190 seeargs.c find Search a directory given as the first argument for files matching the qualifiers. Qualifiers to know: -type for the file type, such as type d for directories, -type f for regular files. -name for a name, such as name S*.java for all Java source files starting in S. Make sure to quote any name that has a pattern, so the shell does not expand the pattern in the current directory. -mtime for modification time, such as mtime -30 for any file modified in the last 30 days, or mtime +30 for any file with modification older than 30 days ago. zip bundle files into a ZIP archive. zip r recursively includes subdirectory contents. unzip Unzip a ZIP archive created with zip. Examples: zip r seeargs.zip seeargs creates archive seeargs.zip from contents of directory seeargs. unzip seeargs.zip extracts directories and file from above archive. tar Create a so-called tape archive file in a UNIX format. It is not compressed. This command can also extract the files from a tar archive file. gzip GNU zip, a predecessor to zip that can compress an existing file such as a tar archive. zcat,gzcat,gunzip Variants of the extractor for GNU gzip files. emacs vi diff Editor for textual files. Editor for textual files. Compare two textual files for differences. 2. Shell commands, variables, and processes File redirection operators include the following. I have put them in quotes so that MS Word does not alter them. > FILE Sends stdout to the named FILE, either creating or truncating the FILE. >> FILE Sends stdout to the named FILE, either creating or appending the FILE. 2> FILE Sends stderr to the named FILE, either creating or truncating the FILE. 2> &1 Sends stderr to the same destination as stdout. < FILE Reads stdin from the named FILE. command1 commands2 Pipes the stdout of command1 to the stdin of command2. Shell variables. MYVAR=STRING set MYVAR STRING export MYVAR export MYVAR=STRING I will use bash on the exam. Sets the value of MYVAR to STRING in all shells except C-shell. Sets the value of MYVAR to STRING in C-shell. Make MYVAR a global variable visible to processes created by this shell. Same as last line, this form also sets the value on the same line. CSC 352, UNIX midterm preparation, page 3 of 6, Spring 2015

setenv MYVAR STRING echo $MYVAR This is how C-shell exports a global variable. Echo the shell variable to stdout. Use a $ to get the value of a shell variable. Important shell variables: SHELL HOME CDPATH Path to the shell program started by some programs such as script. Path to your login directory. Colon-separated list of directory paths where the shell searches when you use the cd command. PATH Colon-separated list of directory paths where the shell searches for the command Files such as ls that you enter into the shell. Example: -bash-3.00$ echo $PATH /usr/jdk/jdk1.6.0_02/bin/:/opt/csw/bin:/usr/sbin:/opt/csw/graphviz2/bin:/usr/local/smlnj/bin:/bin:/usr/bin:/usr/local/bi n:/usr/ccs/bin:/opt/csw/gcc3/bin:/opt/csw/mysql5/bin:/usr/sfw/bin:/opt/csw/bin:/opt/sunwspro/bin:/usr/jdk/jdk1.6.0 _02/bin:/usr/local/instantclient_10_2 -bash-3.00$ which ls /usr/bin/ls /usr/bin is a component of my $PATH. -bash-3.00$ which kjerhbjke no kjerhbjke in /usr/jdk/jdk1.6.0_02/bin/ /opt/csw/bin /usr/sbin /opt/csw/graphviz2/bin /usr/local/smlnj/bin /bin /usr/bin /usr/local/bin /usr/ccs/bin /opt/csw/gcc3/bin /opt/csw/mysql5/bin /usr/sfw/bin /opt/csw/bin /opt/sunwspro/bin /usr/jdk/jdk1.6.0_02/bin /usr/local/instantclient_10_2 Command line substitution of wildcard characters by the shell occurs before the shell invokes your program. The * (asterisk) substitutes for zero or more characters in the specified directory, and the [abc] pattern matches any one of those characters in the square braces. Example: -bash-3.00$ ls -d $HOME/[Uu]*[xX]* /export/home/faculty/parson/unix /export/home/faculty/parson/unixsysprog Back-quotes, also known as back-ticks, run the command enclosed in the back-quotes, and then substitute whatever that command writes to its stdout, back into the command line containing the back-quotes. For example: -bash-3.00$ cd ~/unix -bash-3.00$ echo `pwd` /export/home/faculty/parson/unix # Substitute stdout from `pwd` back into echo s command line Double quotes allow you to enclose spaces and tabs within a single command line arguments or other string value within the shell. Double quotes inhibit wildcards for file name characters, but double quotes allow shell substitution for $VARIABLES and back-quotes. Here are some examples. -bash-3.00$ ls -d *t runcat -bash-3.00$ ls -d "*t" *t: No such file or directory -bash-3.00$ ls -d $HOME /export/home/faculty/parson CSC 352, UNIX midterm preparation, page 4 of 6, Spring 2015

-bash-3.00$ ls -d "$HOME" /export/home/faculty/parson -bash-3.00$ ls -d "`pwd`" /export/home/faculty/parson/unix -bash-3.00$ echo hello > "three word file" -bash-3.00$ ls -l "three word file" -rw-r--r-- 1 parson faculty 6 Feb 21 20:25 three word file -bash-3.00$ cat "three word file" hello A \ backslash can escape shell special treatment of any single character, such as a space or *. -bash-3.00$ cat three\ word\ file hello -bash-3.00$ echo \$HOME $HOME -bash-3.00$ echo \* * -bash-3.00$ echo \`pwd\` `pwd` Single quotes inhibit wildcards, $VARIABLES and back-quotes from expansion by the shell. Compare the following examples with the double quoted examples above. -bash-3.00$ ls -d *t runcat -bash-3.00$ ls -d '*t' *t: No such file or directory -bash-3.00$ ls -d '$HOME' $HOME: No such file or directory -bash-3.00$ ls -d '`pwd`' `pwd`: No such file or directory GNU make uses a makefile to interpret rules contained in that makefile. Each rule consists of: Target: Dependency Action Where the Target is mandatory, and one or Dependencies (on the same line as the Target) and Actions (on separate lines) are optional. Each Target defines a goal to be accomplished. It may be a target file that needs to be compiled. Each Dependency (if any) is something that the Target depends on. A Dependency may be a source file on which a Target file depends for compilation. A Dependency may also be a Target in another rule; that rule must be executed as part of Dependency checking of the above rule. The Actions are invocation lines passed to the shell, for example to compile files or to remove files. 3. UNIX processes CSC 352, UNIX midterm preparation, page 5 of 6, Spring 2015

When you invoke a program from the shell, the shell requests that the underlying UNIX system A) loads that machine-code program from disk into memory, and then B) runs that program in memory using CPU resources such as registers and arithmetic units. A process is a running program. See the computer diagram from week 1. Many processes spend most of their lifetime in the sleep state, waiting for input (from a terminal, disk drive or network interface device), or waiting for output operations (to a monitor, disk drive or network interface device) to complete. Bill has two CPUs, so only two processes can actually be running at a time. (Harry has 64, Hermione has 16, and Ron has 32.) When a process is asleep, UNIX may page portions of its memory contents to disk, or it may swap the entire snapshot of memory to disk. When the input or output operation that the process was awaiting is completed, UNIX can page or swap the memory images from disk back to memory, then resume running the process until it is ready to sleep again. For processes that do a lot of computation with little I/O so-called CPU-bound processes UNIX interrupts these processes periodically, forcing them to sleep for a while to free up CPU for other processes. -bash-3.00$ ps f # Note the user ID, the process ID, its parent process ID, and its command UID PID PPID C STIME TTY TIME CMD parson 28322 28320 0 20:00:13 pts/33 0:00 -bash parson 242 28322 0 20:55:41 pts/33 0:00 ps f -bash-3.00$ ps f -p 0 # Process ID 0 schedules process to run on the CPU. UID PID PPID C STIME TTY TIME CMD root 0 0 0 Jul 25? 0:12 sched -bash-3.00$ ps f -p 1 # Process ID 1, init, starts other major UNIX processes and cleans up processes. UID PID PPID C STIME TTY TIME CMD root 1 0 0 Jul 25? 21:36 /sbin/init CSC 352, UNIX midterm preparation, page 6 of 6, Spring 2015