跳到主要内容

macOs

# 查看可用的分辨率
system_profiler SPDisplaysDataType |grep Resolution
xrandr

# 统计 Chrome 用的内存
ps aux | grep -i chrome | awk '{sum += $4} END {print 4*1024 * (sum/100)}'

# 类似于 lsusb
ioreg -p IOUSB -l -w 0
# lsusb
brew update && brew tap jlhonora/lsusb && brew install lsusb

# 更新软件
softwareupdate -i -w

# 查看 OS X 系统版本信息
sw_vers

# 打开屏保
open -a ScreenSaverEngine

# 锁屏
/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend

# 阅读邮件
mail
# 删除所有邮件
# delete *
# q

# 查看硬件网络端口
networksetup -listallhardwareports

# 查看隐藏文件,需要重启 finder
defaults write com.apple.finder AppleShowAllFiles YES
# 关闭 finder
killall Finder /System/Library/CoreServices/Finder.app
# 关闭
defaults write com.apple.finder AppleShowAllFiles NO

打开取色器

on run {input, parameters}
choose color
return input
end run

文件目录结构

/Library
/Screen Savers # 屏保程序

Brew

Brew 是 OS X 上必不可少的软件包管理器, 具体使用可参考这里

移动磁盘格式选择

如果想要将移动磁盘与 PC 和 Mac 共用,最好选择 ExtFAT,支持大文件(>4G), 都能被识别和读写,在 Mac 上格式化的时候,需要选择使用主引导记录而不是 GUID, 否则 Windows 识别不了.

启动选项

启动键描述
Command-R恢复模式
Command-Option-R网络恢复模式
Alt/Option访问启动管理器
C从 CD, DVD, 或 USB 启动
NNetBoot
Shift安全启动
Command-V详细模式
Command-S单用户模式
Command-Option-P-R重置 NVRAM
T启动目标磁盘模式

常用键盘映射

WindowsmacOS
Windows KeyCommand
AltOption

证书

sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" cert.cer
sudo security remove-trusted-cert -d cert.cer

Finder

  • Finder 的主要问题
    • 不能复制当前地址
    • 不能新建文件
    • 不能剪切
  • xtrafinder
    • XtraFinder add Tabs and features to Mac Finder.
  • FinderPath
    • 地址栏

Install Xcode

xcode-select --install

xcodebuild -runFirstLaunch
clang -v

license

sudo xcodebuild -license

资源下载

终端启用换行

不换行会被截断

tput rmam # 禁用换行
tput smam # 启用换行

csrutil

Modify the System Integrity Protection configuration. All configuration changes apply to the entire machine.
Available commands:

clear
Clear the existing configuration.
disable
Disable the protection on the machine. Only available in Recovery OS.
enable
Enable the protection on the machine. Only available in Recovery OS.
status
Display the current configuration.

netboot
add <address>
Insert a new IPv4 address in the list of allowed NetBoot sources.
list
Print the list of allowed NetBoot sources.
remove <address>
Remove an IPv4 address from the list of allowed NetBoot sources.
/System
/sbin
/bin
/usr *
/Applications **

* /usr is protected with the exception of /usr/local subdirectory, which is often used by tools like Homebrew

** /Applications is protected for apps that are pre-installed with Mac OS (Calendar, Photos, Safari, Terminal, Console, App Store, Notes, etc)

log show --predicate 'eventMessage contains "Previous shutdown cause"' --last 24h

FAQ

Diskutil

# 格式化为 FAT32
diskutil eraseDisk FAT32 NAME MBRFormat /dev/disk2

BasicIPv6ValidationError

# 先禁用掉对应网卡的 IPv6
# networksetup -setv6off Wi-Fi
networksetup -setv6off Ethernet
# 然后通过命令行修改配置
networksetup -setmanual Ethernet 192.168.31.2 255.255.255.0 192.168.1.1
# 设置完成后也可以将 IPv6 设置为自动

NTFS 不能写

OS X 因为版权原因不支持 NTFS 的写操作,需要安装第三方软件才能进行写操作.

  • Tuxera NTFS

使用 USB 以太网

需要安装 HoRNDIS 来支持

在 x86 上安装

更新未能被验证

可参考该文章.

解决办法,前往 苹果组合更新下载页面, 下载需要的版本, 手动进行安装更新.

