Top Banner
CMSC 104 Operating Systems II A brief look at common Unix Commands
31

CMSC 1041 Operating Systems II A brief look at common Unix Commands.

Jan 03, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 1

Operating Systems II

A brief look

at common

Unix Commands

Page 2: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 2

UNIX Overview

History Files Commands Directories Resources

o bookso links from course homepage

Page 3: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 3

History of UnixIn the Beginning, there was the File

Long ago in a distant land …o “Multics” --- Multi-User ??????? OSo “The Operating System for Everything.”o GE, Honeywell, ATT

“Designed bigger than the could build.” ATT: computers but no OS.

o Solution: “Unix” --- single-user OS

Page 4: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 4

History of Unix

Written by Thompson and Ritchie at ATT Bell Labs

Development tied to “C” language Very small, very simple: ran on small

computers. o Used short names to save memoryo File-oriented for simplicity.

Page 5: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 5

Unix Files

“Everything in Unix is a file.” A file is (just) a sequence of bytes Created by

o editors (emacs, pico, vi)o other programs (logs, formatters)o devices (keyboards, modems, networks)

Hierarchical: can contain other fileso “container” files are “directories”

Page 6: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 6

Unix “Philosophy”

“The best way to do a big complex thing is to break it into small simple ones.”

“Make good tools that do one thing well, everywhere they are used.”

“Tools should be easy to use ---- once you know how.”

“Make it easy to use tools together.” “Tools should be able to explain

themselves.”

Page 7: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 7

Introduction to UnixFilenames

Any string of letters and numbers, starting with a letter (plus _-$)

restrictionso no blanks o length (on some systems)o case sensitive

ThisIsAnOkFileName This Is Not

Page 8: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 8

Unix Commands“Double, Double, Toil, and Trouble...”

cat concatenate a file: cat filenamecd change directory: cd dirname

change to home dir: cdcp copy a file: cp old newmore show by screens:more fnamemv move (rename) a file: mv old newrm remove a file: rm fnamepwd print working directory: pwdwc count lines, words, chars: wc

fname

Page 9: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 9

Unix Commands“… Fire burn and Caldron Bubble”

mkdir make a new directory: mkdir newpasswd change your password: passwdman get the manual: man thinglpr print something: lpr fnamegrep find something: grep thinghead show first lines: head fnametail show last lines: tail fnametee write file and pipe: tee fnamelogout logout: logout

Page 10: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 10

Unix Commands

Redirectiono cat < fname take input from

fnameo cat > fname put output in fnameo cat >> fname add output to fname

Pipeso prog1 | prog2 use output from prog1 as

input to prog2

Page 11: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 11

Unix CommandsStandard Input and Standard Output

Two “conventional” I/O Streams, available to all programso Standard Input, stdino Standard Output, stdino cat > fname put stdout in fname o cat >fname take stdin from

fnameo prog1 | prog2 connect stdout of prog1 to

stdin of prog2

Page 12: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 12

Unix Commandsstdin and stdout: redirection

< means “take input from”> means “write output to new file”>> means “append output to file”

cat fname displays fname on screencat f1 > f2 copies f1 into f2cat f3 >> f2 appends f3 to f2cat f1 f2 > f3 copies f1 and f2 into f3cat < f1 > f2copies f1 into f2

Page 13: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 13

Unix Commandsstdin and stdout: piping

“|” means “Take the output of the program on the left and use it as input for the

program on the right.”cat f1 | lpr cat reads f1 and pipes it

into lpr (i.e. print f1)man thing | lpr pipe the man page

thing into lpr (i.e. print it)

Page 14: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 14

Man Pages“I don’t need directions. I’m an engineer!”

“Manual pages” for most commands, some system files, other stuff

Very terse, nitty-gritty details Invoked as “man thingname” or

“man N thingname” (N is number) Organized by number. “1” means user

program: e.g. “man 1 cat” o Implicit N=1: “man cat” = “man 1 cat”

Page 15: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 15

Script files

for repeated command sequences (or complex sequences you don’t want to mess up!).o create with editoro mark as executable (chmod u+x <filename>)o like a DOS “batch” file

Page 16: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 16

Script Files: Example“Boys and Girls, do not try this at home!”

for name in *.*: do

lpr $name ;

wc $name > $name.count ;

cat $name > allfiles ;

done;

cat allfiles | tee allfiles2 | more;

Page 17: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 17

Files“Everything is a file”

Standard files:o Permissions: e.g. “rwxrwxrwx”

� “User, group, other”� read, write, execute

Directories:o Permissions: e.g. “rwxrwxrwx”

� read, write, visit

Devices:o Permissions: e.g. “rw-rw-rw-”

� read, write, N/A

Page 18: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 18

Directories: home directory

HOME directoryo System puts you here automaticallyo Usually “/home/olsen” “/home/grad/olsen”o YOUR directory, YOUR files (may be the

only safe place you can write!)o Limited size

Page 19: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 19

Directories: current directory

Current directoryo Where it’s happening now.o File I/O assumed to be relative to this

directory unless the filename starts with a “/” (e.g. /tmp/junkfile)

o May not be your home directory.o May change during execution

Page 20: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 20

Directories (cont’d)

/afs/umbc.edu/users/b/o/bob

junk recipes

pie cookie(symlink)

apple peach choc_chip

Page 21: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 21

Moving in the directory tree

. (dot) is the current working directory . . (dot-dot) is the parent directory Unix command cd “change directory” Use dot-dot to move up the tree Use directory name to move down Use complete directory name to move

anywhere

Page 22: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 22

Subdirectories

Organizing your files For example

o make a subdirectory for CS104o make subdirectories for each project

Page 23: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 23

EditorsInteractive Tools to Modify Files

Emacs: “The One True Editor”o Flexible and very powerfulo Programmable, hundreds of commandso Very complete on-line helpo H-U-G-E

vi: Quick and dirty, arcane commands Pico: ??

“Editors are a religious issue.”

Page 24: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 24

MailPrograms to Send and Receive Mail

/bin/mail: Standard, found everywhereo not intuitiveo no helpo mail -s “Subject in Quotes” [email protected] Type “naked period” “.” to send.

Elm: nice interface Pine: Elm with training wheels.

Page 25: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 25

Unix Tutorial

Learning the UNIX Operating System, 4th Edition

By Jerry Peek, Grace Todino & John Strang106 pages, $10.95If you are new to UNIX, this concise introduction will tell you just what you need to get started and no more. The fourth edition covers the Linux operating system and is an ideal primer for someone just starting with UNIX or Linux, as well as for Mac and PC users who encounter a UNIX system over the Internet. This classic book, still selling well long after most other intros to UNIX have bitten the dust, now includes a quick-reference card.

Page 26: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 26

Learning the vi Editor, 6th Edition

By Linda Lamb & Arnold Robbins348 pages, $24.95This completely updated guide to editing with vi, the editor available on nearly every UNIX system, now covers four popular vi clones and includes command summaries for easy reference. It starts with the basics, followed by more advanced editing tools, such as ex commands, global search and replacement, and a new feature, multiscreen editing.

Page 27: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 27

Unix Reference

UNIX in a Nutshell: System V Edition, 3rd Edition

By Arnold Robbins616 pages, $24.95The bestselling, most informative UNIX reference book is now more complete and up-to-date. Not a scaled-down quick reference of common commands, UNIX in a Nutshell is a complete reference containing all commands and options, with descriptions and examples that put the commands in context. For all but the thorniest UNIX problems, this one reference should be all you need. Covers

System V Release 4 and Solaris 7.

Page 28: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 28

Csh/Tsh Reference

Using csh & tcsh

By Paul DuBois242 pages, $29.95Using csh & tcsh describes from the beginning how to use these shells interactively to get your work done faster with less typing. You'll learn how to make your prompt tell you where you are (no more pwd); use what you've typed before (history); type long command lines with very few keystrokes (command and filename completion); remind yourself of filenames when in the middle of typing a command; and edit a botched command without retyping it.

Page 29: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 29

Bash Reference

Learning the bash Shell, 2nd Edition

By Cameron Newham & Bill Rosenblatt336 pages, $29.95This second edition covers all of the features of bash Version 2.0, while still applying to bash Version 1.x. It includes one-dimensional arrays, parameter expansion, more pattern-matching operations, new commands, security improvements, additions to ReadLine, improved configuration and installation, and an additional programming aid, the bash shell debugger.

Page 30: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 30

Emacs Tutorial

Learning GNU Emacs, 2nd Edition

By Debra Cameron, Bill Rosenblatt & Eric Raymond560 pages, $29.95

This comprehensive guide to the GNU Emacs editor, one of the most widely used and powerful editors available under UNIX, covers basic editing, several important "editing modes" (special Emacs features for editing specific types of documents, including email, Usenet News, and the Web), and customization and Emacs LISP programming. It is aimed at new Emacs users, whether or not they are programmers, and includes a quick-reference card. Covers

Version 19.30.

Page 31: CMSC 1041 Operating Systems II A brief look at common Unix Commands.

CMSC 104 31

One Publisher of Good CS Reference Books

My opinion, not endorsed by UMBC

O’Reilly and Associates: http://www.oreilly.com

o Reasonable prices (especially through Amazon.com)

o Technically accurate

o Easy to read