前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Mac终端Shell命令Open

Mac终端Shell命令Open

作者头像
hotarugali
发布2023-05-16 20:13:58
1.2K0
发布2023-05-16 20:13:58
举报

1. 简介

Mac 下手动打开目录、文件和应用程序等和 Windows 都很一不样,用惯 Windows 的用户刚开始使用 Mac 系统可能会非常不习惯。好在 Mac 下有一个非常方便的命令行工具 open,它能很方便地打开 Mac 上的目录、文件和应用程序。

2. 格式

代码语言:javascript
复制
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [-u URL] [filenames] [--args arguments]
Help: Open opens files from a shell.
      By default, opens each file using the default application for that file.  
      If the file is in the form of a URL, the file will be opened as a URL.
Options: 
      -a                    Opens with the specified application.
      -b                    Opens with the specified application bundle identifier.
      -e                    Opens with TextEdit.
      -t                    Opens with default text editor.
      -f                    Reads input from standard input and opens with TextEdit.
      -F  --fresh           Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
      -R, --reveal          Selects in the Finder instead of opening.
      -W, --wait-apps       Blocks until the used applications are closed (even if they were already running).
          --args            All remaining arguments are passed in argv to the application's main() function instead of opened.
      -n, --new             Open a new instance of the application even if one is already running.
      -j, --hide            Launches the app hidden.
      -g, --background      Does not bring the application to the foreground.
      -h, --header          Searches header file locations for headers matching the given filenames, and opens them.
      -s                    For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched.
                            Otherwise the highest versioned SDK in each platform is used.
      -u, --url URL         Open this URL, even if it matches exactly a filepath
      -i, --stdin  PATH     Launches the application with stdin connected to PATH; defaults to /dev/null
      -o, --stdout PATH     Launches the application with /dev/stdout connected to PATH; 
          --stderr PATH     Launches the application with /dev/stderr connected to PATH to
          --env    VAR      Add an enviroment variable to the launched process, where VAR is formatted AAA=foo or just AAA for a null string value.

2.1 打开目录

代码语言:javascript
复制
open <path1> [<path2> ...]

其中,<path1> 为需要打开的目录,可以同时打开多个目录项,打开的目录最终是在 Finder 窗口显示。

2.2 打开文件

代码语言:javascript
复制
open <file1> [<file2> ...]

其中,<file1> 为需要打开的文件,可以同时打开多个文件项,以对应文件格式的默认应用打开对应文件。

2.3 定位文件

如果想定位文件所在位置并在 Finder 中打开对应目录,则可以使用以下命令行:

代码语言:javascript
复制
open -R <file1> [<file2> ...]

其中,<file1> 为需要定位的文件,可以同时定位多个文件项。

2.4 打开应用程序

代码语言:javascript
复制
open -a <app1> [<app2> ...]

其中,<app1> 为需要打开的应用程序,可以同时打开多个应用程序项。

2.5 打开 URLs

代码语言:javascript
复制
open <url1> [<url2> ...]
open -a Firefox <url1> [<url2> ...]

其中,<url1> 为需要打开的 URL,以默认浏览器打开;可以通过 -a 参数更换其它浏览器打开。

2.6 头文件

open 另一大用途是,定位并打开对应的头文件:

代码语言:javascript
复制
open -h <header1> [<header2> ...]
open -a TextEdit -h <header1> [<header2> ...]

其中,<header1> 为需要打开的头文件,以默认程序打开;可以通过 -a 参数更换其它应用程序打开。

附录

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-03-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 简介
  • 2. 格式
    • 2.1 打开目录
      • 2.2 打开文件
        • 2.3 定位文件
          • 2.4 打开应用程序
            • 2.5 打开 URLs
              • 2.6 头文件
              • 附录
              相关产品与服务
              命令行工具
              腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
              http://www.vxiaotou.com