UNSW   Faculty of Engineering PRINT VERSION SITE MAP  
cse | School of Computer Science and Engineering (CRICOS Provider No. 00098G)
    #About CSE     #Undergraduate Study     #Postgraduate Study     #Timetables & Courses     #Research & Publications     #People & Work Units     #Help & Resources     #News & Events     #High School Portal

Last updated 19.02.08


Creating a File

You will normally use an editor to create your files. There are several different editors available for your use on the CSE machines. These include nedit, pico, nano, ed, ex, vi and emacs. The editor that you choose to use is entirely up to you and may change depending on the task. For the moment we will use one of the simplest, and you may think most primitive, editors that is available on all UNIX systems, regardless of flavour -- ex.

To create a file called stuff with some text in it, log on as described above, and proceed as follows (NOTE: words within `()' pairs are there as comments to the reader and should not be typed when trying out this example.)

    % ex stuff            (this invokes the ex editor)
    "stuff" [New file]    (message to indicate that stuff is a new file)
    :a                    (command to ex to add, or append, text to file)

    Now you type in any text
    that you want, it does not
    really matter what it is !

    .                     (the `.' signals the end of input)
    :wq                   (write out the file and quit from ex )
    "stuff" [New file] 3 lines, 78 characters

For the moment we shall dispense with an explanation of the ex syntax; it will all become clearer should you choose to pursue your knowledge of vi.

Another simple and quick way of creating a file is to use a combination of a couple of simple UNIX commands, echo and > as shown below.

        % echo "Now you type in any text" > junk

The echo command echoes its arguments to standard output, which is the terminal, by default. The output from this echo command is redirected to a file, in this example junk, using the > character. Input/output redirection is described in more detail in section 3.8, page [*].

You could also use the cat command to create a file as shown below:

        % cat > myfile.txt
        Again you type all the stuff that you want to 
        and then to signal the end of the input
        you hold done the control key on the left hand
        side of the keyboard, and press the d key.
        ^d

In this example, the cat command reads its input from standard input. The output of the cat command is redirected to the file myfile.txt. The Control-d (^d) signals the end of input to the cat command.

nedit is a commonly used basic editor with a point and click, pull down multiple menus type of interface. It is simple to use but its functionality is limited. emacs and vi, on the other hand, are full screen text editors which, with experience, will allow the user to work in a much more efficient and productive environment than basic editors offer. They both have a steep learning curve for advanced usage and are extremely useful and powerful once this has been established.

Loc Van Huynh 2007-03-15
Top Of Page

 ###
Site maintained by webmistress@cse.unsw.edu.au
Please read the UNSW Copyright & Disclaimer Statement