unix commands

some useful commands

=========================

esc- enter command mode

inserting text (exits command mode and enters edit mode)

--------------

i - insert before cursor

a - append after cursor

o - start new line below cursor

O - start new line above cursor

deleting text (must be in command mode)

-------------

x - delete character on cursor

dd - delete current line

dw - delete to end of word

moving the cursor (must be in command mode)

-----------------

h j k l - left, down, up, right

^F - forward one screen

^B - backward one screen

^D - down half a screen

^U - up half a screen

w - forward on word

b - backward on word

0 - move to beginning of line

$ - move to end of line

G - move to last line of file

nG - move to nth line

file commands (must be in command mode)

-------------

:w - write (save) file

:w! - write (save) file (force, and ignore permissions)

:x - save and exit

:q - quit

:q! - quit without saving changes

miscellaneous commands (must be in command mode)

----------------------

u - undo

/pattern - search forward for pattern

?pattern - search backward for pattern

:s/old/new/ - substitute new for old on current line (1st occurence only)

:s/old/new/g - substitute new for old on current line (all occurences)

:1,$s/old/new/g - substitute new for all occurences of old

===============================================================

Some useful Unix commands

=====================

ls -la - file listing of all files, in long format

ls -t - file listing sorted by time stamp

ls -F - file listing, puts a * for executables, @ for symbolic

links, / for directories

passwd - changes your password

date - prints date and time

mv /usr/people/john/file1 /usr/people/mary/file1

- move file1 to new location

mv file1 file2 - rename file1 to file2

mkdir directory - make new directory

cp file1 file2 - copy file1 to file2

rm file1 - remove a file1

rm -r directory - remove directory and all contents in it

rmdir directory - removes an empty directory

file filename - reports on type of file

screen control

--------------

^S - stop output from scrolling off screen

^Q - resume scrolling

^D - send EOF

^C - interupt (terminate) current process

stty -a - list current terminal settings

stty erase '^H' - assigns the erase command to Ctrl-H

C-Shell specific information

----------------------------

To customize your C-shell, edit the file ~/.cshrc

alias ls 'ls -F' - makes an alias command

alias rm 'rm -i' - makes an alias command for interactive removals

unalias ls - unalias the command

echo Hello world - prints 'Hello world' to screen

File searching

--------------

find / -name filename -print

find / -name "*filename*" -print > findresults.txt

find / filename -user thomas -size +2000000 -print

^^^^^^^ size in blocks (1block=512bytes)

find / filename -user thomas -size +1000000c -print

^^^^^^^^ size in characters (1char=1byte)

find / filename -mtime n -print files time stamped less than n days ago

-group groupname files belonging to a specific group

-type d only directories

-type f only files

Creating symbolic links

-----------------------

e.g.

ln -s realfile fakefile

Wild cards

----------

* matches any number of characters

? matches 1 character

Text viewing programs

---------------------

more filename - view contents of filename

tail filename - view last 10 lines of filename

tail -100 filename - view last 100 lines of filename

tail -f filename - view last 10 lines of filename and follow any updates

head filename - view first 10 lines of filename

head -1 filename - view first line of filename

cmp file1 file2 - compare file1 and file2

diff file1 file2 - compare files and report differences line by line