1
0
mirror of https://github.com/jlevy/the-art-of-command-line.git synced 2024-12-12 10:45:00 +02:00

Add Mac-specific tricks for Terminal

This commit is contained in:
John Chang 2019-05-24 09:34:51 +01:00 committed by GitHub
parent 3d8afef22e
commit 7575f23c68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -550,15 +550,19 @@ These are items relevant *only* on macOS.
- Package management with `brew` (Homebrew) and/or `port` (MacPorts). These can be used to install on macOS many of the above commands.
- Drag an item from Finder to Terminal to paste its path.
- Copy output of any command to a desktop app with `pbcopy` and paste input from one with `pbpaste`.
- To enable the Option key in macOS Terminal as an alt key (such as used in the commands above like **alt-b**, **alt-f**, etc.), open Preferences -> Profiles -> Keyboard and select "Use Option as Meta key".
- In Terminal, Option-click to move the cursor e.g. when editing text. To enable the Option key as an alt key instead (such as used in the commands above like **alt-b**, **alt-f**, etc.), open Preferences -> Profiles -> Keyboard and select "Use Option as Meta key".
- To open a file with a desktop app, use `open` or `open -a /Applications/Whatever.app`.
- `xed` opens a file for editing in Xcode.
- Spotlight: Search files with `mdfind` and list metadata (such as photo EXIF info) with `mdls`.
- Be aware macOS is based on BSD Unix, and many commands (for example `ps`, `ls`, `tail`, `awk`, `sed`) have many subtle variations from Linux, which is largely influenced by System V-style Unix and GNU tools. You can often tell the difference by noting a man page has the heading "BSD General Commands Manual." In some cases GNU versions can be installed, too (such as `gawk` and `gsed` for GNU awk and sed). If writing cross-platform Bash scripts, avoid such commands (for example, consider Python or `perl`) or test carefully.
- Be aware macOS is based on BSD Unix, and many commands (for example `ps`, `ls`, `tail`, `awk`, `sed`) have many subtle variations from Linux, which is largely influenced by System V-style Unix and GNU tools. You can often tell the difference by noting a man page has the heading "BSD General Commands Manual." In some cases GNU versions can be installed, too (such as `gawk` and `gsed` for GNU awk and sed). If writing cross-platform Bash scripts, avoid such commands (for example, consider Python or Perl) or test carefully.
- To get macOS release information, use `sw_vers`.