open

作者: e06ef3adf70b | 来源:发表于2018-07-29 14:35 被阅读10次

使用默认程序来打开文件、文件夹、链接等,也可以指定程序打开。

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>来打开

相关文章

网友评论

      本文标题:open

      本文链接:https://www.haomeiwen.com/subject/jcwzmftx.html