常见问题诊断

# Ubuntu
apt-get install hfsprogs
fdisk -l
# 检测磁盘是否有问题
fsck.hfsplus /dev/sda2
# 考虑将其挂载上然后把需要的数据拷贝出来
mount -t hfsplus -o force,rw /dev/sdb2 /media/mntpoint

清除 DNS 缓存

# OS X 12 (Sierra) and later
sudo killall -HUP mDNSResponder
sudo killall mDNSResponderHelper
sudo dscacheutil -flushcache
# OS X 11 (El Capitan) and OS X 12 (Sierra)
sudo killall -HUP mDNSResponder

网络

# 查看路由表
# -n 不做 resolve
netstat -nr

桥接

  • 对 wifi 支持不太好
sudo ifconfig bridge0 create
sudo ifconfig bridge0 addm en0 addm en1
sudo ifconfig bridge0 up

ifconfig tap0 192.168.0.20 netmask 255.255.255.0

ifconfig bridge0 addm tap0

man ifconfig

tuntap

brew cask install tuntap
# 避免 root 访问
sudo chown $USER:staff /dev/tap0

ll /dev/tun*
ll /dev/tap*

# 会创建失败
ifconfig tap0 create
# 在 root shell 中执行该命令会创建
# https://sourceforge.net/p/tuntaposx/mailman/message/30457237/
# The idea is that interfaces only get created when a program opens the corresponding /dev/tapX or /dev/tunX device.
# To try, do exec 3<>/dev/tap0 on a root shell.
exec 3<>/dev/tap0

ifconfig tap0 10.10.10.1 10.10.10.255
ifconfig tap0 up
ping -c1 10.10.10.1

ifconfig tap0 0.0.0.0
sudo ifconfig bridge0 addm tap0

转发

INTERFACE=en0

# ifup
sysctl -w net.inet.ip.forwarding=1
sysctl -w net.link.ether.inet.proxyall=1
sysctl -w net.inet.ip.fw.enable=1
ifconfig bridge0 create
ifconfig bridge0 addm $INTERFACE addm tap0
ifconfig bridge0 up
natd -interface $INTERFACE
ipfw add divert natd ip from any to any via $INTERFACE

# ifdown
sysctl -w net.inet.ip.forwarding=0
sysctl -w net.link.ether.inet.proxyall=0
sysctl -w net.inet.ip.fw.enable=1

路由

# -r show routes, -n not resolve
netstat -nr
route delete -host 10.3.2.1
route add -net 10.3 tun0
route add -host 9.8.7.6 tun0

防火墙

cat /etc/pf.conf
# 启用, 可能默认未启用
pfctl -ef /etc/pf.conf
# 语法检测
pfctl -v -n -f /etc/pf.conf
# 应用和重载
pfctl -f /etc/pf.conf

DocumentRevisions-V100

常见网络名称

  • lo0 = loopback
  • gif0 = Software Network Interface
  • stf0 = 6to4 tunnel interface
  • en0 = Ethernet 0
  • fw0 = Firewire
  • en1 = Ethernet 1
  • vmnet1 = Virtual Interface

Develope

security find-identity -v -p codesigning

命令行开启屏幕共享

# 开启所有服务,允许所有用户
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -off -restart -agent -privs -all -allowAccessFor -allUsers

# 只开启屏幕共享
sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist

syslog

历史

  • 乔布斯离开苹果创建 NeXT
  • NeXT 专注于个人工作站 - NeXT Computer, NeXTstation, NeXTcube
  • NeXT 研发的操作系统 NeXTStep - 基于 BSD, Mach 微内核
    • 添加 OO 系统库,Frameworks, Toolkits - kits
    • 基于 OO 的桌面
    • ObjectC
    • Xcode Interface Builder
    • App Store
  • NeXT 分离高层框架为 OpenStep for Mach - 面向 Windows NT, Sun Solaris
  • Apple 多次尝试完善 MacOS 以失败告终
  • Apple 并购 NeXT - 乔布斯回到 Apple
  • MacOS 基于 OpenStep 完善
    • 基于 xnu 内核
    • 构建 Cocoa API
  • 未完成 Rhapsody ,完成部分发布为 MacOS X Server 1.0
  • Rhapsody -> MacOS X, OS X, macOS
  • 参考