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 do not need to explicitly create that folder.

.
└── cs1302
    └── emacs
        └── NOTES.txt

To replicate this scenario, you may use the following commands to create the subdirectories and a blank NOTES.txt file:

mkdir -p cs1302/emacs
touch cs1302/emacs/NOTES.txt

3.3.1. Opening an Existing File

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

emacs cs1302/emacs/NOTES.txt

Alternatively, you can launch emacs directly and then use the C-x C-f (find-file) key binding. When prompted in the minibuffer at the bottom of the screen, type the relative or absolute path to the file and press RET. You can also press TAB to auto-complete directory and file names.

3.3.2. Creating a New File

To create a file, it is not necessary to first use the touch command. Instead, you can launch Emacs with your desired new filename (e.g., emacs cs1302/emacs/NOTES.txt) or press C-x C-f from inside Emacs and type the new filename.

When you specify a non-existent file, Emacs will display (New file) at the bottom of the screen. The new file is held in an editing buffer and is not written to disk 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 (such as a sentence about what you plan to learn in CSCI 1302). Once finished, use C-x C-s to save the file and C-x C-c to exit Emacs and return to the terminal shell prompt.

Step-by-Step Solution
  1. Open the file in Emacs:

    emacs cs1302/emacs/NOTES.txt
    
  2. Type your text directly into the buffer.

  3. Save your changes by pressing C-x C-s (Hold CTRL, press x, then press s). Emacs will display a confirmation message such as Wrote /path/to/NOTES.txt in the echo area at the bottom.

  4. Exit Emacs by pressing C-x C-c (Hold CTRL, press x, then press c).

Here is a short screencast demonstrating the commands in this section: