DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Writing and editing

Putting text into a file

You can use the cat command to create a file quickly by typing cat > filename. cat creates a file named filename, and puts the text you type into the file, until you tell it you have finished by pressing <Ctrl>D. (The name cat is short for concatenate, or join together; this is another thing the cat command can do.)

   $ cat > todo
   write staff report
   review budget figures
   return doug's call
   <Ctrl>D
Using cat to write a file is like writing a mail message: you can backspace to correct mistakes within a line, but you cannot backspace past the beginning of the line you are on. The vi editor, discussed later in this chapter, lets you correct mistakes anywhere in a file.

Try writing a file with cat:

  1. Type cd; pwd and press <Enter> to make sure you are in your home directory.

  2. Type cat > mytodo and press <Enter> to open up a file called mytodo. Everything you type now goes into mytodo, until you press <Ctrl>D.

  3. Type in the text as shown in the following screen display. Remember to press <Enter> to start each new line.

  4. When you have finished typing the text, go to a new line and press <Ctrl>D.

  5. Type l mytodo and press <Enter> to check that the file was created.
    $ cd; pwd
    /u/susannah
    $ cat > mytodo
    write status report
    fill out timesheet
    buy cat food
    <Ctrl>D
    $ l mytodo
    -rw-rw----   1 susannah techpubs      52 Jun 24 12:12 mytodo
    

Q: What if I see a message like:
mytodo: Permission denied or
mytodo: cannot create?

A: When you see a Permission denied or cannot create message, this means you do not have permission to write in the directory where cat is trying to create a file. (File and directory permissions are covered in ``Protecting files and directories''.) Try changing to your home directory by typing cd and pressing <Enter>, then try opening up your new file there.


Next topic: Filenames
Previous topic: Writing and editing

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005