Some Brief Intermediate Level csh Workstation Help

alias
Example 1: Create the shortcut mathlab for designating remote display to the console (really X-server) of a machine.
		alias mathlab setenv DISPLAY mathlab.cit.cornell.edu:0
Example 2: An alias with arguments to show the last 8 files modified in a directory:
		alias lsh 'ls -Flagt \!* | head'
arithmetic
Example 1: Assignment:
		@ total = 0
		@ total = $total + 1	# spacing is important
Example 2: Add up the number of lines in the current directory using foreach and awk:
		@ total = 0
		foreach i ( * )
		? @ total = $total + `wc -l $i | awk '{print $1}'`
		? end
		echo $total
awk
to simply extract pieces from files or output.
Example: Print words number 3 and 4, separated by a space from each line of output from the command ls -al.
		ls -al | awk '{print $3 " " $4}'
backquotes to use the result of one unix command as the argument of another:
Example 1: Create the environment variable TMP as an abbreviation for the directory you are in when pwd is executed.
		setenv TMP `pwd`
editors
environment variables
DISPLAY
where X programs will display results; e.g.
setenv DISPLAY mathlab.cit.cornell.edu:0
LD_LIBRARY_PATH
additional directories to search for shared libraries; e.g.
setenv LD_LIBRARY_PATH /usr/openwin
MANPATH
a colon separated list of directories within which the man command searches for man pages; e.g.
setenv MANPATH /usr/man:/usr/openwin/man:/usr/local/man:/usr/local/X11/man
OPENWINHOME
location of the Open Windows distribution; e.g.
setenv OPENWINHOME /usr/openwin
TERM
type of terminal, used with the /etc/termcap database; e.g.
setenv TERM xterm
find
To locate or work on files in a directory heirarchy.
Example 1: (locating all files named *.ps below the directory
		cd 
		find . -name '*.ps' -print
Example 2: Compressing these files with gzip.
		cd 
		find . -name '*.ps' -exec gzip {} \;
Note that {} is substituted for by the name of each file found, and \; is part (the terminator) of the exec syntax.
if
in a csh.
Example 1: Find the size of all subdirectories of the current one.
		foreach i (*)
			if (-d $i) du -s $i
		end
Example 2: Prompt a user for yes or no and set the variable go accordingly.:
	echo -n "(YES or no)? " 
	set ans = $<
	if ( $ans == "" || $ans =~ [yY]* ) then
	   set go = 1
	else 
           set go = 0
	endif
loops (foreach)
in a csh.
Example 1: Make a backup copy of all files in the current directory of the form *.tex by appending .res.
		foreach i (*.tex)
		cp $i $i.res
		end
(After the line with foreach, you will get a new prompt.)
mail (sending with the unix mail program)
Tilde commands let you read in (~r), save (~w), view (~p), or edit (~v) a file.
Typing ~? at the beginning of a line gives you help.
Example 1: To read a file named "cube" into the current message:
polygon% mail sam
Subject: 
Sam, 
Below is a sample data file for a cube:
~r cube 
"cube" 14/97
Remark 2: When invoking an editor with ~v, the values of the VISUAL and EDITOR environment variables (e.g. emacs) will be relevant.
make
files for simple programs.
Example 1: Compile sample.c and sample.h producing sample whenever one of the sources has changed. (And link in the math library.)
 
		sample: sample.c sample.h
			cc sample.c -o sample -lm
Make is an old program and it is vital to only use TABS in indenting the compile line above.
References -I<non_standard_include_file_directory> and -L<non_standard_library_file_directory> are often needed to enable the compiler and linker to locate X and other not completely standard components.
printing
remote display
from one Unix workstation to another using X. (This includes Open Windows...)
Example 1: To tell all X programs to send their displays to the machine mathlab.cit.cornell.edu:
		setenv DISPLAY mathlab.cit.cornell.edu:0
If the machine receiving the display balks, use
		xhost +
or
		xhost + machine_running_remote_program
on mathlab.cit.cornell.edu to give machine_running_remote_program permission to display to mathlab.cit.cornell.edu.
sed
for stream editing of a collection of files.
Example 1: A script sub_sed to do basic substitution with sed:
		#!/bin/csh -f
		#USAGE: sub_sed source_pattern replacement_pattern < infile > outfile
		sed  "s/$1/$2/g"
shared libraries
The environment variable LD_LIBRARY_PATH, a colon-separated list of directories is key here.
tar
Example 1: To backup everything below directory in the file /tmp/dir.tar:
		cd directory
		tar -cvf /tmp/dir.tar .
(Note . is an abbreviation in csh for the current directory.)
Example 2: To check the table of contents of dir.tar:
		tar -tvf dir.tar
Example 3: To extract everything from dir.tar.
		tar -xvf dir.tar
terminal survival skills
Resetting the backspace character:
		stty erase hit_backspace_or_delete_as_you_prefer
Resetting your terminal:
		tset
Announcing the type of your terminal in a csh:
		setenv TERM xterm
or
		setenv TERM vt100

usage monitoring
Example 1: To find out the size and time consumption of all processes of username:
		ps -aux | grep username
on Linux machines or Suns or
		ps -efl  | grep username
on an SGI.
Example 2: Check out printing status:
		lpq
The command lprm job_number can delete a print request and lprm - will remove all requests.

Last Update: August 20, 2001