如何从终端打开特定文件?

Suh*_*pta 32 linux fedora terminal

如何从终端打开文件?当我尝试打开一个简单的.txt文件时:

open _b2rR6eU9jJ.txt
Run Code Online (Sandbox Code Playgroud)

我收到这条消息:

Couldn't get a file descriptor referring to the console
Run Code Online (Sandbox Code Playgroud)

我是否使用了错误的命令?或者你使用不同的命令来打开不同的文件类型?

jok*_*ino 57

您可以使用 xdg-open在终端中打开文件。

从手册页xdg-open

xdg-open - 在用户的首选应用程序中打开文件或 URL

用法

该命令xdg-open _b2rR6eU9jJ.txt将在设置为处理文本文件的文本编辑器中打开文本文件。该命令也适用于其他常见文件扩展名,使用相关应用程序打开文件。

也可以看看:


Nli*_*tis 5

您必须使用编辑器打开文本文件:

其中任何一个都可以做到:

 - 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)
Run Code Online (Sandbox Code Playgroud)

或者,如果您只想查看文件而不修改其内容: cat _b2rR6eU9jJ.txt

编辑#1:我刚刚注意到这个问题被标记为fedora,到目前为止它使用 gnome 作为其核心图形用户界面,它预装了gedit。所以这保证有效:gedit _b2rR6eU9jJ.txt