open:在终端打开文件|应用程序等

时间:2022-09-11 11:32:33

1、 需求&解决方案

  • 打开文件 或url(用默认应用程序): $ open fileName
  • 打开文件 或url(用指定应用程序): $ open -a appName fileName ## appName 中若有空格,则用引号" 括起来
  • 打开Finder,定位到当前位置: $ open 'curDir' ## PS: curDir 一定要用引号括起来 , open . # 表示Finder打开当前文件夹

2、 附录($ man open)

OPEN(1) BSD General Commands Manual OPEN(1)

NAME

open - open files and directories

SYNOPSiS

open [-e] [-t] [-f] [-F] [-W] [-R] [-n] [-g] [-h] [-s _sdk]

[-b bundle_identifier] [-a application] _file. [-args arg1 ...]

DESCRIPTION

The open command opens a file (or a directory or URL), just as if you had

double-clicked the file's icon. If no application name is specified, the

default application as determined via LaunchServices is used to open the

specified files.

 If the file is in the form of a URL, the file will be opened as a URL.

 You can specify one or more file names (or pathnames), which are interpreted relative to the shell or Terminal window's current working direc-
tory. For example, the following command would open all Word files in the
current working directory: open *.doc Opened applications inherit environment variables just as if you had
launched the application directly through its full path. This behavior
was also present in Tiger. The options are as follows: -a application
Specifies the application to use for opening the file -b bundle_identifier
Specifies the bundle identifier for the application to use when open-
ing the file -e Causes the file to be opened with /Applications/TextEdit -t Causes the file to be opened with the default text editor, as deter-
mined via LaunchServices -f Reads input from standard input and opens the results in the default
text editor. End input by sending EOF character (type Control-D).
Also useful for piping output to open and having it open in the
default text editor. -F Opens the application "fresh," that is, without restoring windows.
Saved persistent state is lost, except for Untitled documents. -W Causes open to wait until the applications it opens (or that were
already open) have exited. Use with the -n flag to allow open to
function as an appropriate app for the $EDITOR environment variable. -R Reveals the file(s) in the Finder instead of opening them. -n Open a new instance of the application(s) even if one is already running. -g Do not bring the application to the foreground. -h Searches header locations for a header whose name matches the given
string and then opens it. Pass a full header name (such as NSView.h)
for increased performance. -s For -h, partial or full SDK name to use; if supplied, only SDKs whose
names contain the argument value are searched. Otherwise the highest
versioned SDK in each platform is used. -args
All remaining arguments are passed to the opened application in the
argv parameter to main(). These arguments are not opened or interpreted by the open tool.

EXAMPLES

  "open '/Volumes/Macintosh HD/foo.txt'" opens the document in the default application for its type (as determined by LaunchServices).
"open '/Volumes/Macintosh HD/Applications/'" opens that directory in the Finder.
"open -a /Applications/TextEdit.app '/Volumes/Macintosh HD/foo.txt'"
opens the document in the application specified (in this case, TextEdit). "open -b com.apple.TextEdit '/Volumes/Macintosh HD/foo.txt'" opens the
document in the application specified (in this case, TextEdit). "open -e '/Volumes/Macintosh HD/foo.txt'" opens the document in TextEdit. "ls | open -f" writes the output of the 'ls' command to a file in /tmp
and opens the file in the default text editor (as determined by LaunchServices). "open http://www.apple.com/" opens the URL in the default browser. "open 'file://localhost/Volumes/Macintosh HD/foo.txt'" opens the document
in the default application for its type (as determined by LaunchServices). "open 'file://localhost/Volumes/Macintosh HD/Applications/'" opens that
directory in the Finder. "open -h NSView" lists headers whose names contain NSView and allows you
to choose which ones to open. "open -h NSView -s OSX10.12" lists headers whose names contain NSView in
the MacOSX 10.12 SDK and allows you to choose which ones to open. "open -a Xcode -h NSString.h" quickly opens /System/Library/Frameworks/Foundation.framework/Headers/NSString.h in Xcode.

HISTORY
First appeared in NextStep. Mac OS X February 10, 2004 Mac OS X

