42

I am new to ubuntu and I would like to know how to open a simple text file or open a video or a picture via the terminal

60

If you wish to open files in graphical applications from the command line, such as within gnome-terminal or xterm then simply run:

xdg-open $file

And it will open $file in an appropriate application for that file. The argument can also be a URL, so

xdg-open http://askubuntu.com/

will open this site in your browser, and:

xdg-open mailto:someone@somewhere.com

should open your default mail program's composer, with someone@somewhere.com in the To: field.

If what you want to view videos on a virtual terminal, without Xorg, you can use mplayer with the directfb, fbdev, fbdev2, sdl (with the frame buffer back-end), or svga as the video output, by running

mplayer -vo fbdev2 file.mpg

For example. For still images, you can install the fbi package, and use it to display images on a framebuffer.

2
  • I forgot about xdg-open. xD But they were not specific about whether they have only the terminal, or whether they have the GUI, so I assumed worst-case in that they only have a terminal and no GUI... – Thomas Ward Nov 30 '13 at 0:58
  • Related: How do I set a new xdg-open setting? – Kulfy Mar 20 '20 at 18:38
4

To open a video from terminal

  • First install vlc player by running the below commands on terminal

    sudo add-apt-repository ppa:videolan/stable-daily
    sudo apt-get update
    sudo apt-get install vlc
    
  • Then go into the directory which contains videos you want to play,

    cd /path/to/the/directory/which/contains/videos
    
  • Play the video from terminal using vlc player,

    vlc "videofilename.fileformat"
    

To open a picture from terminal,

  • Install shotwell to open a picture via terminal,

    sudo add-apt-repository ppa:yorba/ppa
    sudo apt-get update
    sudo apt-get install shotwell
    
  • Then go into the directory which contain picture you want to open,

    cd /path/to/the/directory/which/contains/picture
    
  • Open the picture via terminal using shotwell,

    shotwell "picturefilename.fileformat"
    
2

To open a text file, you can use nano /path/to/file where /path/to/file is the location on the computer your file is stored, with the actual name of the file at the end (so, if you downloaded it into your Downloads directory and your username is "example", and the file is named "test.txt", then you can do nano /home/example/Downloads/text.txt).

(This is a half-answer)

0
0

I just downloaded a song (Mario theme song (fast)) and typed :

    $ play main_theme_sped_up.ogg

And it worked!

0

As an addition to @dobey's good answer, if you prefer opening an image by system's image viewer via terminal, use xdg-open as the answer suggests. Another common alternative is feh, which can be installed by typing

$ sudo apt install feh

and then, for example,

$ feh icon-us.jpg .

0

Use cat

cat $file

cat usage (Unix-like operating system command)

Stands for: Concatenate

Function: Concatenate files and print on the standard output

Syntax: cat [-benstuv] [file ...]

1
  • 2
    While cat will display text files in human readable form but it can't open pictures and videos since the data inside that isn't stored in form of a regular text file. – Kulfy Mar 20 '20 at 18:36
0

You can use Eye Of Gnome too:

sudo apt-get install eog If not installed already

eog filename.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.