Special Surgery: UNIX Survival Skills and Programming in C


Audiences:CT212: Comm Tech Students, Research Assistants & Associates Only

Editor: A/Prof. Philip M. Tsang
Last Updated: 27 September 1998, HK
 
[ Online NZ Unix course ] http://www.cit.ac.nz/smac/os100/unix01.htm
[Online C Programming Course] http://devcentral.iftech.com/learning/tutorials/c/
[David Marshall's Programming in C Course] http://www.cm.cf.ac.uk/Dave/C/CE.html
[Life Long Learning on the World Wide Web] http://www.cit.ac.nz/smac/csware.htm

To get the most out of the on-campus Unix machines such as sun04, plbpc010 (ourct212 www server) you need to know some essential Unix commands and some other commands which will increase your productivity. The following commands which I have grouped into two categories will get you started.

Getting Help from plbpc010

There are three (3) important help commands:

[com_tech@plbpc010 com_tech]$  apropos
[com_tech@plbpc010 com_tech]$  man
[com_tech@plbpc010 com_tech]$  whatis
You use 'apropos' with a matching string to see if there are any commands associated with it.
For example: 'apropos dir' returns screens of materials including the commands
such as 'rmdir' (removes a directory) & 'rm'
The next command-- 'man'--is the unix command for help.
So if you don't know what 'rm' does, you can do: ' man rm'.
'whatis' is also useful. Let's say you read somewhere something about 'ping'.
Boy! what is that?? Well the following command at least will get you started:
[com_tech@plbpc010 com_tech]$  whatis ping

 

The terminal freezed: you are lost

 Every once in a while you may want to stop an interactive process or suspend it. Control-c (^C) will usually kill it. Control-Z (^Z) will suspend the process. If you want to actually kill the process, first-- that's right: apropos kill then when you "man kill", you will see a "see also" for "ps". The best way to learn Unix is to sit infront of a terminal and get your hands dirty and experiment with the commands. Of course, getting to know someone who is an old-hand of Unix will certainly help a lot.

Basic Directory Management Commands

ls -lists a directory
cd - Changes the current working directory
mkdir - Makes a directory
mv - Moves files and directories
mvdir - Moves (renames) a directory
pwd - Displays the pathname of the current (working) directory
rm - Removes (unlinks) files or directories
rmdir - Removes a directory
ln - Removes a directory
alias -creates a short name for a lengthy command
grep - Searches a file for a pattern
Example: grep news /usr/log/hislog/todays.log Advanced File Management Commands
chmod-Changes permission codes (usefull command when creating your own home page
tar- Manipulates multiple files/directory archieve.
examples:
 tar -cvf *.html conf-archive-html.tar
recovery the archive: tar -xvf conf-achive-html.tar

Some Short Cut shell Commands
!p -repeates the last command staring with p
alias -creates a short name for a lengthy command
page -Displays a file one screenful at a time
cat -Concatenates or displays files

Here are some examples:
ls -s *.c
rm -r old-directory
rmdir old-directory (not the same as above)
mv old-file-name new-file-name
cat a b c d >big_abcd

Some new commands (start with 'whatis') :
chmod a+r *.pop           ( For "basic" info on chmod click here ).
kill -9 process-number
grep worms /usr/log/hislog/todays.log
alias pt 'cd /local/WWW/special/conference/'

Pipes "|" allows output from one program to go to another.
So the following:
ls -sl |more
displays a full directory listing and outputs it to the 'more' program.