Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to Edit Multiple Files in Vim Editor in Linux
Next article icon

How to Edit Text Files in Linux: Proven 3 Methods

Last Updated : 13 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Need to tweak a file in Linux but not sure where to start? Editing text files in Linux is a handy skill that can help you fix settings, write scripts, or just note down notes all from your keyboard. This blog is here to help you get started, even if you’re new to Linux. We’ll show you simple ways to edit files without needing any fancy apps.

You’ll learn about easy tools like "nano", "vim", and "Emacs" that work right in the terminal. No hard steps or confusing stuff—just quick tips to help you edit files fast. Whether you’re tweaking something small or starting from scratch, we’ll guide you through it.

how-to-edit-text-files-in-Linux-copy
Edit Text Files in Linux

What is Text File in Linux?

In Linux, a text file is a type of file that stores information as plain text in human-readable characters. Text File or TXT file is a widely compatible text format with a small file size. It doesn't include complex formatting, making it easy for users to create, edit, and view using text editors. Text files commonly end with extensions like .txt. and can be edited with simple text editors.

Using Command-Line Text Editors

Command-line text editors are the preferred tools for file editing for a large number of Linux users. These editors are ideal for making fast edits or working on distant servers because they are lightweight and powerful. Some of the most well-liked command-line editors are listed below:

1. Nano

Nano is a user-friendly text editor that is perfect for beginners. It is easy to use and comes pre-installed on most Linux distributions.

How to edit text files in Linux using Nano:

Step 1: Open the terminal.

Command: Ctrl + Alt + T 

Step 2:Type ` nano filename.txt ` and press Enter.

Step 3:Edit the text file as needed.

Step 4:To save the file, press ` Ctrl + O `, then Enter.

Step 5:To exit Nano, press ` Ctrl + X `.

2. Vim

Vim is a powerful and flexible text editor, widely used by developers and system administrators. It has a steep learning curve but offers advanced features.

How to edit text files in Linux using Vim:

Step 1: Open the terminal.

Command: Ctrl + Alt + T 

Step 2: Type ` vim filename.txt ` and press Enter.

Step 3: Press ` i ` to enter insert mode and start editing.

Step 4:Press Escto exit insert mode.

Step 5: To save and exit, ` type :wq ` and press Enter.

3. Emacs

Emacs is another robust text editor that is highly customizable. It offers a wide range of features, including a built-in file manager and support for multiple programming languages.

How to edit text files in Linux using Emacs:

  • First install Emacs by the writing the command in the terminal :-
 Command: apt  install e3
Emacs
Install Emacs

Step 1: Open the terminal.

Command: Ctrl + Alt + T 

Step 2: Type ` emacs filename.txt ` and press Enter.

Step 3: Edit the file directly

Step 4: To save the file, press ` Ctrl + X ` followed by ` Ctrl + S `.

Step 5: To exit Emacs, press ` Ctrl + X ` followed by ` Ctrl + C `.

Using Graphical Text Editors

If you prefer a graphical interface, Linux also offers several graphical text editors that are user-friendly and feature-rich.

1. Gedit

Within the GNOME desktop environment, Gedit is the default text editor. With plugin support and syntax highlighting, it's easy to use yet extremely effective.

How to edit text files in Linux using Gedit:

  • Locate the text file by opening the file manager and opening it.
  • When you do a right-click on the file, choose "Open with Gedit."
  • Make changes to the file and save it.

2. Kate

The KDE desktop environment includes Kate, a potent text editor. It has sophisticated features like syntax highlighting and enables multiple document editing.

How to edit text files in Linux using Kate:

  • From the apps menu, launch Kate.
  • Drop the text file into the Kate window by dragging it there.
  • After making changes, click "Save" to close the file.

Conclusion

Whether you use a graphical editor like Gedit or Kate, or a command-line editor like Vim, Emacs, or Nano, editing text files in Linux is a simple task. Gaining proficiency with these tools will enable you to effectively manage and edit files on your Linux system, streamlining and increasing productivity.


Next Article
How to Edit Multiple Files in Vim Editor in Linux
author
sourabh_jain
Improve
Article Tags :
  • TechTips
  • linux

Similar Reads

  • How to edit PDF files using PDFedit In Linux?
    PDF (Portable Document Format) files are widely used for sharing documents due to their platform independence and consistent formatting. While PDF files are known for their static nature, there are occasions when you may need to make edits or modifications to the content. Fortunately, Linux offers v
    4 min read
  • How to Open a File in Linux​
    In Linux, a file is a fundamental unit of storage, representing everything from documents and images to system logs and program data. Unlike traditional operating systems, Linux treats almost everything—files, directories, devices, and processes—as a file. Whether you're accessing a simple text docu
    6 min read
  • How to Edit Multiple Files in Vi Editor in Linux
    Vi, short for "visual editor," is a powerful and ubiquitous text editor in the Linux ecosystem. Among its many features, one of the most useful is its capability to edit multiple files simultaneously. This ability streamlines the editing process, especially when dealing with projects that span multi
    4 min read
  • How to Set File Permissions in Linux
    Ever worried about who can access, modify, or execute your critical files on a Linux system? File permissions are the backbone of Linux security, ensuring that only authorized users and processes interact with your data. In this guide, you’ll learn how to master Linux file permissions using commands
    10 min read
  • How to Edit Multiple Files in Vim Editor in Linux
    Vim, short for "Vi Improved," is a highly configurable and powerful text editor built upon the foundation of Vi. Like its predecessor, Vim offers robust support for editing multiple files simultaneously, making it an indispensable tool for developers, system administrators, and anyone working extens
    4 min read
  • How to Compare Local and Remote Files in Linux
    In this article, we will discuss how to compare or differentiate between local and remote files in Linux. Programmers and writers often want to know the difference between two files or two copies of the same file when writing program files or regular text files. The discrepancy between the contents
    3 min read
  • How to search and replace text in a file in Python ?
    In this article, we will learn how we can replace text in a file using python. Method 1: Searching and replacing text without using any external module Let see how we can search and replace text in a text file. First, we create a text file in which we want to search and replace text. Let this file b
    5 min read
  • How to Run a File in Linux
    The command line is one of the most powerful tools in Linux. It allows you to execute commands, manage files, and automate tasks all from a single terminal window. One common task you'll often need to do is run a file, whether it’s a script, a compiled program, or even a text file. In this article,
    6 min read
  • How to Read Text File Into List in Python?
    In this article, we are going to see how to read text files into lists in Python. File for demonstration: Example 1: Converting a text file into a list by splitting the text on the occurrence of '.'. We open the file in reading mode, then read all the text using the read() and store it into a variab
    2 min read
  • How to Get the Full Path of a File in Linux
    While dealing with files on Linux, especially shell scripts, one may require determining the full path of a file at times. Now, let's consider several methods of getting the full path of a file in Linux. In this article, we will be discussing several different solutions to a popular problem. Before
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences