How to Open, Create, Edit, and View a File in Linux?

Learn via video courses
Topics Covered

Linux, a prevalent open-source operating system, supports diverse file formats, including text, audio, video, images, and documents. Opening files in Linux involves utilizing its array of text editors, file managers, and command-line interfaces. For newcomers, navigating Linux commands like cat and ls is essential, as it differs from conventional methods like opening files in Notepad. This article elucidates three distinct methods to effortlessly access and view files within the Linux environment. Mastery over these techniques ensures efficient file management, catering to the needs of programmers, IT professionals, and general users interfacing with Linux systems.

Text Editors Available for Linux

Linux systems offer various text editors to choose from. The two primary types of text editors available for Linux are GUI text editors and terminal-based text editors.

GUI Text Editors

GUI text editors are those text editors that provide a graphical interface for editing text files. These editors are typically designed for ease of use and offer many features such as syntax highlighting, auto-indentation, and code completion, etc. Some of the popular GUI text editors for Linux include Gedit, Nedit, Sublime Text, Kate and Geany, etc. Now, let's talk about some popular GUI-based text editors and how to install and use them in linux operating system:

Gedit

  • It is a popular GUI-based text editor for Linux that comes pre-installed with many Linux distributions, including Ubuntu, Fedora, and Debian. It is a compact and user-friendly editor that offers many functions for creating and editing text files, including syntax highlighting, search and replace, and file comparison.
  • One of the standout features of Gedit is its intuitive and simple interface, which makes it very easy to navigate and use, even for new users. The interface is designed to be very clean and simple, with menus and toolbars that are easily understandable. Gedit also offers various customization options that allow the user to customize the editor according to their preferences, like changing the font size or adding plugins.
  • It supports several programming languages, such as Python, Java, C++, and HTML. It also includes syntax highlighting for each of these languages. This feature highlights various code components, such as keywords, variables, and comments, making it simpler for developers to understand and update the code.
  • If you are using Ubuntu or Debian Linux, you can install Gedit using the following command:

gedit

Nedit

  • Nedit is a popular Linux text editor having a graphical user interface (GUI) for editing text files. It includes capabilities like syntax highlighting, search and replace, and macro recording to assist users in creating and editing text files. Nedit's interface is basic and straightforward, making it simple to explore and use even for inexperienced users.
  • Nedit's ability to handle multiple tabs is one of its distinguishing features, allowing users to work on many files at the same time. Nedit also allows the users to customize the font size and color, as well as keyboard shortcuts, making it simpler to work with.
  • Nedit is especially popular among developers because it supports a wide range of programming languages, including C, C++, Java, Python, and HTML, and it includes syntax highlighting for each of these languages, making it easier for developers to understand and edit their code.
  • If you are using Ubuntu or Debian Linux, you can install Nedit using the following command:

nedit

Sublime Text

  • Sublime Text is a popular text editor for programmers that is accessible on a variety of platforms such as Linux, macOS, and Windows. It is well-known for its speed, versatility, and wide plugin support, making it a very useful tool for developers.
  • Sublime Text's user interface is one of its most notable aspects. I0t is extremely customizable and can be tailored to the demands of individual users. The interface is basic and tidy, with a minimalist design that focuses on the material being edited. Sublime Text also has a variety of color schemes and themes, as well as the option to design your custom themes.
  • C, C++, Java, Python, and HTML are among the programming languages supported by Sublime Text. Each of these languages has syntax highlighting and auto-completion, making it easier for developers to write and update code. Multiple cursors, split editing, and fuzzy searching are also available in Sublime Text to aid in code navigation and editing.
  • Sublime Text's plugin support is one of its most significant features, allowing users to enhance the editor's capabilities with custom plugins. Sublime Text has dozens of plugins that cover everything from linting and debugging to version control and package management.
  • You can install sublime text in Ubuntu by installing it from the Ubuntu Software store.

sublime test

  • After installing it, you can use the unregistered version:

sublime test unregistered version

Kate

  • Kate is a popular Linux text editor with a graphical user interface (GUI) for editing text files. It includes capabilities such as syntax highlighting, search and replace, and code folding to assist users in creating and editing text files. Kate offers a straightforward and user-friendly layout that is simple to explore and use, even for inexperienced users.
  • Kate's support for multiple tabs and split views is one of its distinguishing features, letting users work on numerous files at the same time or view the same file in multiple locations. Kate also provides customization options, such as changing the font size and color, as well as keyboard shortcuts, to make it easier to use.
  • Kate is particularly popular among developers since it supports a wide variety of programming languages, including C, C++, Java, Python, and HTML. It contains syntax highlighting for each of these languages, as well as auto-completion and code snippets, to make writing and editing code easier for developers.
  • If you are using Ubuntu or Debian Linux, you can install Kate using the following command:

