Skip to main content

Editing files

You need a text editor to edit files on M3. A text editor will have one of two forms:

  • Text-based user interface (TUI): you can use this kind of text editor straight from a terminal. Ideal if you do not have access to a desktop.
  • Graphical User Interface (GUI): a "normal" application in a window where you can use your mouse. Only usable in a desktop environment.

For brevity, we'll only cover using nano here.

Nano

note

We assume you have already connected to an M3 login node. Remember, if you have done this right then you should see a Bash prompt similar to

[lexg@m3-login3 ~]$

Nano is a very simple terminal-based text editor To create a file called my-first-file with Nano, type the following, then press Enter.

nano my-first-file

This creates a file named my-first-file in your current working directory, and opens up the Nano editor. You should see something like below:

alt text

The top of the screen shows we are using GNU nano version 5.6.1, and that the name of the open file is my-first-file. The bottom shows some useful keyboard shortcuts. The empty space in between the top and bottom is where all of the file's text will show.

What does ^G mean?

Here, ^ represents the Ctrl character on your keyboard. So ^G means press Ctrl and g on your keyboard at the same time to open up the Help menu.

Start typing whatever you want into this file. Use Enter to go to a newline, and use the arrow keys to move the cursor around. By default, you cannot use your mouse in Nano.

alt text

Once you are happy with your text file, use Ctrl + o to save your changes. You will see a prompt on the bottom asking you for the File Name to Write. You can leave this as my-first-file (this prompt is mainly useful if you e.g. want to make a new copy of a file rather than overwriting the existing one). To confirm, press Enter.

alt text

You should see a notification at the bottom indicating how many lines of text were written to the file. At this point, you can keep making changes to the file and saving. Once you want to quit Nano, press Ctrl + x.

tip

If you made changes after your last save, pressing Ctrl + x will cause Nano to ask if you want to Save modified buffer?. If you want to save your most recent changes, press y then Enter, otherwise press n then Enter. If you say yes, then you will see the same file-saving interface as when you used Ctrl + o earlier. Once you get through this, Nano should close.

If you want to edit an existing file with Nano, you use exactly the same command as before! This command only creates the file if it didn't already exist.

nano my-first-file

There is much more that Nano can do. Search online for more tips and guides on using Nano. These two resources might be a good start:

Understanding filepaths

If you are not comfortable with Linux filepaths, https://www.redhat.com/en/blog/navigating-linux-filesystem is a brief summary of how they work.

Other options

For all of these, we suggest you search online for beginner guides. Some may already be installed on M3.