Skip to content

Linux gedit Commands

Overview

gedit is a simple text editor for the GNOME desktop environment. It is known for its ease of use and is suitable for editing text files, programming scripts, and more. This document covers basic gedit commands and operations.

Opening Files

Open a File

To open a file with gedit, use the following command:

gedit <file_name>

Example

gedit example.txt
# Opens 'example.txt' in gedit

Editing Files

Create a New File

To create a new file, simply open gedit without specifying a file name:

gedit

Example

gedit
# Opens a new, untitled document in gedit

Save Changes

To save changes to a file, use the graphical interface:

  1. Click File > Save or press Ctrl + S.
  2. Choose the file name and location, then click Save.

Example

  1. Make edits to the document.
  2. Press Ctrl + S to save.

Save As

To save the file with a new name or location:

  1. Click File > Save As... or press Ctrl + Shift + S.
  2. Enter the new file name and location, then click Save.

Example

  1. Click File > Save As....
  2. Enter a new name like newfile.txt and select the location.
  3. Click Save.

Undo and Redo

To undo or redo changes:

  • Undo: Ctrl + Z
  • Redo: Ctrl + Y

Example

# Press Ctrl + Z to undo the last action
# Press Ctrl + Y to redo the action

Searching and Replacing

Search for Text

To search for text within the file:

  1. Press Ctrl + F.
  2. Enter the search term and press Enter.

Example

  1. Press Ctrl + F.
  2. Type search_term and press Enter.

Replace Text

To replace text within the file:

  1. Press Ctrl + H.
  2. Enter the search term and the replacement term.
  3. Click Replace or Replace All.

Example

  1. Press Ctrl + H.
  2. Enter old_term in the search box and new_term in the replace box.
  3. Click Replace or Replace All.

Other Useful Commands

Open Multiple Files

To open multiple files at once, list them after the gedit command:

gedit file1.txt file2.txt

Example

gedit file1.txt file2.txt
# Opens 'file1.txt' and 'file2.txt' in separate tabs

Open Files from a Directory

To open all text files in a directory:

gedit /path/to/directory/*.txt

Example

gedit /home/user/documents/*.txt
# Opens all '.txt' files in the '/home/user/documents' directory

Open Files with Specific Encoding

To open a file with a specific encoding, use the --encoding option:

gedit --encoding <encoding> <file_name>

Example

gedit --encoding utf-8 example.txt
# Opens 'example.txt' with UTF-8 encoding

Summary

gedit is a versatile text editor with a straightforward graphical interface. It allows for simple text editing tasks such as creating, opening, saving, and searching files. For more detailed information and options, refer to the gedit documentation or the GNOME Help.