12
The UNIX development The UNIX development environment environment 400/600 – Data Structures 400/600 – Data Structures

The UNIX development environment CS 400/600 – Data Structures

Embed Size (px)

Citation preview

Page 1: The UNIX development environment CS 400/600 – Data Structures

The UNIX development The UNIX development environmentenvironment

CS 400/600 – Data StructuresCS 400/600 – Data Structures

Page 2: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 2

Basic UNIX commandsBasic UNIX commands The directory tree

• pwd – Print working directory• ls – List contents• cd – change directory

Relative path: dir/dir/dir Absolute path : /dir/dir/dir

• Special directory names: . = current directory .. = parent directory ~ = my home directory ~fred = fred’s home directory

Page 3: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 3

Working with filesWorking with files More directory commands

• mkdir – make directory• rmdir – remove directory (must be empty)

File commands• cp <sourcefile> <newfile> – copy a file• mv <oldname> <newname> – move or rename• touch – create a file or update the timestamp• rm – remove a file

rm -r – remove an entire directory (BE CAREFUL!)

Page 4: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 4

More commandsMore commands Files

• ls -l – show file details• chmod – change permissions

user, group, other rwx,rwx,rwx chmod 640 <filename> = user: rw, group: r, other: none chmod g+w <filename> = add group write permission

Page 5: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 5

Running Programs and RedirectionRunning Programs and Redirection Safest: ./program Redirection

• program > filename (cout file)• program < filename (cin file)• program < file1 > file2• program1 | program2 (output of program1 becomes

cin for program2) Examples: ls > file, more < file, ls | more

Page 6: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 6

The VI text editorThe VI text editor VI <filename> Two modes: command and editing Use <Esc> to get to command mode Be careful with CAPS LOCK Basic commands

• i = insert text (go to editing mode)• :w <return> = write changes (save)• :wq <return> = save and exit (or ZZ)• :q! <return> = exit without saving

Page 7: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 7

Cursor MovementCursor Movement Switch to command mode

• Arrow keys or (k, j, h, l) to move around• ^f / ^b = forward/back 1 screenfull• ^d / ^u = down/up ½ screenful• H / L = move cursor to top / bottom of screen• 0 (zero) / $ = move cursor to start / end of line• G = go to last line of the file• #G = go to line number # of the file (useful for debugging)

Page 8: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 8

Text OperationsText Operations x = delete one character D = delete to end of line dd = delete entire line dw = delete word r = replace one character R = replace until escape is pressed i = insert characters (edit mode) a = append characters (edit mode) o = “open” a new blank line (edit mode) J = join this line with the next one

Page 9: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 9

TipsTips # followed by a command is very handy

• 29dd = delete 29 lines• 34G = go to line 34• 17 = move 17 characters to the right• 5dw = delete 5 words

Period (.) in command mode repeats last command• Can be combined with the above

yy = “yank” (copy) one line, p = paste• Paste works after delete commands (dd, dw,etc.) too

Page 10: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 10

Lnode Slist

CompilingCompiling

Lnode.h Slist.h

Slist.cpp

Slist_main.cpp

g++ -c Slist.cpp

g++ -c Slist_main.cpp

g++ -o slist Slist.o Slist_main.o

Page 11: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 11

Dependency TreeDependency Tree

slist

Slist_main.o Slist.o

Slist_main.cpp Lnode.h Slist.h Lnode.hSlist.hSlist.cpp

Page 12: The UNIX development environment CS 400/600 – Data Structures

ADTs and SimpleList 12

MakefileMakefile# M. Raymer -- 9/2004# CS 400/600 -- Data Structures and Software Design# -------------------------------------------------------------

# Use the following CFLAGS for debuggingCFLAGS= -g -ggdb -DUNIX

# Use these CFLAGS for optimized, non-debugging code#CFLAGS= -O -DUNIX

CC= g++

slist: Slist.o Slist_main.o $(CC) $(CFLAGS) -o slist Slist.o Slist_main.o

Slist.o: Slist.h Slist.cpp Lnode.h $(CC) $(CFLAGS) -c Slist.cpp

Slist_main.o: Slist_main.cpp Slist.h Lnode.h $(CC) $(CFLAGS) -c Slist_main.cpp

clean: rm -f *.o slist

Must be a tab character!