Creating files

Unix files are created as soon as their name is used in a command. Where a new file is only to contain a few lines of text, it is convenient to create it using the cat or echo commands.

...with the cat command

Type the command

   cat > name_of_file

Now type in your text. Press the <Return> key to start a new line.

When you have finished typing in your text, enter Ctrl-d (Press and hold down the Ctrl key and type a "d"). This stops the cat command and returns you to the system prompt.

Warning: do not use the name of a file that already exists. If you do, it will be overwritten by the new copy. To avoid this, set the shell variable noclobber.

Example

   cat > memo
   remember to make appointment at opticians
   get cost of scheduled flight to Athens Ctrl-d

This creates a file called memo in the current directory containing two lines of text.

... with the echo command

To create a file, type the command echo and then continue to type the text that you want to appear in the file.

When you have finished typing in your text, type

   > name_of_file

and press the <Return> key. This is useful for creating short files containing only one or two lines of text.

Example

   echo use an editor for large files > tips

This creates a file called tips in the current directory containing a single line of text.