Basic Unix - Appendix C: .login and .cshrc
This appendix introduces two files, .login and .cshrc. This files are only relevant if you are using either the csh or tcsh shells. A shell is like the command prompt in Windows or the terminal in Mac OS X; it's an interface between you and the commands/files of the system. The default shell on NSIT's interactive use server, harper, is tcsh.
Overview
You have two special files in your directory which make customizing your session easy: .login, which is read every time you log in; and .cshrc, which is read each time you begin a new csh or tcsh shell.
On harper, depending on when your account was created, simple .login and .cshrc files may have been installed for you by the system administrators; you are free to change these (the files, not the system administrators) to your heart's content. If you're using a different Unix or Linux system, the existence, or lack thereof, of these files depends on the distribution. If they aren't already in place, you can put them there simply by creating a text file with those names.
This document scope of this document is limited to the csh and tcsh shells; if you are using sh, zsh, ksh, or bash you can begin using tcsh (or csh) simply by entering:
tcsh
at the command line. This loads a new shell on top of your existing one; to change your default shell, you can try either chsh (change shell) or passwd -e. While easier to remember, chsh will not necessarily work on all systems (and does not work on harper). Either way, you'll need to specify the location of the new shell you want to use. You can see a list of available shells by reading the contents of the file /etc/shells:
more /etc/shells
Exploring .login
To see your .login file, type the command:
more .login
This command will display the .login file screen by screen. To see the next screen, simply press the space bar; to see the file one line at a time, press the return key. Your .login file may include lines like the following:
# This forces you to use 'logout' rather than D set ignoreeof # Change the 'vt100' to the type of terminal you normally use. set noglob; eval `tset -sQm 'dialup> 1200:?vt100' '?vt100'`;unset noglob # Show load average and number of users; who is logged on? uptime; users
A pound sign (#) indicates a line which comments on the lines which follow it and are not read by the system.
The commands in this file configure your terminal so that you will not accidentally log out if you enter a ^D (Control-D); set up your terminal so that you can use certain convenient commands; show you who else is on the system; and, display any system messages.
As you gain experience and confidence with Unix, you will probably want to customize your .login file to suit your own particular needs. You may edit .login files as you would any other file, using your preferred text editor (such as pico, emacs or vi). A simple way to change the .login file is to add options to some of the commands already contained in pre-existing file (when there is one).
To learn what options are available for each command, look up the command in the man pages, via the `man' command.
(You may also create a .logout file, containing commands to be executed each time you log out; .logout files are not very common, but they can occasionally be useful.)
Exploring .cshrc
The ".cshrc" file customizes work in the C shell (csh) and Tenex-extended C shell (tcsh) even further. A .cshrc looks much like a .login, and may be viewed the same way. The difference between them is that while .login is only invoked if the shell is a login shell, the .cshrc file is read whenever csh or tcsh are invoked.
If you want to be able to run a command in your friend's directory, or if you want to continue having a .cshrc file but your current one is configured so that Unix can't find a common command, you will need to edit your .cshrc file.
There are two changes you might want to make in your .cshrc file so that Unix would be able to run a program for which it currently says "Command not found." You can either create an alias for that specific program, or change your path so that Unix checks the directory where that program is when you type in a command.
Creating an Alias
In order to create an alias which will run a program not in your path, you need to know the full absolute path name of that command. (For more on absolute vs. relative path names, see Basic Unix, Part 3: The Unix File System,.) Then you should edit your .cshrc file with your preferred Unix editor (but be careful; lines in your .cshrc file may be over 80 characters and should not be automatically wrapped!) and add a line saying:
alias commandname /full/absolute/path/of/program
The alias command substitutes the final command for the middle command whenever you type it, so that when you type commandname, Unix automatically substitutes /full/absolute/path/of/program and knows where to find the program in question. Since the alias command is in your .cshrc, the alias command is executed every time you log into Unix, and therefore Unix always knows to substitute the latter command for the former.
Changing Your Path
As explained above, your .cshrc file includes a list of directories which are searched for an appropriate program when you type in a command. That list of directories is in a line saying
#set path = ( list of directories separated by spaces ) #e.g. the default path command is set path = ( $HOME/bin /usr/ccs/bin /opt/bin /opt/SUNWspro/bin /usr/bin /usr/ucb . ) #and a path statement in your .cshrc would probably say: set path = ( $HOME/bin /directory/to/add $path )
When you type in a command, Unix checks the directories in your path, starting with the first (leftmost) directory and going on (right) from there, and looks for a program named that command.em> Please note that the set path command, like all the commands in your .cshrc, must be a single line regardless of how long that line is.
The $HOME/bin means your own home directory with /bin appended to it. If you have such a personal bin directory, it should be first in your path, so that if you compile your own program and put it in your personal bin directory, Unix will find your copy before it finds a system-wide installed program.
The $path means the path that you have before the set path command takes effect. It should always be included when you set your path in your .cshrc so that you don't exclude the directories which are put in your path by the default Unix settings.
Activating Your .cshrc and .login Changes
Whether you add an alias to your .cshrc or change your path, you will need to activate your .cshrc before the changes take effect. Since your .cshrc file is automatically activated when you log in, the simplest way to activate your .cshrc is by disconnecting and logging back in. You can also activate your new .cshrc with the source command:
source .cshrc
Please note, however, that the source command does not deactivate your old .cshrc settings; it simply uses the settings in your new .cshrc, which will override the old settings when appropriate.
Last updated: 10/03/06