kate

Geany

  • Geany is a lightweight and fast Linux text editor with a graphical user interface (GUI) for editing text files. It includes features like syntax highlighting, auto-completion, and code folding to assist users in creating and editing text files. Geany offers a straightforward and user-friendly layout that is simple to navigate and use, even for inexperienced users.
  • Geany's support for many file types, including programming languages such as C, C++, Java, Python, and HTML, is one of its most notable features. Geany offers syntax highlighting for each of these languages, as well as auto-completion for symbol names and basic project management capabilities.
  • Geany also provides a variety of customization options, including plugin support, so users can tailor the editor to their specific needs.
  • If you are using Ubuntu or Debian Linux, you can install Geany using the following command:

geany

Terminal-Based Text Editors

Terminal-based editors are text editors that operate fully within a terminal window and do not require a graphical user interface (GUI). These editors are popular among command-line developers because they allow for quick and efficient editing of text files without the need for a separate program window.

Vim, Emacs, and Nano are some the examples of terminal-based editors. These editors provide a variety of capabilities to assist users in creating and editing text files, such as syntax highlighting, search and replace, and macro recording. Now, let's discuss them in detail:

Nano

  • Nano is a well-known terminal-based text editor for Linux and other Unix-like operating systems. It is a simple and user-friendly editor that is intended to be simple for beginners while also having enough features to be useful for advanced users.
  • Nano comes with standard functionality including syntax highlighting, search and replace, and copy and paste. It also supports keyboard shortcuts, which makes it simple to navigate and edit text files. Nano, which is available on practically all Linux distributions and can be used from the command line, is especially handy for altering configuration files and other system files.
  • If you are using Ubuntu or Debian Linux, you can install Nano using the following command:

Vim

  • Vim stands for Vi Improved and is a well-known text editor for Unix-based operating systems such as Linux, macOS, and BSD. It is a command-line interface (CLI) editor that includes syntax highlighting, search and replace, macros, and keyboard shortcuts for editing text files.
  • Vim's modal editing system, which allows users to switch between different modes for different activities, is one of its most notable features. Vim provides a set of commands for accessing and editing text files in normal mode, while insert mode allows users to immediately enter text into the file. Because users may easily transition between modes to do different activities, this strategy enables fast and efficient editing.
  • If you are using Ubuntu or Debian Linux, you can install Vim using the following command:

Emacs

  • Emacs is a well-known text editor for Unix-based operating systems such as Linux, macOS, and BSD. It is a command-line interface (CLI) editor that includes syntax highlighting, search and replace, macros, and keyboard shortcuts for editing text files.
  • One of Emacs' most notable characteristics is its extensibility, which allows users to tailor the editor to their specific needs. Emacs comes with a built-in scripting language called Emacs Lisp, which may be used to write custom macros, add plugins for more functionality, and adjust the editor's behavior. This technique enables users to customize Emacs to their workflow, making it a valuable tool for programmers, authors, and academics.
  • If you are using Ubuntu or Debian Linux, you can install Emacs using the following command:

How to Create and Edit Text Files in Linux by Using Terminal?

Creating file in linux and editing file in Linux using a terminal-based text editor is a straightforward process. Let's see how we can do the same for some of the editors:

Nano

Below steps can be performed to create a new file and edit it using Nano:

  • Open a new terminal window.

    nano new terminal window

  • Navigate to the directory where you want to create the text file using the cd command.

    navigate

  • To create a new file using nano, type "nano filename.txt" and press Enter.

  • Type the text you want to include in the file.

    type the text

  • Save the file by pressing Ctrl+O and then Enter (in nano). save file

  • Exit the text editor by pressing Ctrl+X (in nano).

  • Now, we can see the created file using the ls command.

    see the file

Vim

Below steps can be performed to create a new file and edit it using Vim:

  • Open a new terminal window.

    vim terminal window

  • Navigate to the directory where you want to create the text file using the cd command. navigate

  • To create a new file using nano, type "vim filename.txt" and press Enter.

  • Type the text you want to include in the file.

    type the test

  • Save the file by pressing the ESC button, then after getting in command mode, type and press enter to save the file.

    save file

  • Exit the text editor by typing command and then pressing enter.

    exit

  • Now, we can see the created file using the ls command. see the file

Conclusion

  • In this article, we understood everything about linux open files, creating and editing files in linux.
  • We learned about the types of text editors available in linux.
    • We understood what are GUI-based editors and looked at some examples.
    • We learned about different terminal-based text editors.
  • Then we learned how to Create and Edit Text Files in Linux by Using Terminal.