LevSelector.com New York
home > tcsh 
tcsh
intro
basics
history
patterns
complete
misc

 
intro home - top of the page -

tcsh - was born at Ohio State circa 1983, and Paul Placeway was its dad.
    Since 1987 is maintained by Christos Zoulas (christos@ee.cornell.edu).
    See more here: www.tac.nyc.ny.us/mirrors/tcsh-book/tcsh.html/AUTHORS.html

www.tcsh.org/page?Home - tcsh home page
www.tcsh.org - tcsh home page.
www.tac.nyc.ny.us/mirrors/tcsh-book/tcsh.html/index.html - tcsh manual page
www.engin.umich.edu/htbin/mangate?manpage=tcsh - tcsh
www.tac.nyc.ny.us/mirrors/tcsh-book/bindings.html - tcsh Command Editor Commands
www.blackie.dk/dotfile/ - TDG - The Dotfile Generator ( also read article here )
www.dubois.ws/software/csh-tcsh-book/ - Archive for "Using csh & tcsh" book by Paul DuBois - who also has written more good books: MySQL, MySQL and Perl for the Web, Software Portability with imakeThe MySQL Cookbook -
 This page has excellent links, for example an old article (1994): Tom Christiansen's article ( same at another address ) - why csh (and tcsh) should not be used for writing shell scripts.

http://www.flug.dk/lg/issue12/tcsh.html - Features of the TCSH Shell - By Jesper Kjær Pedersen

 
basics home - top of the page -

 
left-right arrows - move left-right in the line  (^B, ^F), 
up/down arrows - move up-down in the history (^P, ^N)

bindkey - shows the list of shortcuts you can use.
Standard key bindings
"^@"           ->  set-mark-command
"^A"           ->  beginning-of-line
"^B"           -> backward-char
"^C"           ->  tty-sigintr
"^D"           -> delete-char-or-list-or-eof
"^E"           ->  end-of-line
"^F"           -> forward-char
"^G"           ->  is undefined
"^H"           ->  backward-delete-char
"^I"           ->  complete-word (TAB)
"^J"           ->  newline
"^K"           ->  kill-line
"^L"           ->  clear-screen
"^M"           ->  newline
"^N"           -> down-history
"^O"           ->  tty-flush-output
"^P"           -> up-history
"^Q"           ->  tty-start-output
"^R"           ->  redisplay
"^S"           ->  tty-stop-output
"^T"           ->  transpose-chars
"^U"           ->  kill-whole-line
"^V"           ->  quoted-insert
"^W"           ->  kill-region
"^X"           ->  sequence-lead-in
"^Y"           ->  yank
"^Z"           ->  tty-sigtsusp
"^["           ->  sequence-lead-in
"^\"           ->  tty-sigquit
"^]"           ->  tty-dsusp
" "  to "/"    ->  self-insert-command
"0"  to "9"    ->  digit
":"  to "~"    ->  self-insert-command
"^?"           ->  backward-delete-char
"^Ä"           ->  list-choices
"^È"           ->  backward-delete-word
"^É"           ->  complete-word
"^Ì"           ->  clear-screen
"^Ú"           ->  run-fg-editor
"^Û"           ->  complete-word
"^ß"           ->  copy-prev-word
"\240"         ->  expand-history
"¡"  to "ÿ"    ->  self-insert-command 
Alternative key bindings
Multi-character bindings
"^[[A"         -> up-history
"^[[B"         -> down-history
"^[[C"         -> forward-char
"^[[D"         -> backward-char
"^[OA"         -> up-history
"^[OB"         -> down-history
"^[OC"         -> forward-char
"^[OD"         -> backward-char
"^[^D"         -> list-choices
"^[^H"         -> backward-delete-word
"^[^I"         -> complete-word
"^[^L"         -> clear-screen
"^[^Z"         -> run-fg-editor
"^[^["         -> complete-word
"^[^_"         -> copy-prev-word
"^[ "          -> expand-history
"^[!"          -> expand-history
"^[$"          -> spell-line
"^[/"          -> dabbrev-expand
"^[0"          -> digit-argument
"^[1"          -> digit-argument
"^[2"          -> digit-argument
"^[3"          -> digit-argument
"^[4"          -> digit-argument
"^[5"          -> digit-argument
"^[6"          -> digit-argument
"^[7"          -> digit-argument
"^[8"          -> digit-argument
"^[9"          -> digit-argument
"^[?"          -> which-command
"^[B"          -> backward-word
"^[C"          -> capitalize-word
"^[D"          -> delete-word
"^[F"          -> forward-word
"^[H"          -> run-help
"^[L"          -> downcase-word
"^[N"          -> history-search-forward
"^[P"          -> history-search-backward
"^[R"          -> toggle-literal-history
"^[S"          -> spell-word
"^[U"          -> upcase-word
"^[W"          -> copy-region-as-kill
"^[_"          -> insert-last-word
"^[b"          -> backward-word
"^[c"          -> capitalize-word
"^[d"          -> delete-word
"^[f"          -> forward-word
"^[h"          -> run-help
"^[l"          -> downcase-word
"^[n"          -> history-search-forward
"^[p"          -> history-search-backward
"^[r"          -> toggle-literal-history
"^[s"          -> spell-word
"^[u"          -> upcase-word
"^[w"          -> copy-region-as-kill
"^[^?"         -> backward-delete-word
"^X^X"         -> exchange-point-and-mark
"^X*"          -> expand-glob
"^X$"          -> expand-variables
"^XG"          -> list-glob
"^Xg"          -> list-glob
"^Xn"          -> normalize-path
"^XN"          -> normalize-path
"^X?"          -> normalize-command
"^X^I"         -> complete-word-raw
"^X^D"         -> list-choices-raw

