本文收集mac常用文章。
网络相关命令
| 功能 | 命令 |
|---|---|
| 查看本机IP | ifconfig | grep "inet " | grep -v 127.0.0.1 |
| 关闭网络服务 | networksetup -setairportpower en0 off |
| 重置DNS | sudo 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相关命令
| 功能 | 命令 |
|---|---|
| 查看当前shell | echo $SHELL |
| 查看当前shell的版本 | echo $SHELL_VERSION |
| 查看当前shell的类型 | echo $SHELL_TYPE |
| 同步时间 | sudo sntp -sS pool.ntp.org |
brew相关命令
| 功能 | 命令 |
|---|---|
| 更新brew | brew 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 22或nc -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 Docktar 相关命令
| 功能 | 命令 |
|---|---|
| 压缩文件 | 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