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 $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.
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"
- 80,446
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
- 16,703
- 131
- 4
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
- 16,703
- 78,878
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
- 16,703
- 361
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!
- 16,703
- 1
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
- 16,703
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 ...]
- 16,703