email@example.comThis is a very brief guide to how to use cshell to speed up your use of Unix commands. Googling ``C Shell Tutorial'' can lead you to more detailed information.
Open a terminal, if you can not use left/right arrow to edit your commands, you are NOT using tcsh. To formally check it, type command
echo $shellIf you see
/usr/local/bin/tcshyou are using tcsh. Otherwise, enter command:
passwd -r nis -eEnter
/usr/local/bin/tcshwhen prompted. The new setting will be effective after around 10 minutes. For the purpose of this tutorial, use command
tcshto start an instance of tcsh.
All the features of cshell can be set in .cshrc. This is a plain text file located under you home directory. It will be loaded and executed whenever you open a shell window. After you edit this file (with any text editor of your choice), use source ~/.cshrc command to activate the change.
$path contains a list of directories to be searched when running programs or shell scripts. For example, the command Splus is in /usr/local/bin. If /usr/local/bin is not in your $path, you will have to enter the full path name /usr/local/bin/Splus to start Splus, rather than simply Splus. Usually, we set $path in ~/.cshrc, which will be executed whenever a new shell is started. The syntax of setting $path is:
set path = ( $path /home/helpdesk/bin ~/bin .)To check the content of your current $path, use command
echo $pathNote that '~' means your home directory, '.' means current directory. The above set path command add /home/helpdesk/bin ~/bin and . to your $path.
Tcsh records up to $history your previous commands. You can set $history in your .cshrc file as follows
set history=50Then, history command will list all your previous commands and
!27will execute command 27. !! is used to repeat your alst command.
You can also use the arrow keys to navigate the command history and edit the command line. It is also very important to know how to use the middle button of your mouse. Try to select your previous command with the left button and paste it with your middle button.
The <TAB> key is very useful in tcsh. Whenever you press <tab>, tcsh will try to complete your command, file or directory name. That is to say, you can enter
xt<tab>instead of xterm if xterm is the only command in your searching path that begin with xt. This is especially useful if you have very long file/directory names.
You need to understand some basics about standard input/output of Unix commands. Briefly, Unix programs usually read from their standard input, like the keyboard, output to their standard output, like the terminal. We can redirect their standard input/output in the following ways:
Alias, as its name implies, maps a (shorter) name to another (long) name. It can be used to give shortcuts to existing commands, create new commands or even 'overwrite' existing commands. For example, command
alias ll 'ls -l'maps ll to ls -l so that ls -l will be called whenever ll is entered as a command. It is perfectly all right to use command
alias ls 'ls -l'to alias ls to ls -l. The result of this alias is to add a default option -l to the ls command. This trick is most frequently used on the dangerous rm command,
alias rm 'rm -i'since the default rm command removes files without warning.
Alias can also handle parameters. Here I only demonstrate the simplest case where you use \!* as the parameters. For example:
alias mcd 'mkdir -p \!*; cd \!*'When you call
mcd statit will be expanded to
mkdir stat; cd stat
Can you mak the following aliases? You can use unalias command to disable an alias.
set cdpath = (~ ~/public_html ~/stat )and you can use cd stat410 to change your current directory to ~/stat/stat410 even when you are not under ~/stat.
set prompt= %n@%m:%~ %will set your prompt to username@machine name: current directory %.
You do need to understand more about variables, expressions before you can use control structure or write a shell script. Here are two very simple examples about how they can be used:
foreach file in (*)Starting from the above basics, you can learn:
move $file $file.bak
$Date: 2003/07/17 02:49:21 $
$Revision: 1.1 $
This document was generated using the LaTeX2HTML translator Version 2002-1 (1.68)
Copyright © 1993, 1994, 1995, 1996,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -local_icons -no_subdir -split 0 cshell.tex
The translation was initiated by Statistics Helpdesk on 2003-08-11