How to open a particular file from a terminal?

31

10

How do I open a file from a terminal ? When I try to open a simple txt file like :

 open _b2rR6eU9jJ.txt

I get this message :

Couldn't get a file descriptor referring to the console

Is that command a wrong one ? Is it that to open files of different type we have modified commands ?

Suhail Gupta

Posted 2012-09-21T07:35:49.920

Reputation: 1 655

Sounds like you're coming from a Mac, where open does the same as double-clicking would in the Desktop. – Roger Dueck – 2019-02-01T17:02:11.080

That question can't be serious. – Johan Boulé – 2019-05-19T03:22:08.110

1What do you mean by opening it? Do you want to edit it? You can use nano, emacs or vi for that. – artistoex – 2012-09-21T07:39:36.440

Answers

51

You can use xdg-open to open files in a terminal.

From the man-page of xdg-open:

xdg-open - opens a file or URL in the user's preferred application

Usage

The command xdg-open _b2rR6eU9jJ.txt will open the text file in a text editor that is set to handle text files. The command will also work with other common file extensions, opening the file with the relevant application.

See also:

jokerdino

Posted 2012-09-21T07:35:49.920

Reputation: 2 330

If you struggle to remember xdg-open like I often do, add alias open=xdg-open to your ~/.bashrc file. Then, run source ~/.bashrc and now you can use open instead of xdg-open. – Waldir Leoncio – 2020-02-13T14:50:09.760

5

You must use an editor to open a text file:

Any of those can do it:

 - vi _b2rR6eU9jJ.txt
 - vim _b2rR6eU9jJ.txt
 - emacs _b2rR6eU9jJ.txt
 - nano _b2rR6eU9jJ.txt
 - gedit _b2rR6eU9jJ.txt (gnome's default editor)
 - leafpad _b2rR6eU9jJ.txt (lxde's default editor)
 - kedit _b2rR6eU9jJ.txt (KDE's default editor)

Or if you wanted to just view the file without modifying its contents: cat _b2rR6eU9jJ.txt

EDIT #1: I just noticed that the question is tagged fedora, which up until now is using gnome as its core graphical user interface, which comes with gedit preinstalled. So this is guaranteed to work: gedit _b2rR6eU9jJ.txt

NlightNFotis

Posted 2012-09-21T07:35:49.920

Reputation: 173

2

You should use an appropriate application to open it - try nano _b2rR6eU9jJ.txt or cat _b2rR6eU9jJ.txt. The former will edit, the latter will output it to standard output. (Note - you can replace nano with vi, emacs or other text editor of your preference)

From what I can tell

geek@ubuntu:~$ open --help
open: invalid option -- '-'
Usage: openvt [-c vtnumber] [-f] [-l] [-u] [-s] [-v] [-w] -- command_line

open refers to openvt - and the man page describes it as openvt - start a program on a new virtual terminal (VT). You're trying to open a text file, so unless I'm missing something, it isn't the software for doing what you want to do.

Journeyman Geek

Posted 2012-09-21T07:35:49.920

Reputation: 119 122