先看下xdg-open的说明:
NAME
xdg-open - opens a file or URL in the user’s preferred application
SYNOPSIS
xdg-open {file URL}
xdg-open {--help --manual --version}
DESCRIPTION
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.
OPTIONS
--help Show command synopsis.
--manual
Show this manualpage.
--version
Show the xdg-utils version information.
EXIT CODES
An exit code of 0 indicates success while a non-zero exit code indicates failure. The following failure codes can be
returned:
1 Error in command line syntax.
2 One of the files passed on the command line did not exist.
3 A required tool could not be found.
4 The action failed.
EXAMPLES
xdg-open ’http://www.freedesktop.org/’
Opens the Freedesktop.org website in the user’s default browser
xdg-open /tmp/foobar.png
也就是说利用xdg-open 我们就可以在终端直接打开各种文件,目录 图片或者文档等
比如:
打开根目录
xdg-open /
打开图片
xdg-open /tmp/foobar.png
打开文档
xdg-open xxx.doc
xdg-open xxx.pdf
打开html
sudo xdg-open xxx.html
当然,如果也可以直接指定打开的应用程序,这样就要记住已安装的各种应用名称
wps xxx.doc
FoxitReader xxx.pdf
sudo firfox xxx.html
我们也可以在项目中使用来达到比较友好的交互,比如打开opt目录
#include<unistd.h>
int main()
{
system("xdg-open /opt");
return 0;
}