Arrow key bindings
down           -> down-history
up             -> up-history
left           -> backward-char
right          -> forward-char

Autocomplete:
Press tab key to autocomplete the name of the file or a directory. If more than one match exists - you can see the list if you have variable "autolist" set up:
   set autolist
   set autolist=ambiguous:
Note: 
    in csh you need to do set filec  in your ~/.cshrc  file.
Note: 
   with autolsit set, you can also get a list of commands if you press tab when typing a command.

3 uses of ctrl-D:
^D on an empty line - exit the shell
^D in the middle of the line - delete on char (under the cursor)
^D at the end of a line - list the matching names. To get a list of names when the cursor is in the middle of a line (or
on an empty line), type Escape followed by ^D). 

. - current directory
.. - parent directory
~ - home directory
~somelogin - home directory of user with login 'somelogin'

Names whith spaces: - use quotes or escape spaces:
more 'abc def'
more abc\ def

 
history home - top of the page -
Accessing history in tcsh:
type "history" to see history of commands

Event specifiers:
!n This refers to the history event, with index n
!-n This refers to the history event, which was executed, n times ago: !-1 for the previous command, !-2 for the one before the previous command etc.
!! This refers to the previous command
!# This refers to the current command
!s This refers to the most recent command, whose first word begins with the string s
!?s? This refers to the most recent command, which contain the sting s

For example, just type !!, to re-execute the previous command.

But how can you re-execute some part of a previous command, with some new elements added? Use  the following word designators, which is appended to the event specifier, with a colon:
0 The first word (i.e. the command name)
n The nth word
$ The last argument
% The word matched by an ?s? search
x-y Argument range from x to y
* All the arguments to the command (equal to ^-$)
Now it's possible to get the last argument from the previous command, by typing !!:$.
If no event specifier is given, the previous command is used. This means that instead of writing !!:$, you may only write !$.
Note: more words designators exists, and it's even possible to edit the words with different commands.
 
!* Repat all arguments from previous command
!^ Repeat firt argument
!$ Repeat last argument

Example:
grep ERROR file1 file2 file3
grep -i !*

You can also repeat words from the current command:
!#* All arguments
!#^ First argument
!#$ Last argument
!#:n Argument n

