「轉」 Ubuntu下用命令行快速打開各類型文件

摘要:
    在Ubuntu下,當需要打開其他格式文件時,咱們通常做法是進入到文件所在的目錄,雙擊打開,很影響效率。事實上,可以通過命令xdg-open打開這些格式文件,甚至是網頁,像打開文件一樣簡單。  

    在Ubuntu下,通常用命令行打開文本文件,比如用命令gedit、more、cat、vim、less。但當需要打開其他格式文件時,比如pdf、jpg、mp3格式文件,咱們通常做法是進入到文件所在的目錄,雙擊打開,很影響效率。事實上,可以通過命令xdg-open(opens a file or URL in the user's preferred application)打開這些格式文件,甚至是網頁,像打開文件一樣簡單。

先舉兩個例子:
  1. jelline@jelline:~$ xdg-open la_isla_bonita.mp3

  2. jelline@jelline:~$ xdg-open http://baidu.com
  3. jelline@jelline:~$ 已在現有的瀏覽器會話中創建新的窗口。
      xdg-open會選擇合適的程序打開指定文件,跟雙擊打開效果一樣。在我電腦,第一個例子會用Totem Movie Player打開,第二個例子會用谷歌瀏覽器打開,而不是Firefox,這是因爲谷歌瀏覽器是我默認的瀏覽器。

具體操作如下:
xdg-open { file | URL }
xdg-open { --help | --manual | --version }

OK,現在是不是方便多了,通過快捷鍵Ctrl+Alt+T可以打開shell,F11可以全屏顯示(Alt+F9最小化窗口,Alt+F10最大化/恢復窗口),再輔予xdg-open命令,極大減少了鼠標操作,也大大提升了效率。

附xdg-open manual部分信息:
    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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章