I am new to Ubuntu and I would like to know how to open a simple text file or a video file or an image file via the terminal.

8 Answers 8


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.

  • 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, 2013 at 0:58
  • Related: How do I set a new xdg-open setting?
    – Kulfy
    Mar 20, 2020 at 18:38

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"

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 your file 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

To open any file via terminal, you have to locate the path of that file. Then type the name of the application which you want to open the file with.

For example, to open an image file in the current directory using Shotwell, you would run:

shotwell image.jpg

or (using the absolute path of the file):

shotwell /home/username/Downloads/image.jpg

Use cat to read the contents of text files:

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 ...]

  • 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, 2020 at 18:36

You can use Eye Of Gnome too to open image files:

eog filename.png

If not installed already, you can install it using:

sudo apt-get install eog

I just downloaded a song (Mario theme song (fast)) and ran the following to play it:

play main_theme_sped_up.ogg

And it worked!


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

sudo apt install feh

and then, for example:

feh icon-us.jpg

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.