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.
Command Line
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.
Hi Jarrod,
Thanks a lot for doing this!
I’m studying for the RHCSA exam and your publications are super-useful. Please continue!
Thank you!
Hey thanks for letting me know! I still want to write more articles I just have a lot of other projects going on at the moment :)
I totally understand. :)
Am a seasoned linux sysadmin starting my RHCSA, RHCE journey. Had previously taken LPIC 2.Target RHCSA in one month.
Thanks for the few topics you have covered. Will provide feedback on how to approach when am done with the exam.
For the time being, several mugs of coffee will do :-).
Good luck!
Interested in getting email alert on new topics.
Jarrod, Don’t stop now. You got some great stuff going on here.
Thanks, just hard to find time with other projects unfortunately.
Excellent writeup!
Amazing content you have here. It is hard to find high-quality content in the online world.