Open a file with the default program on the terminal

Source: Internet
Author: User
Working in a Linux environment, most of the time I am dealing with terminals, I often encounter a need to view a file, such as an image or a Word document (which cannot be viewed directly on the terminal ). In this case, the common practice is to switch to the gui, go to the directory where the file is located, and double-click the File to work in the Linux environment. most of the time it is dealing with the terminal, you will often encounter a file to be viewed, for example, an image or a Word document (which cannot be directly viewed on a terminal ). In this case, you can switch to the gui, go to the directory where the file is located, and double-click the file you want to open. Another method is to directly input the specified program in the shell to open the file, for example, evince xx.pdf to view a PDF file. Of course, the premise is that you have to remember the names of those programs. for example, do you remember to use LibreOffice to open a word file? I cannot remember it.

Many default file opening methods have been defined in the graphic interface. for example, if you double-click a webpage file, it will be automatically opened in the default browser. if you double-click an image, it will be opened in the default image browser, so there should be a corresponding mechanism under the terminal. After following this idea, I went to google and found the xdg-open command (compatible with gnome and kde ), this command will use the default file opening method set in the graphic interface (the same as double-clicking to open the file ).

Using this command, it is much easier to open a file in the terminal. for example, you can use the default pdf reader to open a pdf file:

Xdg-open xxxlarge

You can also use the file manager in the image to open the directory, for example, to open the user's home directory:

Xdg-open ~

A very useful tool!

The procedure is as follows:
Xdg-open {file | URL}
Xdg-open {-- help | -- manual | -- version}


OK. Now it's much more convenient. you can press Ctrl + Alt + T to open the shell, and F11 can be displayed in full screen (Alt + F9 to minimize the window, Alt + F10 to maximize/restore the window ), the xdg-open command greatly reduces mouse operations and improves efficiency.


Part of xdg-open manual information is provided:
Xdg-open opens a file or URL in the user's preferred application. if a URL is provided the URL will be opened in the user's preferred web browser. if a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.
Xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.