UNIX/LINUX in 25 commands (or less) DIRECTORY cd change directory cd .. drop one level cd ~/dirname back to root directory, then to dirname cd dir1/dir2 change directory at higher level pwd print working directory (where am I?) ls dirname list files in dirname Options: -l show directory files with long format -a include files beginning with . -d just name of directory not contents (with *) -t list in chronological order Wildcards: ? single character * anything mkdir dirname make (create) a directory rmdir dirname remove (delete) a directory FILES can name file from current directory as dir1/dir2/filename cp file1 file2 copies file1 to file2 (automatic overwrite) cp file1 dir copies file1 to directory dir (same filename) mv file1 file2 renames -- file1 has new name 'file2' mv file dirname moves file from current directory to dirname rm file removes (erases) file rm -f file remove -- and don't ask for confirmation dos2unix filename converts dos(Windows) file to unix ~/dir1/dir2/file names file from root (~) directory CONTENTS AND MANIPULATION head file print the first 10 lines of file head -23 file print the first 23 lines tail file print the last 10 lines tail -3 file print the last 3 lines more file look at file a screenful at a time less file more sophisticated wc file gives count of lines, words, and characters grep 'text' files finds 'text' in files grep '%let' *.sas egrep regexp file find lines with regular expression regexp cmp file1 file2 compares file1 and file2 (0 if same, 1 not same) diff file1 file2 compares files -- gives more info than cmp cat file lists contents of file cat file1 file2 > both concatenates file1 and file2 and puts in file both paste file1 file2 concatenates file1 and file2 in side-by-side manner cut -cstart-stop file1 prints cols start to stop of file file1 cut -c11-72 f1 > file2 writes cols 11-72 of file1 into file2 cut -c1,5-9 file1 > file2 writes cols 1 and 5-9 of file1 into file2 cut -f1,3 -d, file1 writes items 1 and 3 of file1 using ',' as delimeter (one char only) cut -f3 -d, -s file1 writes item 3 of file1 with comma delimiter and no lines without comma sort filename sorts filename (by ascii character order) sort -r filename sorts in reverse order Other options: -b ignore leading blanks -g general-numeric sort (3 vs 12) uniq filename deletes common records uniq -c filename gives count of common records (as proc freq) SED SIMPLE EDITOR COMMANDS sed 's/pat/repl/' file change 'pat' to 'repl' in file sed 's/pat/repl/3' file change just 3rd occurence sed 's/pat/repl/g' file change all occurences sed 'y/abc/def/' file substitute char for char (e.g. abc for bca) PIPING AND DIRECTION command > file1 direct output of command to file1 command >> file1 as above, but append to previous contents command < file2 use file2 as input to command command < file2 > file1 combine above command1 | command2 pipe output from command1 to command2 PRINTING lpr file print file lpq print queue status a2ps prints in two column format (80 cols wide) HELP get info man command display reference manual for command whatis command display one line description of command JOB CONTROL command & run command in background kill -9 num kills process num ps program status (what's running) J F Monahan, Nov 2008, 2009 update of handout by Tim Arnold dated 1990