open:在终端打开文件|应用程序等的更多相关文章

  1. 简述在Ubuntu终端打开文件的几种不同方法与区别

    一· 在Ubuntu下,通常用命令行打开文本文件,比如用命令gedit.more.cat.vim.less. gedit:在文本软件下打开文件,可直接修改. more ,cat 和 less :类似, ...

  2. 解决Ubuntu系统中文乱码显示问题,终端打开文件及查看目录

    解决Ubuntu系统中文乱码显示问题 [日期:2014-02-20] 来源:Linux社区  作者:njchenyi [字体:大 中 小]   我是先安装了Ubuntu 12.04 Server,然后 ...

  3. sublime text3 支持终端打开文件

    sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

  4. Mac 设置终端中使用 sublime 打开文件

    在Mac下用终端创建文件等比较方便,但如果配合Sublime用,最好是可以直接在终端中输入命令就可以用Sublime打开指定文件或文件夹. #检查用户目录下有没有bin目录,如里没有就创建一个(目的是 ...

  5. [转] - 在mac的终端中使用sublime打开文件

    在mac的终端中使用sublime打开文件 使用sublime提供的命令行工具.这个命令行工具位于 /Applications/Sublime\ Text\ 2.app/Contents/Shared ...

  6. 使用JAVA打开本地应用程序相关的文件

    在该项目中需要运行本地文件或应用程序,JDK6添加后Desktop类别.可以直接使用.这使得有可能在程序中无论什么应用程序可以打开的.例:打开pdf文件,当地福昕是默认打开.执行程序将使用福昕开放pd ...

  7. mac终端调用编辑器打开文件

    1.调用atom编辑器,前提是编辑器打开, cd+filename 2 .VScode里面: 调用终端:ctrl + `(esc健下面那个) 安装:shift + command+ p 安装如下插件 ...

  8. qt: 系统默认程序打开文件或者软件;

    Qt提供了QDesktopServices类, 可以利用openUrl函数调用默认程序打开文件: 源码参考: #ifdef Q_OS_WIN32 m_szHelpDoc = QString(&quot ...

  9. [AIR] 使用操作系统默认应用程序打开文件

    AIR 2.0及以上提供了非常简单易用的API让你使用操作系统所定义的关联应用程序打开文件. 这使得使用AIR开发基于“文件管理器”的应用称为可能 用法如下: var file:File = File ...

随机推荐

  1. Windows核心编程&内核对象

    1. 一个进程在初始化时,系统将会他分配一个空的句柄表,这个句柄表仅供内核对象使用,不供用户对象和GDI对象使用.进程在首次 初始化时,该句柄表为空.句柄表是一个由数据结构组成的数组,包含一个内核对象 ...

  2. qml layout

    一.使用总结 1.锚点:锚点锚在父控件左边anchors.left: parent.left ,才可以设置anchors.leftMargin:20 才有作用,设置anchors.topMargin: ...

  3. Python用户名密码登录系统(MD5加密并存入文件,三次输入错误将被锁定)及对字符串进行凯撒密码加解密操作

    # -*- coding: gb2312 -*- #用户名密码登录系统(MD5加密并存入文件)及对字符串进行凯撒密码加解密操作 #作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.co ...

  4. 优化Ubuntu 16.04系统的几件事

    安装完Ubuntu 16.04后,要更换为国内的软件源: sudo gedit /etc/apt/sources.list #用文本编辑器打开源列表 在文件开头添加下面的阿里云的软件源: deb ht ...

  5. 关于使用Iscroll.js异步加载数据后不能滑动到最底端的问题解决方案

    关于使用Iscroll.js异步加载数据后不能滑动到最底端,拉到最下边又弹回去的问题困扰了我老半天,相信很多朋友都遇到了.我刚好不小心解决了,和大家分享一下.由于各种忙,下边就直接上代码吧. (前提是 ...

  6. 制作macOS10.12系列的系统镜像文件

    制作macOS10.12系列的系统镜像文件步骤,过程也比较简单,十来个命令.以10.12.6为例,首先,在苹果商店下载系统安装包APP,或者网上下载后把安装APP复制到  应用程序  文件夹. 然后打 ...

  7. eos开发实践

    一 下载前端代码 git clone https://github.com/baidang201/eos-todo 二 安装nodejs sudo apt-get install python-sof ...

  8. Apache 配置参数

    参数说明 1.Global Environment 全局环境配置,决定Apache服务器的全局参数3.Virtual Hosts—虚拟主机,虚拟主机不能与Main Server主服务器共存,当启用了虚 ...

  9. 详述 SQL 中的 distinct 和 row_number() over() 的区别及用法

    1 前言 在咱们编写 SQL 语句操作数据库中的数据的时候,有可能会遇到一些不太爽的问题,例如对于同一字段拥有相同名称的记录,我们只需要显示一条,但实际上数据库中可能含有多条拥有相同名称的记录,从而在 ...

  10. Log4J 配置 详解

    Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以创建出Log4J的运行环境 ...