The use of aliases in the C shell will be briefly described here.
If one was used to working in a DOS environment and wanted to continue to use the letter combination dir to give a DOS style listing of files in the directory, one could issue the command:
alias dir 'ls -al'
This was make dir an "alias" for the command string ls -al
which would list all files (including those beginning with a period), in
"long" format (with date of last changes, ownership and protections).
This command could be given after the user logged in, but most commonly would be included in the .cshrc file in a section with other aliases.
To see what aliases are determined by the system (along with any personally defined), one merely types the command:
alias
without any arguments.
A very useful alias to create is the "inquiry remove," in which the standard Unix "remove" command, rm, is slightly redefined to inquire whether the user really wants to remove that file. This is particularly helpful if one uses the wildcard symbol, *, in a remove command. Many people have deleted entire directories of files unintentionally because of an incorrect use of the * with rm!
Thus a suggested alias (which should be included in your .cshrc file is
alias rm 'rm -i'
With the Korn shell or POSIX shell, one uses a slightly different version of the alias statement (which must include an equals sign) in places it in the .profile or .login file. See the man pages for sh or ksh for more information.
One common use of this command on Unix work stations would be to start a netscape process and be able to have it active on your screen while editing or doing other things in your work space as well. To invoke netscape in this fashion, the user would type:
math 123:netscape &
Another common use is to be able to edit a program file and then compile it without leaving the editor. For example, one could invoke Emacs on a program file as follows:
math 124:emacs prog3.cxx &
If the user is logged in via CDE or through X-server, an independent
window would open up in which the file prog3.cxx could be
edited and saved. But one would not have to quit the editor
in order to try to execute the file!
One would merely move the cursor to the login window, try to compile the file, and if there were error, go back to the editing window to correct the file.
Subdirectories: Some authors recommend that users create new subdirectories for each course and even create an independent sub-subdirectory for each program in that course. This provides an environment in which only necessary files are located in that directory and irrelevant files are elsewhere.
To create a new subdirectory, one types:
mkdir directory_name
and to connect to that directory, one types:
cd directory_name
if one is in the parent directory. To return to the parent
directory, one types cd .. and to return to the
"home" directory (i.e., the directory you are in when you first
login), one types cd without any argument.
Removing Old Files: Compiled files take up an significant amount of space. After completing a program, one should delete compiled files, such as a.out files or other executable files.
The emacs editor also creates a backup of each file edited and gives the files the same name as the original file, but appends a ~ to the end. One can delete such files, by the command (for example)
rm *.cxx~
This also is good to do every so often to free up space on the
disk.
The currect protection of a file can be seen when giving the "long listing" (ls -l) command. For each file, one see a line such as
4 -rw-r--r-- 1 dsmolars staff 1985 Jul 13 12:56 mp10a.cxxAfter the initial number, there is a - which indicates that this is a file entry (instead of the -, a d indicates a directory, and a l indicates a link (alias) to another file or directory.
After the initial - (or d or l), there are three sets of three letters or -'s. The first three refer to the user's permissions, the second three refer to the group's permissions, and the final three refer to the "world's" permissions.
In this example, the user's permission is rw-, and the group's and the world's permissions are both r--. This means that the user has read (r) and write (w) permission and that the group and world have only read permission.
Often this sequence is translated into a binary and then a decimal code. For example, rw- is translated into 110 (i.e., 1 stands for "yes" and 0 for "no", and 110 means yes for read permission, yes for write permission, and no for execute permission). 110 (in binary) translates into 6 (in decimal). Similarly, r-- translates into 100 or 4 (in decimal). Thus, the permission mode is 644 for the sample file given above.
To change the permission mode, one indicates the new mode number (or indicates a change in the mode number explained on the man page) and the file name. For example to give the "group" and the "world" read and write access to the file, one would type:
chmod 666 mp10a.cxx
REMEMBER: Each of these commands has fuller information on-line obtainable by using the man feature.
cd ~/ma10
The period indicates the current directory, and the double
period the previous directory. Thus, if directory ma10
had two subdirectories, say mp2 and mp3,
and a user is currently in mp2, one
could go from mp2 to mp3 by the command:
cd ../mp3
This references the parent directory of the current directory (..) and
then one of its subdirectories (mp3).
If one needs to go several levels, one indicates the full directory path name, for example.
cd ~/ma10/mp3/secondtry
The use of such path names is also possible with other commands,
such as the copy command to copy files from one directory to
another, such as:
cp ../mp3/progtemplate.cxx .
which would copy the file in a "brother" directory to the current
directory and give it the same name. It may also be used in the
pushd command as well.
This page is maintained by Dennis C. Smolarski, S.J.
dsmolarski@math.scu.edu
© Copyright 1998, 1999 Dennis C. Smolarski, SJ, All rights reserved.
Last changed: 15 April 1999.