U N I X H a N D O
U N I X H A N D O U T
LIST CURRENT DIRECTORY CONTENTS
ls lists the files in the current directory.
lsl list all files in the current directory (including system files, those that begin with a dot) in the long format (includes file size and last edited).
DIRECTORY NAVIGATION AND MANIPULATION
cd lab01 change directory to lab01 directory (relative path name).
cd .. change directory to the parent of current directory.
cd change directory to the user's home directory.
cd ~/CS159/hw change directory to /CS159/hw (full path name).
mkdir labs creates directory labs.
rmdir labs removes directory labs (directory must be empty).
FILE UTILITIES
more hw01.c displays the contents of the file hw01.c one screen at a time.
rm hw01.c removes/deletes hw01.c from the current directory.
cp hw01.c hw01B.c makes a copy of hw01.c and calls it hw01B.c
mv lab01.c lab02.c renames the file lab01.c to lab02.c
mv lab01.c /lab01 file lab01.c will be moved to the directory /lab01.
COMPILERS/COMMAND LINE MATLAB
gcc lab05.c compiles the C program lab05.c.
octave lab02.m runs the lab02.m file using the MATLAB emulator octave.
CS 159 ASSIGNMENT SUBMISSION
submit start the submission script to submit a file to an assignment.
USEFUL UNIX COMMANDS
!v re-executes the last command beginning with v. !g re-executes the last command beginning with g. !a re-executes the last command beginning with a. !! re-executes the most recent command.
LOGGING OFF
logout use this command rather than clicking the X when using PuTTY.
RESTORING LOST COURSE CONFIGURATION FILES – USE ONLY WHEN INSTRUCTED TO BY COURSE STAFF
~cs159/studentConfig/resetUp V I E D I T O R ENTER AND EXIT vi
vi f1.c initiates an edit session on the file f1.c
:q! will exit and discard any changes. :w will update the file being edited without exiting. :wq will write (save) and quit (exit) the text editor.
ENTER INSERT MODE
a appends text after the cursor position. i inserts text before the cursor position. o opens a new line below the cursor position. O Opens a new line above the cursor position.
EXIT INSERT MODE
CURSOR MOVEMENT (Arrows work in both insert and command mode)
G moves the cursor to the last line in the file. 10G moves the cursor to line 10. :10 moves the cursor to line 10.
TEXT MOVING/EDITING COMMANDS
yy Yank a copy of a line, place it in a buffer. 10yy Yank 10 lines and places them in a buffer.
p put the last item yanked after the cursor. P Put the last item yanked before the cursor.
dd deletes the current line. 4dd deletes the next four lines.
x deletes the character under the cursor.
J join the current line with the line below.
OTHER COMMANDS IN vi
u undo the last command that changed the buffer.
/string Searches for "string" in the text file.
USEFUL EDITING TOOLS
:set paste move to paste mode (shut off indenting). Use no paste to exit paste mode. :set nu turn on line numbers. Use :set nonu to turn off line numbers. gg=G format/indent entire file
ADDING COURSE HEADERS
hmlb Insert MATLAB lab assignment header. hmhw Insert MATLAB homework assignment header. hlb Insert C lab assignment header. hhw Insert C homework assignment header. hfx Insert C user-defined function header.