macOS 开发命令
创建于:2025-07-26 15:06:11
|
更新于:2025-11-12 15:59:45

本文收集mac常用文章。

网络相关命令

功能命令
查看本机IPifconfig | grep "inet " | grep -v 127.0.0.1
关闭网络服务networksetup -setairportpower en0 off
重置DNSsudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder
重启网络服务sudo ifconfig en0 down && sudo ifconfig en0 up
查询网络端口对应的设备名称networksetup -listallhardwareports
网路连通性测试(telnet平替)nc -vz github.com 22

open-connect 无法连接、卡住大概率:dns 缓存问题,清空所有的 dns 或者 将 dns 设置为 8.8.8.8 即可。

Shell相关命令

功能命令
查看当前shellecho $SHELL
查看当前shell的版本echo $SHELL_VERSION
查看当前shell的类型echo $SHELL_TYPE
同步时间sudo sntp -sS pool.ntp.org

brew相关命令

功能命令
更新brewbrew update
更新brew包brew upgrade
清理brew缓存brew cleanup
查看依赖关系brew deps --installed
清理brew包缓存brew cleanup --prune=all
清理无用依赖brew autoremove

Git相关命令

功能命令
忽略证书错误yarn config set "strict-ssl" false -g

Github connnect error

git pull 时报错:

git pull
Connection closed by 127.0.0.1 port 6153
fatal: Could not read from remote repository.
 
Please make sure you have the correct access rights
and the repository exists.
 
# or
 
ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.
 
Please make sure you have the correct access rights
and the repository exists.

这里本质上是当前网络环境无法访问 github 22 端口,可能是 22 端口被防火墙、网络运营商屏蔽了。

我们需要做的是,不在走 22 端口,而是走 443 端口。

是否被墙可以通过 telnet、nc 来判断: telnet github.com 22nc -vz github.com 22

# ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port 443

系统设置

减少 dock-hover 延迟

write http://com.apple.dock autohide-time-modifier -float 0.2
defaults write http://com.apple.dock autohide-delay -float 0
killall Dock

tar 相关命令

功能命令
压缩文件tar -czvf filename.tar.gz directory/
解压文件tar -xzvf filename.tar.gz
查看压缩文件内容tar -tzvf filename.tar.gz

涉及到大量文件压缩会很慢,可以考虑不压缩直接打包。

例如 node_modules,直接打包:

tar -cvf node_modules.tar node_modules

我也是有底线的 🫠