Basic Unix Commands

clear resets the display if it gets messed up.

history shows commands you recently entered.

man display help for specified command.

cd change working directory. cd ../.. goes up two folders.

ls list files/directories. -lrt lists most recent files last.

cp a b copy file from location a to location b. Use cp -a for directories.

mv a b move file from location a to location b

rm delete file

rmdir delete empty directory

mkdir create new directory

cat print file contents to standard output.

echo print specified character string to standard output.

ps u CPU/memory usage info for active processes.

kill kill process with PID

find find . -name "*.txt" searches files in directory

<up> arrow key: scroll thru command history

chmod change file access permissions

ssh remote login

rsync remote copy. rsync -avP folder host:

python python interpreter (Ctrl+D, ^d, to quit)

exit close shell/subshell/logout

vim open Vi IMproved editor (see below).

> redirect standard output into new file.

>! redirect and overwrite previous file.

>> append existing file with standard output.

>& redirect standard output and any errors.

^c kill active foreground process.

& perform process in background.

Vi Editor Commands (must be in command mode)

vim file opens text file in Vi editor

i enter insert mode so you can type at cursor

esc escape key returns from insert mode to command mode so you can navigate

h move cursor left; nh 'n' spaces left

j cursor down

k cursor up

l cursor right

I insert at begin of line

A append at end of line

R enter replace mode to type over existing text

O open new line before cursor

o open new line after cursor

. repeats previous command

u undo previous command

^r redo previous command

^f page down

^b page up

G goto end of file

nG goto line 'n'

0 goto line beginning

$ goto end of line

x deletes character

dd delete an entire line

ndd deletes 'n' lines

d$ delete til end of line

yy yank 1 line

nyy yank 'n' lines

P put yanked lines before cursor

p put yanked lines after cursor

~ change case of character

:w save work

:w file2 writes to a new file

:wq save and quit Vi (returns to Unix shell)

:q! quit Vi without saving

/x search for string 'x' (n or N cycles forward/backward between matches)

:set wrap display wraps long lines to fit into window

:syntax on enables syntax highlighting

:set hlsearch highlight all search matches

:set ruler shows line/character number of cursor

:set showmode display insert/command mode


Installation for Mac Users

  • Apple computers with Mac OS X are based on the Unix operating system so basic Unix commands and the vim program will already be available when you open Applications/Utilities/Terminal.app

Installation for Windows Users

  • Check that your computer has a 64-bit CPU and download the appropriate installer file setup.exe for your cpu architecture at www.cygwin.com.

  • Do NOT select every Unix package available in cygwin. Select only the packages specified in the Tutorial 1 instructions before starting the download/install.


Programming Languages

Command syntax Detailed syntax notes from Dr. Hills: C shell, awk, Vi, Python, C++, alphabetical list of Unix commands, etc.