使用默认程序来打开文件、文件夹、链接等,也可以指定程序打开。
open '/Volumes/Macintosh HD/foo.txt' # 打开文件
open '/Volumes/Macintosh HD/Applications/' # 打开文件夹
open https://www.baidu.com # 打开链接
常用参数
-
-a application
指定应用程序打开文件
open -a /Applications/TextEdit.app '/Volumes/Macintosh HD/foo.txt'
-
-b bundle_indentifier
指定bundle identifier来打开文件
open -b com.apple.TextEdit '/Volumes/Macintosh HD/foo.txt'
-
-e
使用/Applications/TextEdit
来打开文件
open -e '/Volumes/Macintosh HD/foo.txt'
-
-t
使用默认的文本编辑器打开文件 -
-f
从标准输出里读取内容并用默认文本编辑器打开,如ls | open -f
-
-R
在Finder中打开文件的位置 -
-n
如果应用程序已经在运行,可以使用这个参数来打开新的实例,在Mac上可以使用这个参数来登录多个QQ -
-g
在后台打开 -
-j
打开文件但隐藏在Dock栏
实践
不喜欢使用vim
的同学可以在命令行下设置这样一条alias
alias vscode='open -a /Applications/Visual\ Studio\ Code.app'
在命令行下想要打开文件的时候可以使用vscode <file>
来打开
网友评论