Linux console edit file

How to open, create, edit, and view a file in Linux

One thing GNU/Linux does as well as any other operating system is give you the tools you need to create and edit text files. Ask ten Linux users to name their favorite text editor, and you might get ten different answers. On this page, we cover a few of the many text editors available for Linux.

GUI text editors

This section discusses text editing applications for the Linux windowing system, X Windows, more commonly known as X11 or X.

If you are coming from Microsoft Windows, you are no doubt familiar with the classic Windows text editor, Notepad. Linux offers many similar programs, including NEdit, gedit, and geany. Each of these programs are free software, and they each provide roughly the same functionality. It’s up to you to decide which one feels best and has the best interface for you. All three of these programs support syntax highlighting, which helps with editing source code or documents written in a markup language such as HTML or CSS.

NEdit

NEdit, which is short for the Nirvana Editor, is a straightforward text editor that is very similar to Notepad. It uses a Motif-style interface.

The NEdit homepage is located at https://sourceforge.net/projects/nedit/. If you are on a Debian or Ubuntu system, you can install NEdit with the following command:

For more information, see our NEdit information page.

Geany

Geany is a text editor that is a lot like Notepad++ for Windows. It provides a tabbed interface for working with multiple open files at once and has nifty features like displaying line numbers in the margin. It uses the GTK+ interface toolkit.

The Geany homepage is located at http://www.geany.org/. On Debian and Ubuntu systems, you can install Geany by running the command:

Gedit

Gedit is the default text editor of the GNOME desktop environment. It’s a great, text editor that can be used on about any Linux system.

The Gedit homepage is located at https://wiki.gnome.org/Apps/Gedit. On Debian and Ubuntu systems, Gedit can be installed by running the following command:

Terminal-based text editors

If you are working from the Linux command line interface and you need a text editor, you have many options. Here are some of the most popular:

pico started out as the editor built into the text-based e-mail program pine, and it was eventually packaged as a stand-alone program for editing text files. («pico» is a scientific prefix for very small things.)

The modern version of pine is called alpine, but pico is still called pico. You can find more information about how to use it in our pico command documentation.

On Debian and Ubuntu Linux systems, you can install pico using the command:

nano is the GNU version of pico and is essentially the same program under a different name.

On Debian and Ubuntu Linux systems, nano can be installed with the command:

vim, which stands for «vi improved,» is a text editor used by millions of computing professionals all over the world. Its controls are a little confusing at first, but once you get the hang of them, vim makes executing complex editing tasks fast and easy. For more information, see our in-depth vim guide.

Читайте также:  Кто занимает порт линукс

On Debian and Ubuntu Linux systems, vim can be installed using the command:

emacs

emacs is a complex, highly customizable text editor with a built-in interpreter for the Lisp programming language. It is used religiously by some computer programmers, especially those who write computer programs in Lisp dialects such as Scheme. For more information, see our emacs information page.

On Debian and Ubuntu Linux systems, emacs can be installed using the command:

Redirecting command output into a text file

When at the Linux command line, you sometimes want to create or make changes to a text file without actually running a text editor. Here are some commands you might find useful.

Creating an empty file with the touch command

To create an empty file, it’s common to use the command touch. The touch command updates the atime and mtime attributes of a file as if the contents of the file had been changed — without actually changing anything. If you touch a file that doesn’t exist, the system creates the file without putting any data inside.

For instance, the command:

The above command creates a new, empty file called myfile.txt if that file does not already exist.

Redirecting text into a file

Sometimes you need to stick the output of a command into a file. To accomplish this quickly and easily, you can use the > symbol to redirect the output to a file.

For instance, the echo command is used to «echo» text as output. By default, this goes to the standard output — the screen. So the command:

The above command prints that text on your screen and return you to the command prompt. However, you can use > to redirect this output to a file. For instance:

The above command puts the text «Example text» into the file myfile.txt. If myfile.txt does not exist, it is created. If it already exists, its contents will be overwritten, destroying the previous contents and replacing them.

Be careful when redirecting output to a file using >. It will overwrite the previous contents of the file if it already exists. There is no undo for this operation, so make sure you want to completely replace the file’s contents before you run the command.

Here’s an example using another command:

The above command executes ls with the -l option, which gives a detailed list of files in the current directory. The > operator redirects the output to the file directory.txt, instead of printing it to the screen. If directory.txt does not exist, it is created first. If it already exists, its contents will be replaced.

Redirecting to the end of a file

The redirect operator >> is similar to >, but instead of overwriting the file contents, it appends the new data to the end of the file. For instance, the command:

Источник

Best Text Editors for Linux Command Line

Last updated July 20, 2020 By Munif Tanjim 21 Comments

A text editor is a must-have application for any operating system. We have no dearth of the best modern editors for Linux. But those are GUI based editors.

But, for a lot of good reasons, you still need to utilize the command-line. Not just for System Administrators but for the average user as well. Hence, text editors tailored for the terminal is definitely something important.

Here, I’ll compile a list of the best command line text editors for Linux.

Classic Command Line Text Editors

These are some of the most commonly-used and powerful command-line text editors for Linux.

1. Vim

If you’re on Linux for quite some time, you must have heard about Vim. Vim is an extensively configurable, cross-platform, and a highly efficient text editor.

It may not be suitable for newbies but it’s something every aspiring Linux System administrator should get comfortable with. You will probably find it pre-installed in your Linux distribution. It is extremely popular for its wide range of advanced features.

Vim can be quite agonizing for first-time users. I remember the first time I tried to edit a text file with Vim, I was completely puzzled. I couldn’t type a single letter on it and the funny part is, I couldn’t even figure out how to close this thing. If you are going to use Vim, you have to be determined for climbing up a very steep learning curve.

