Introduction
Text editing is a fundamental skill for anyone working with Linux systems. Whether you're creating configuration files, writing scripts, or taking notes, knowing how to efficiently create and edit text files is essential. In this lab, you will learn to use gedit, a beginner-friendly graphical text editor available in most Linux distributions. Unlike command-line editors such as nano or vim, gedit provides a familiar graphical interface with menus, toolbars, and visual feedback that makes text editing more accessible for newcomers to Linux.
Getting Started with gedit
In this step, you will learn how to open gedit and create your first text file. Gedit is a graphical text editor that comes pre-installed on many Linux distributions, including Ubuntu.
First, let's navigate to our project directory. Open a terminal by clicking on the terminal icon in the dock or pressing
Ctrl+Alt+T, then type:cd ~/projectThis command changes your current directory to
/home/labex/project.Now, let's launch gedit to create a new file. In the same terminal, type:
gedit first_note.txtThis command opens gedit with a new file named
first_note.txt. If the file already exists, it will open that file for editing.You should now see the gedit window with an empty document. Type the following text:
HelloTo save your file, press
Ctrl+Sor click on the menu optionFile > Save. The file will be saved in your current directory (~/project).You can confirm that your file has been saved by checking the title bar of the gedit window - it should display the filename without an asterisk, which would indicate unsaved changes.
Close gedit by clicking the
Xin the top-right corner of the window or by selectingFile > Quitfrom the menu.Verify that your file was created by listing the files in your project directory:
ls -lYou should see
first_note.txtin the output, similar to:-rw-rw-r-- 1 labex labex 6 Jul 15 10:30 first_note.txt
Editing Existing Files with gedit
In this step, you will learn how to open and edit existing files using gedit. You'll also explore some basic editing features.
Let's open the file you created in the previous step. In the terminal, type:
gedit first_note.txtGedit will open the existing file and display its contents.
Now, place your cursor at the end of the text you previously wrote, press
Enterto create a new line, and type:WorldYour file should now contain:
Hello WorldNotice that gedit automatically shows an asterisk (*) next to the filename in the title bar, indicating that there are unsaved changes.
Save your changes by pressing
Ctrl+Sor selectingFile > Savefrom the menu. The asterisk should disappear, indicating that all changes have been saved.Let's explore some useful gedit features:
- To select text, click and drag with your mouse
- To copy text, select it and press
Ctrl+C - To paste text, place your cursor where you want the text and press
Ctrl+V - To find text, press
Ctrl+Fto open the search bar
Try selecting the word "World" and copying it (with
Ctrl+C). Then place your cursor at the end of the file, pressEnterfor a new line, and paste it (withCtrl+V).Practice these operations, and when you're done, save your file with
Ctrl+Sand close gedit.You can verify the contents of your file from the terminal using the
catcommand:cat first_note.txtThis should display the contents of your file in the terminal.
Creating a Reference File
In this step, you will create a more comprehensive text file using gedit to demonstrate how useful a text editor can be for creating reference materials or documentation.
Open gedit to create a new file for storing common Linux commands:
gedit linux_commands.txtIn this file, you'll create a simple reference guide for basic Linux commands. Type the following content into the file:
Basic Linux Commands Reference: ls - List files and directories cd - Change directory mkdir - Create a new directory rm - Remove files or directoriesExperiment with basic text formatting in gedit:
- Select a line and press
Ctrl+Bto make it bold (if supported in plain text) - Try other formatting options from the Format menu
Note: Plain text files (.txt) won't retain formatting like bold or italic, but gedit allows you to see formatting while editing.
- Select a line and press
Save your file by pressing
Ctrl+Sor using theFile > Savemenu option.Let's add more content to our reference guide. Add these additional commands:
cp - Copy files or directories mv - Move or rename files pwd - Print working directory (show current directory) touch - Create an empty fileGedit includes a spell checker. Enable it by clicking on
Tools > Check Spellingin the menu. Any misspelled words will be underlined in red.When you're satisfied with your reference guide, save the file and close gedit.
You can view your completed reference guide using the
catcommand:cat linux_commands.txtYou should see all the commands you documented displayed in the terminal.
Advanced gedit Features and Customization
In this final step, you'll explore some advanced features of gedit and learn how to customize it to suit your preferences.
Open gedit with a new file:
gedit example.pyLet's experiment with search and replace functionality. Type the following text:
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog again.Now let's replace all occurrences of "fox" with "cat":
- Press
Ctrl+Hto open the Find and Replace dialog - In the "Search for" field, type
fox - In the "Replace with" field, type
cat - Click "Replace All"
All occurrences of "fox" should now be replaced with "cat".
- Press
Clear the file and add the following Python code:
def greet(name): print(f"Hello, {name}!") greet("World")Notice how gedit automatically applies syntax highlighting for Python code, making different parts of the code appear in different colors. This feature helps in reading and writing code more efficiently.
Save the file by pressing
Ctrl+S. Gedit should already recognize this as a Python file from the extension.Let's customize gedit to make it more comfortable for coding:
- Click on
Edit > Preferencesin the menu - Click on the "Font & Colors" tab
- Experiment with different color schemes from the "Color Scheme" dropdown
- Click on the "Editor" tab
- Enable "Display line numbers" for easier navigation
- Set "Tab width" to 4 spaces, which is common in Python
- Click "Close" to apply your changes
- Click on
Gedit also supports plugins to extend its functionality:
- Open Preferences again (
Edit > Preferences) - Click on the "Plugins" tab
- Browse through the available plugins and enable a few that interest you, such as "File Browser Panel" or "Code Comment"
- Click "Close"
- Open Preferences again (
Try out any plugins you enabled. For example, if you enabled the "File Browser Panel":
- Click on
View > Side Panelto show the side panel - Use the file browser to navigate and open files
- Click on
Save your Python file and close gedit when you're done exploring.
You can run your Python script from the terminal to see if it works:
python3 example.pyYou should see the output:
Hello, World!
Summary
In this lab, you have learned the fundamentals of graphical text editing in Linux using gedit. You have mastered essential skills including:
- Opening and launching gedit, a popular graphical text editor
- Creating and saving new text files
- Opening and editing existing files
- Using basic editing operations like copy, paste, and find/replace
- Creating structured content with proper formatting
- Exploring advanced features like syntax highlighting and plugins
- Customizing gedit to match your preferences
These text editing skills are crucial for various Linux tasks, from writing simple notes to editing configuration files or creating scripts. As you continue your Linux journey, the ability to efficiently create and edit text files will be an essential part of your toolkit. Gedit provides a user-friendly bridge between the simplicity of command-line editors and the complexity of full-featured IDEs, making it an excellent choice for both beginners and experienced users.



