Upload
gerald-welch
View
221
Download
0
Embed Size (px)
Citation preview
The UNIX development The UNIX development environmentenvironment
CS 400/600 – Data StructuresCS 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
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!)
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
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
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
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)
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
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
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
ADTs and SimpleList 11
Dependency TreeDependency Tree
slist
Slist_main.o Slist.o
Slist_main.cpp Lnode.h Slist.h Lnode.hSlist.hSlist.cpp
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!