You can repeat the words from previous commands while editing by pressing:
ESC _ Repat last argument from previous command
ESC ^_ Repeat previous word from current command
ESC / Repeat most recent word from my history list that matches the word to the left of the cursor

NOTE:
It is possible to expand the history references on the command line before you evaluate them by pressing ESC-SPC or ESC-! (This is: first the escape key, and next the space key or the ! key). On some keyboards you may use the meta key instead of the escape key. I.e. M-SPC (One keystroke!). Here is an example:
Before After
% sed 's/^\(...\) *\([0-9][0-9]*\)/\2 \1/' data1 > temp
% anova Height Weight < temp | more
% anova Height Weight < temp | lpr
% sed 's/^\(...\) *\([0-9][0-9]*\)/\2 \1/' data2 > temp
% anova Height Weight < temp | more
% anova Height Weight < temp | lpr
% sed 's/^\(...\) *\([0-9][0-9]*\)/\2 \1/' data1 > temp
% anova Height Weight < !$ | more
% ^more^lpr
% !sed:sdata1/data2
% !?more
% !?lpr

 
patterns home - top of the page -
Patterns:
Many operations in the shell often works on many files, e.g. all files ending with .tex or starting with test-. Tcsh has the opportunity to type all these files for you, with file patterns. The following list shows which possibilities there exists:
* Match any number of characters
? Match a single character
[...] Match any single character in the list
[x-y] - match any character within the range
[^...] - match elements which doesn't match the list
{...} This expands to all the words listed. There's no need that they match. See examples below.
^... ^ in the beginning of a pattern negates the pattern.

Examples:
*.tex match all files ending with .tex
^*.tex match all files which does not end with .tex
xxx{ab,cde,hifj}yy match xxxabyy xxxcdeyy and xxxhifjyy
*.[ch] or *.{c,h} match all .c and .h files

NOTE:
The shell expand patterns before the program will get it. For example, if you use:

   somecommand a:* /tmp

it will try to expand the star before passing arguments to the command. If you really want to pass the star itself to the command - escape it:

      somecommand a:\* /tmp

NOTE:
Use ctrl-x followed by 'g' key to list all pattern matches without actually executing the command.
Or use ctrl-x followed by '*' to expand * right on the command line.

 
complete home - top of the page -

 
complete display all completion definitions
complete name
uncomplete name
uncomplete *
display completion definition for command 'name'
delete completion rule for one (or all) names
complete cd 'p/1/d/' p - apply to a word at a given position
1 - first position (first after command itself)
d - complete as a directory name
complete rmdir 'p/*/d/' p - position
* - any position
d - as directory
complete alias 'p/1/a/' complete alias with alias name
complete ftp 'p/1/(serv1.edu  serv2.edu)/' complete with server names
complete find 'c/-/(user group type name print exec mtime fstype perm size)/' c - match the first thing (dash in this case) and complete it with the second thing from the lsit (use TAB or ^D)
complete find \
  'c/-/(user group type name print exec mtime fstype perm size)/'
  'n/-user/u/' \
  'n/-group/g/'
n means "match first thing - and complete it something of a type of a second thing (in this case u - user names, g- group names)"
complete {cd,pushd}  'p/1/d/' same complete rule for 2 commands
complete gunzip 'p/*/f:*.{z,gz,Z}/' restrict completion words by a pattern
complete elm 'c@=@F:/usr/staff/dubois/Mail@' you can use other characters (in this case - @) as a delimiter
complete '=' with the name of actual file

www.dubois.ws/software/csh-tcsh-book/complete.tcsh - many examples of using complete

 
misc home - top of the page -

Making Aliases
Aliases can often be a bit hard to create since one often wants history/variable references expanded at time of use, and not at the definition time.
This has been done easier with The Dot Generator (TDG).

Script example:
#!/bin/tcsh

 foreach f (*.py *.java)
 echo ================================================
 echo $f
 echo ================================================
 cat $f
 end