Subject: Creating Files and Viewing Existing Files

Software Category: system
Supported by: ACS


Description:

In UNIX you can view existing text files and create new text files using text editors such as vi and emacs, available on most systems. You can also create new files with these editors or by using other commands.


Getting Started:

You can create files with a text editor, such as emacs ("ee-macks"), vi ("vie" or "vee-eye"), or with the command

cat > filename

where filename is the name you wish to give the file. Now type the contents of the file, pressing the Return key at the end. of each line. Press Return when you are finished, and then press CTRL-d (which is the UNIX end-of- file character). When you want to see the contents of the file, enter one of the following commands:

cat filename

or

more filename

replacing filename with the name of the file you want to view. Using cat will make the entire file scroll by on the screen. Using more will make the system display one screenful of text at a time, and display the message ---More--- at the bottom of the screen. Press the SPACEBAR to continue to the next screen. Type q at anytime to quit viewing a file.

You can also view an existing file by using the more or vi commands as shown in the examples above (more filename or vi filename).

To create a new file using emacs, enter the following command:

emacs filename

replacing filename with the name you wish to give the file. Begin typing. To exit emacs, press the CTRL key and and the x key, then release those keys and press the CTRL key and c, then release them. Emacs will ask if you wish to save your file. Enter yes or no.

To create a new file by using vi, the visual editor, enter the following com- mand:

vi filename

replacing filename with the name you wish to give the file. Then:

  1. Type i (to put vi into insert mode).
  2. Type the text that you want to put in the file.
  3. Press the Return key at the end of each line.
  4. When you are finished, press the ESC key (to exit from insert mode).
  5. Type :wq to save (write) your file and, at the same time, quit vi.

You can also use emacs or vi to view an existing document by entering the following command for emacs:

emacs filename

or the following command for vi:

vi filename

In emacs you can scroll through the file using the PageUp and PageDown keys or CTRL-v (scroll up) and ESC-v (scroll down). In vi you can scroll through the file using CTRL-d (scroll down) and CTRL-u (scroll up).


Documentation:

There's an on line manual page on more. To read it, enter the command man more at a UNIX prompt.

For more information about using vi and emacs, please refer to Memo RPI.113, Using UNIX: The Rensselaer Computing System (RCS).


Tips and Hints:

If someone wants you to view a file in his or her public directory, you can do so, but unless you have been given special permission by the owner, you cannot change the file. You can, however, make a copy of it into your own directory.

To view the file file.txt in smithj's public directory, for example, you would enter the following command at a UNIX prompt:

more ~smithj/file.txt

You could also substitute emacs or vi for more.

The ~smithj is a shortcut for typing out smithj's entire home directory path, which you probably don't know anyway. (It might be something like /afs/rpi.edu/home/76/smithj.)


Possible Problems and Solutions:

If you have problems viewing someone's files, it could be that you don't have permissions set to allow you to do so.


Return to ACS Consulting home page.

Return to the General System page.

Return to ACS home page.


Please send comments and suggestions to

consult@rpi.edu