2

Suppuse I have some text file and I want to open it with text editor, how to do that from terminal?.

  1. I need it that it would work for Red hat 5.3 enterprise.
  2. Without need to download nothing, I need the built in text editor.

I need something like: [root@localhost]# open /home/Plompy/Desktop/README_PLOMPY

That equivalent to this:

enter image description here

5
  • 1
    Hi @Plompy.. Just type in terminal gedit /home/Plompy/Desktop.README_PLOMPY is this what you are looking for?
    – user88036
    Sep 21, 2018 at 14:22
  • @Goro I am trying to edit Plompy.h file, I tried gedit now but it tells: No protocol specified and Unable to init server: Could not connect: Connection refused and (gedit:12764): Gtk-WARNING **: 20:24:45.829: cannot open display: :0, While I succeed to open it manually from text editor
    – Plompy
    Sep 21, 2018 at 14:29
  • Are you open it on a server? try sudo gedit /home/Plompy/Desktop.README_PLOMPY or sudo nano /home/Plompy/Desktop.README_PLOMPY
    – user88036
    Sep 21, 2018 at 14:31
  • @Goro I installed ftp server, but I'm running Fedora right now
    – Plompy
    Sep 21, 2018 at 14:31
  • 1
    gedit is the official text editor of the GNOME desktop environment. Generally, in a server, there is no desktop environment installed or needed. Therefore, gedit can't start and display. I would suggest sudo nano /home/Plompy/Desktop.README_PLOMPY instead
    – user88036
    Sep 21, 2018 at 14:32

3 Answers 3

9

In Ubuntu exist a command called xdg-open, that opens a file or URL in the user's preferred application, so you can open several types of files with the default program pre-defined.

xdg-open hello_word.tiff Open the file using the default image visualizer.

xdg-open Template.odt Open the file using with LibreOffice.

xdg-open myfile.txt Open the file using gedit (Text editor).

By my knowledge the xdg-utils are already installed in Red hat.

1

For the users who got here by Google search looking for a different answer, who want want to stay in the terminal: check to see if there's a defined editor, then try something else, like nano file, or use xdg-open file as a less portable fallback.

if [ -z ${EDITOR} ];  
then  
    xdg-open myfile.txt; #from Luis's answer above  
else  
    $EDITOR file.txt;  
fi
1

xdg-open only works when the file is a text-like file. To e.g. open an otherwise executable binary with a text editor instead, you can determine the default text editor for text files and run that on your file:

gtk-launch $(xdg-mime query default text/plain) your-file

Apparently there's a bug in XFCE though: This can potentially open another editor than the on the user has configured, see https://forum.xfce.org/viewtopic.php?pid=68497#p68497

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .