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