37

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

open _b2rR6eU9jJ.txt

I get this message:

Couldn't get a file descriptor referring to the console

Have I used the wrong command? Or do you use different commands to open different file types?

3
  • 1
    What do you mean by opening it? Do you want to edit it? You can use nano, emacs or vi for that.
    – wnrph
    Sep 21, 2012 at 7:39
  • Sounds like you're coming from a Mac, where open does the same as double-clicking would in the Desktop. Feb 1, 2019 at 17:02
  • That question can't be serious. May 19, 2019 at 3:22

3 Answers 3

61

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:

2
  • 1
    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. Feb 13, 2020 at 14:50
  • or for a windows user - alias start=xdg-open :-)
    – Andy
    Apr 8, 2022 at 10:00
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

3

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.

You must log in to answer this question.

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