3.3. Open / Create File

Take a moment to create the directory structure below on Odin. Remember, the . represents your present working directory so you don’t need to explicitly create that folder.

.
└── cs1302
    └── emacs
        └── NOTES.txt
To replicate this scenario, you may have used the following commands to
create the subdirectories and a blank NOTES.txt file. It is fine to use other commands to complete the task. However, take a moment to make sure you understand these:
mkdir -p cs1302/emacs
touch cs1302/emacs/NOTES.txt

Without changing directories, you can open a file specified by the relative path cs1302/emacs/NOTES.txt in Emacs by executing the following command:

emacs cs1302/emacs/NOTES.txt

Alternatively, you can simply execute emacs, then use C-x C-f to find the file you’re trying to open.

To create a file, it is not necessary to first use the touch command. Instead, you can use one of the methods just described with your desired filename. When you create a new file, Emacs will display (New file) at the bottom of the screen. The new file does not exist until you save it, usually using C-x C-s.

Test Yourself

Open the NOTES.txt file you just created and type out some text (anything you want). Once you are finished, use C-x C-s to save the file and C-x C-c to close the file and return to the terminal.

Here is a short screen cast demonstrating the commands in this section in case you got stuck along the way: