Being able to create and edit text files in Red Hat Enterprise Linux (RHEL) 8 is a simple yet important task.
In these examples we will cover the Red Hat Certified System Administrator (RHCSA) objective “Create and edit text files”, both through the graphical user interface and command line.
Graphical User Interface
If your installation of Red Hat Enterprise Linux (RHEL) 8 comes with the graphical user interface (GUI) installed, the default, you can open the text editor by following these steps:
- Click “Activities” towards the top left hand corner of the screen.
- Select the icon towards the bottom from the bar on the left, allowing you to see more applications.
- Click on “Text Editor”
Note that this process may differ depending on what display manager your installation is using, this example was done with a fresh default installation of RHEL 8.
Once opened, you’ll have access to a standard text editor where you can write content and then choose where to save the file.
The GUI may not always be available, for instance if you’re editing a text file through SSH, so it is important to know how to create and edit text files through the command line interface (CLI).
In this example we’ll be using the ‘vi’ text editor, as it is always available by default within RHEL – perfect for the RHCSA exam. It’s not very beginner friendly unfortunately, so we’ll only be covering the basics of creating and editing text files. Here’s a great game which will help you learn and get better with Vim (vi-improved, basically a newer more modern version of vi).
To edit an existing file, simply enter ‘vi <filename>’ which will open up the file in the vi text editor. If ‘filename’ does not exist, once you save your changes the new file will be created.
In the example below we are creating a new file called ‘testing’ in the current working directory (the home directory of ‘user’, as identified by the ‘~’ symbol at the end of the bash shell).
This is what the vi text editor looks like by default.
At this point vi is in command mode, you cannot yet start typing. To enter text, press ‘i’ to enter insert mode. Insert mode is identified by the – – INSERT – – text down the bottom left corner.
With insert mode activated, we can now edit the text file by typing normally.
Once complete, press the escape key to leave insert mode and go back to command mode. Next we want to save the file and exit vi. To do this, enter ‘:wq’ as shown down the bottom left corner of the screen. The ‘w’ means write the file, so save it, and the ‘q’ means quit vi.
You can of course just use ‘w’ only to save the file without exiting vi. You could also use ‘:q!’ to quit without saving the changes. Combining these into a ‘:wq!’ will save the changes, overwrite the files even if it’s read only if the user account has the privileges and exit vi.
Finally we can check that our new file exists and contains the contents expected.
That’s it, you should now have a basic understanding of how to create and edit text files in RHEL 8 for the RHCSA exam. Make sure you practice these examples yourself to get a full understanding on how the commands work, new Linux users often have trouble escaping vi!
This post is part of our Red Hat Certified System Administrator (RHCSA) exam study guide series for Red Hat Enterprise Linux (RHEL) 8. For more RHCSA related posts and information, see our full RHCSA 8 study guide.