How to open text, video, or image files via terminal?
Andrew Henderson
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
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 $fileAnd it will open $file in an appropriate application for that file. The argument can also be a URL, so
xdg-open will open this site in your browser, and:
xdg-open mailto:should open your default mail program's composer, with 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.mpgFor example. For still images, you can install the fbi package, and use it to display images on a framebuffer.
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 vlcThen go into the directory which contains videos you want to play,
cd /path/to/the/directory/which/contains/videosPlay 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 shotwellThen go into the directory which contain picture you want to open,
cd /path/to/the/directory/which/contains/pictureOpen the picture via terminal using shotwell,
shotwell "picturefilename.fileformat"
To open a text file, you can use:
nano /path/to/filewhere /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 0 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.jpgor (using the absolute path of the file):
shotwell /home/username/Downloads/image.jpg Use cat to read the contents of text files:
cat $filecat usage (Unix-like operating system command)
Stands for: Concatenate
Function: Concatenate files and print on the standard output
Syntax: cat [-benstuv] [file ...]
You can use Eye Of Gnome too to open image files:
eog filename.pngIf 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.oggAnd 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 fehand then, for example:
feh icon-us.jpg