The Wayback Machine - https://web.archive.org/web/20250116090713/https://www.geeksforgeeks.org/xdg-open-command-in-linux-with-examples/
Open In App

xdg-open command in Linux with Examples

Last Updated : 27 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

xdg-open command in the Linux system is used to open a file or URL in the user’s preferred application. The URL will be opened in the user’s preferred web browser if a URL is provided. The file will be opened in the preferred application for files of that type if a file is provided. xdg-open supports ftp, file, https, and http URLs.

This can be used inside a desktop session only. It is not recommended to use xdg-open as root. Here, zero is an indication of success while non-zero shows failure.

Syntax

xdg-open {file | URL}

where,

  • file: Specifies the file that you want to open.
  • URL: Specifies the URL that you want to open.

Basic Example

xdg-open read.html

Basic ExampleBasic Example

Key Options used with the xdg-open

1. xdg-open –version:

This option will show the xdg-utils version information.

xdg-open --version

xdg-open --version

2. xdg-open –help:

Provides a summary of the command’s options and usage.

xdg-open --help

xdg-open --help

3. xdg-open –manual:

Opens the manual page for the xdg-open command, offering detailed documentation about the tool.

xdg-open --manual

xdg-open --manual

Conclusion

The xdg-open command is a simple yet powerful tool for opening files and URLs in the user’s default applications. It seamlessly integrates with the desktop environment, making it easy to launch files or web resources from the command line. With support for multiple file types and URL schemes, it is an essential utility for both casual users and system administrators alike.

xdg-open command in Linux – FAQs

What is the xdg-open command used for?

The xdg-open command is used to open files and URLs in the user’s preferred applications. It automatically launches the appropriate application based on the file type or URL protocol.

Can I open a website using xdg-open?

Yes, you can open a website by specifying a URL with the xdg-open command. For example:

xdg-open https://www.example.com

How do I open a local file with xdg-open?

To open a local file, specify the file path as an argument to xdg-open. For example:

xdg-open /path/to/your/file.txt

What URL schemes does xdg-open support?

xdg-open supports various URL schemes including http, https, ftp, and file.

Master DevOps and also get 90% Course fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.

The most sought-after Three 90 challenge has started and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!


Next Article

Similar Reads

three90RightbarBannerImg