linux随记:shell命令,利用xdg-open打开默认文件

先看下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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值