Unix 7 -- More Common Unix Practices

Math 10 -- D. C. Smolarski, S.J.
Santa Clara University, Department of Mathematics and Computer Science

[Return to Math 10 Homepage | Return to Math 61 Homepage]
[Return to Unix 6 Page | Go to Unix 8 Page ]

Contents


Aliases

The C shell and the Korn shell (and certain other shells) give the user the ability to define certain letter combinations as commands, thereby creating an "alias." Each shell does this in a slightly different way. For details, please see the man pages for the particular shell and search for the word "alias."

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.

Common Unix Practices

Spawning Processes: Unix has a feature when permits one program (process) to run simultaneously with another. This is often called running a program in the "background." A process can be spawned to run a program in the background if the command line for the program is terminated with an ampersand (&) before the enter key is pressed.

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.

More Helpful Unix Commands

More helpful commands:

REMEMBER: Each of these commands has fuller information on-line obtainable by using the man feature.

Directory Path Names

The tilde, ~, indicates the user's home directory. Thus, if one is several levels into a directory tree, one can return to a directory one level below the home directory by a command such as
     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.

Internal Commands for more and man

When using either the more or man commands, while reading the text of the file (or manual page), the following commands are possible:
[Return to Math 10 Homepage | Return to Math 61 Homepage]
[Return to Unix 6 Page | Go to Unix 8 Page ]

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.