Читайте также:  Борланд паскаль для windows

But after you have gone through all that, combed through its official documentation, and practice the commands/operations, you’ll find it worth all the time spent. Not to forget, you can use it for basic text editing or leverage its support for hundreds of programming languages, extensions and file formats.

How to install it?

If you don’t have it installed already, you can just try typing in the command (on Debian-based systems) to install it:

You can also find it listed in your software center of the Linux distribution you use. In either case, just head on to its official download page to get more details.

2. GNU Emacs

GNU Emacs is undoubtedly one of the oldest and versatile text editor out there. In case you didn’t know, it was created by GNU Project founder Richard Stallman.

Emacs is cross-platform and has both command-line and a graphical user interface. It is also very rich with various features and, most importantly, extensible.

Just as Vim, Emacs too comes with a steep learning curve. But once you master it, you can completely leverage its power. Emacs can handle just about any types of text files. The interface is customizable to suit your workflow. It supports macro recording and shortcuts as well.

The unique power of Emacs is that it can be transformed into something completely different from a text editor. There is a large collection of modules that can transform the application for using in completely different scenarios, like — calendar, news reader, word processor etc. You can even play games in Emacs!

How to install it?

You should find it in your software center or if you prefer using the terminal on Ubuntu-based distros, you can type in:

You can find more information on it in their official download page. Once you’re done installing, you need to type in a specific command to launch emacs in your terminal, which is:

Basically, this command instructs to not include any window to launch the program but the terminal itself.

3. Nano

When it comes to simplicity, Nano is the one. Unlike Vim or Emacs, it is suitable for beginners to get used to quickly.

If you want to simply create & edit a text file, look no further.

The shortcuts available on Nano are displayed at the bottom of the user interface. It is minimal and perfectly suitable for editing system & configuration files. For those who don’t need advanced features from a command-line text editor, Nano is the perfect pick.

If interested, you can learn how to use Nano text editor in our beginner’s guide.

How to install it?

For the most part, Nano editor should come in pre-installed on Ubuntu-based distributions. If it isn’t there, you can simply visit the official download page to get the binaries for the distribution you want.

Modern Text Editors For Command Line

Here, I shall list some terminal-based text editors that bring something new to the table or focus on making things easier.

4. ne – The Nice Editor

When compared to the classic and popular text editors, ne (the nice editor) is a good alternative which tries to offer advanced functionalities and making it easier to use them.

In other words, it’s a simpler alternative to Vim/Emacs offering you powerful features. It is being actively maintained — but not as regular as you’d expect. However, I tried it installing on Pop OS 20.04 and it worked just fine. You can explore more about it in their GitHub page.

Of course, unless you test it extensively, you should take it with a pinch of salt.

Читайте также:  Как правильно настроить malwarebytes windows firewall control

How to install it?

You should find it available in the official repositories of your Linux distribution. For Ubuntu-based distros, you can install it using the command:

You can also check out their official download page for more information on other Linux distributions.

5. Neovim

Neovim is a fork of Vim that aims to add more extensibility while simplifying it. If you’re comfortable with Vim, you will be good to go using Neovim.

The project is being actively maintained and the progress is promising so far. Of course, unless you’re acquainted with how Vim works, you may not notice the striking difference between the two.

But, overall, Neovim tries to take Vim up a notch.

How to install it?

For Ubuntu-based distros, you can simply install it by typing:

For other Linux distributions or platforms, you may refer to its official installation instructions to get started.

To give you a head start, I must mention that when using the terminal, you will have to type the following to launch it (instead of neovim):

6. Tilde

Tilde is a terminal-based text editor tailored for users who are normally used to GUI applications.

Unlike other options mentioned in this list — this may not be a power tool. But, for basic text editing operations, this is very easy to use. You do have some advanced functionality – but that’s not something to compare with Vim/Emacs.

If you wanted to try something easy-to-use and different, this is the one I’d recommend you to try.

How to install it?

For Ubuntu-based distros, you can simply type the following command in the terminal:

For information on other Linux distributions, you may refer to their GitHub page or the download page to explore more about it.

Wrapping Up

If you are an experienced Linux user, you must be aware of the popular options mentioned in this list.

Even though there are some good-old options like WordGrinder and JOE — I’m afraid that they are no longer actively maintained.

What do you think of the best command line text editors for Linux listed in this article? Did I miss any of your favorites? Let me know your thoughts in the comments below!

Like what you read? Please share it with others.

Источник

How to edit a text file in my terminal

I’m using Linux mint and using the vi command to create text files, now that I created a text file and saved it. How do I get back into to edit the text file again?

6 Answers 6

Try this command:

it, will open up a text editor to edit your file.

OR

Here, you can edit your file in the terminal window.

Open the file again using vi. and then press the insert button to begin editing it.

Open the file again using vi. and then press » i » or press insert key ,

For save and quit

and write the following command

without save and quit

If you are still inside the vi editor, you might be in a different mode from the one you want. Hit ESC a couple of times (until it rings or flashes) and then «i» to enter INSERT mode or «a» to enter APPEND mode (they are the same, just start before or after current character).

If you are back at the command prompt, make sure you can locate the file, then navigate to that directory and perform the mentioned «vi helloWorld.txt». Once you are in the editor, you’ll need to check the vi reference to know how to perform the editions you want (you may want to google «vi reference» or «vi cheat sheet»).

Once the edition is done, hit ESC again, then type :wq to save your work or :q! to quit without saving.

For quick reference, here you have a text-based cheat sheet.

Источник

Оцените статью