Creating a file with "cat" (for "concatenate")

This is a cheat-sheet for creating a file without using an editor on Unix. It will allow you to create text files for mail messages. This gives you a record of the file in case it gets "lost" in the mail -- losing a file is easier to do than I would like to admit.

There are several steps in the process but the most important thing to remember is that Unix, like all computer systems, is stupider than your below-average goldfish and requires very literal treatment. This means that if you decide to embellish on these instructions the management assumes no responsibility for the consequences. Onward!

Setp 1. Creating the file:

Pick a file name that you will remember in connection with the contents of your proposed file and type:

% cat > filename <ret>

[NOTE: <ret> means to hit the cariage return]

where "filename" is what you want to call the file. File names can be any arrangement of numbers and/or letters but must not contain spaces or punctuation except periods -- i.e. "my.file" and "myfile" are single filenames while "my file" is two filenames and my*file will create problems when you try to open the file again.

Once you hit the return the machine expects you to begin typing your stuff. Remember that "cat" will not wrap lines at the margins like a word-processor -- you must use the return just like on a typewriter. Once you are done typing your file, come to a blank line with another return and type a Control-D (hold the control key down and type a "d").

The machine will return the shell prompt (the %) and you have a file on disk that you can play with and mail to your instructor (or anyone else).

Once the file is created it is time to copy it so that you can afford to screw things up without losing anything (much). Type:

% cp filename newfilename

(note that there are no spaces in either of these filenames!!)

This gives you two identical files -- one to make your mail attempt with and another to copy again if you blow it!

Next list your files again:

% ls

See! you now have two new files! Congratulations. What? You don't have two files? Re-proceed to step 1. Oh, you do have two files. Okay, mail one of them:

% mail account < filename

(as in: % mail za12 < filename)

In this step, the important thing is that you use a less-than sign (<) and not a greater-then sign (>). The penalty for getting things backwards is that the file gets destroyed! (That's why you just made a copy). The account "za12" is mine (Bruce), you should substitute the proper account for the person(s) you want to send to.


(c)Copyright 1985, 1996 by Bruce Jones
Anyone is free to reproduce any of these documents in their entirety or parts thereof providing:
  1. Sections used are reproduced entirely and without alteration
  2. The following page footer is reproduced on each page:
    BJ's UNIX Primer - (c) Bruce Jones - 1985, 1996
  3. Full credit is noted somewhere in the reproduction
Bruce Jones 			Department of Communication
bjones@ucsd.edu			University of California, San Diego
(619) 534-0417/4410		9500 Gilman Drive
FAX (619) 534-7315		La Jolla, Ca. 92093-0503

Comments to: bjones@ucsd.edu


Return to:
Bruce Jones Homepage
BJ's Unix Primer Index
The CommWeb Homepage

This page last updated on: Feb 3 1997