You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
372 lines
12 KiB
372 lines
12 KiB
[appendix]
|
|
= Mac OS 使用技巧
|
|
== homebrew
|
|
=== 简介
|
|
Homebrew 是一款 Mac OS 平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。
|
|
Homebrew 通过简单的一条指令,就可以实现包管理,不需要关心各种依赖和文件路径的情况。
|
|
|
|
=== 安装 homebrew
|
|
由于官网的安装方式会比较慢,此处我们将采用清华大学开源软件镜像站进行安装。
|
|
|
|
==== 设置环境变量
|
|
[source,bash]
|
|
----
|
|
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
|
|
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
|
|
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
|
|
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
|
|
----
|
|
|
|
==== 下载并执行安装脚本
|
|
[source,bash]
|
|
----
|
|
# 下载安装脚本
|
|
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
|
|
|
|
# 执行安装脚本
|
|
/bin/bash brew-install/install.sh
|
|
----
|
|
|
|
==== 环境变量持久化
|
|
[source,bash]
|
|
----
|
|
# 通过以下命令将环境变量写入 ~/.zprofile 文件
|
|
echo '# Start Set PATH, MANPATH, etc., for Homebrew.' >> /Users/wangshaoping/.zprofile
|
|
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> /Users/wangshaoping/.zprofile
|
|
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> /Users/wangshaoping/.zprofile
|
|
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> /Users/wangshaoping/.zprofile
|
|
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> /Users/wangshaoping/.zprofile
|
|
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/wangshaoping/.zprofile
|
|
echo '# End Set PATH, MANPATH, etc., for Homebrew.' >> /Users/wangshaoping/.zprofile
|
|
|
|
# 关闭并重新打开终端以便环境变量生效
|
|
----
|
|
|
|
==== 检查安装情况
|
|
[source,bash]
|
|
----
|
|
brew -v
|
|
----
|
|
|
|
=== 卸载 homebrew
|
|
[source,bash]
|
|
----
|
|
# 下载安装和卸载脚本
|
|
<1> git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
|
|
|
|
# 执行卸载脚本
|
|
<2> /bin/bash brew-install/uninstall.sh
|
|
----
|
|
|
|
=== Homebrew 术语
|
|
|
|
* Formulae:软件包,包括了这个软件的依赖、源码位置及编译方法等
|
|
* Casks:已经编译好的应用包,如图形界面程序等
|
|
|
|
=== Homebrw 文件夹用途
|
|
|
|
* bin:用于存放所安装程序的启动链接(相当于快捷方式)
|
|
* etc:brew 安装程序的配置文件默认存放路径
|
|
* Library:Homebrew 系统自身文件夹
|
|
* Cellar:通过 brew 安装的程序将以 [程序名/版本号] 存放于本目录下
|
|
|
|
=== 常用的 brew 命令
|
|
[source,bash]
|
|
----
|
|
# 查看brew版本
|
|
brew -v
|
|
|
|
# 更新brew版本
|
|
brew update
|
|
|
|
# 本地软件库列表
|
|
brew list
|
|
|
|
# 查看软件库版本
|
|
brew list --versions
|
|
|
|
# 查找软件包(xxx为要查找软件的关键词)
|
|
brew search xxx
|
|
|
|
# 安装软件包(xxx为软件包名称)
|
|
brew install xxx
|
|
|
|
# 卸载软件包(xxx为软件包名称)
|
|
brew uninstall xxx
|
|
|
|
# 安装软件(xxx为软件名称)
|
|
brew cask install xxx
|
|
|
|
# 卸载软件(xxx为软件名称)
|
|
brew cask uninstall xxx
|
|
|
|
# 查找软件安装位置(xxx为软件名称)
|
|
which xxx
|
|
----
|
|
|
|
=== brew install & brew cask install
|
|
Homebrew 提供了两种安装软件的方式,brew install 和 brew cask install,下面对两种方式进行一些解释说明。
|
|
|
|
.brew install
|
|
brew 是下载源码解压,然后 ./configure && make install ,同时会包含相关依存库,并自动配置好各种环境变量。
|
|
对于对程序员只需通过简单的指令,就能快速安装和升级本地的各种开发环境,非常快捷方便。
|
|
|
|
.brew cask install
|
|
brew cask 是针对已经编译好了的应用包(.dmg/.pkg)下载解压,然后放在统一的目录中(Caskroom),省掉了自己下载、解压、安装等步骤。
|
|
这个对一般用户来说会比较方便,包含很多在 AppStore 里没有的常用软件。
|
|
|
|
简单来说,
|
|
|
|
* brew install 用来安装一些不带界面的命令行工具和第三方库
|
|
* brew cask install 用来安装一些带界面的应用软件
|
|
|
|
== 启动、停止服务
|
|
[source,bash]
|
|
----
|
|
brew services start xxx # 启动名为 xxx 的服务
|
|
brew services stop xxx # 停止名为 xxx 的服务
|
|
brew services restart xxx # 重启名为 xxx 的服务
|
|
----
|
|
|
|
== 国内镜像配置
|
|
=== 安装
|
|
[source,bash]
|
|
----
|
|
# 设置环境变量
|
|
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
|
|
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
|
|
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
|
|
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
|
|
export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
|
|
|
|
# 从本镜像下载安装脚本并安装 Homebrew / Linuxbrew
|
|
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
|
|
/bin/bash brew-install/install.sh
|
|
rm -rf brew-install
|
|
|
|
# 设置环境变量
|
|
test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
|
|
test -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
|
|
----
|
|
|
|
=== 替换现有仓库上游
|
|
[source ,bash]
|
|
----
|
|
# 设置环境变量
|
|
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
|
|
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
|
|
|
|
# 更新 brew
|
|
brew update
|
|
|
|
# 设置环境变量
|
|
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
|
|
|
|
|
|
brew tap --custom-remote --force-auto-update homebrew/core https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
|
|
brew tap --custom-remote --force-auto-update homebrew/cask https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
|
|
brew tap --custom-remote --force-auto-update homebrew/cask-fonts https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
|
|
brew tap --custom-remote --force-auto-update homebrew/cask-drivers https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
|
|
brew tap --custom-remote --force-auto-update homebrew/cask-versions https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git
|
|
brew tap --custom-remote --force-auto-update homebrew/command-not-found https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-command-not-found.git
|
|
|
|
brew update
|
|
----
|
|
|
|
== Shottr 截屏
|
|
这是一款功能丰富,支持小巧,反应快速的截图工具,并且还是免费的,很难得。
|
|
|
|
== 查看隐藏文件
|
|
在访达文件夹中, 通过快捷键 [command + shift + .] 进行切换
|
|
|
|
== 刷新 dns
|
|
[source,bash]
|
|
----
|
|
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
|
|
----
|
|
|
|
== crontab
|
|
[source,bash]
|
|
----
|
|
# 查看 crontab 是否启动,Mac的定时任务都由 launchctl 来管理.
|
|
sudo launchctl list | grep cron
|
|
|
|
# 输出
|
|
- 0 com.vix.cron
|
|
|
|
# 没有就查看一下启动项的配置
|
|
locate com.vix.cron
|
|
|
|
# 输出
|
|
WARNING: The locate database (/var/db/locate.database) does not exist.
|
|
To create the database, run the following command:
|
|
|
|
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
|
|
|
|
Please be aware that the database can take some time to generate; once
|
|
the database has been created, this message will no longer appear.
|
|
|
|
# 报错,database 不存在,按照提示步骤创建一个
|
|
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
|
|
|
|
# 再次查看一下启动项的配置
|
|
locate com.vix.cron
|
|
|
|
# 输出
|
|
WARNING: The locate database (/var/db/locate.database) does not exist.
|
|
To create the database, run the following command:
|
|
|
|
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
|
|
|
|
Please be aware that the database can take some time to generate; once
|
|
the database has been created, this message will no longer appear.
|
|
|
|
# 发现没效果,进行库更新一下
|
|
sudo /usr/libexec/locate.updatedb
|
|
|
|
# 再次查看一下启动项的配置
|
|
locate com.vix.cron
|
|
|
|
# 输出
|
|
/System/Library/LaunchDaemons/com.vix.cron.plist
|
|
|
|
# 查看配置项
|
|
vi /System/Library/LaunchDaemons/com.vix.cron.plist
|
|
|
|
# 配置项的内容
|
|
----
|
|
|
|
[source,xml]
|
|
----
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
|
|
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>com.vix.cron</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>/usr/sbin/cron</string>
|
|
</array>
|
|
<key>KeepAlive</key>
|
|
<dict>
|
|
<key>PathState</key>
|
|
<dict>
|
|
<key>/etc/crontab</key>
|
|
<true/>
|
|
</dict>
|
|
</dict>
|
|
<key>QueueDirectories</key>
|
|
<array>
|
|
<string>/usr/lib/cron/tabs</string>
|
|
</array>
|
|
<key>EnableTransactions</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
----
|
|
|
|
[source,bash]
|
|
----
|
|
# 注意,其中有个 KeepAlive 的条件是 /etc/crontab 是否存在
|
|
# 所以查看是否存在,如果不存在,我们需要创建一个,不然任务是无法正常运行的。
|
|
sudo touch /etc/crontab
|
|
|
|
# 到此,就完美了,接下来我们开始创建任务了。
|
|
|
|
# 我们通过下面一个命令来添加一个计划任务
|
|
crontab -e
|
|
|
|
# 我们会进入一个页面,上面就可以添加我们的计划任务了,每一行代表一条。
|
|
*/1 * * * * touch /Users/wangshaoping/Desktop/test/$(date +\%Y\%m\%d\%H\%M\%S)
|
|
|
|
# 查看我们的所有任务
|
|
crontab -l
|
|
|
|
# 删除任务
|
|
crontab -r
|
|
----
|
|
|
|
== 如何加速 github 网站的访问
|
|
github 由于某些原因,经常导致无法访问或者访问比较慢,主要是因为 dns 的污染,可通过以下方式加速 github 网站的访问。
|
|
|
|
.增加 crontab 任务
|
|
[source,bash]
|
|
----
|
|
# 增加 crontab 任务, 每小时更新 /etc/hosts 文件,获得最近的 github 网址的 ip 地址
|
|
crontab -e
|
|
|
|
# 增加以下内容,每个小时更新一次 /etc/hosts 文件
|
|
0 0/1 * * * sh /Users/wangshaoping/Documents/etc/crontab-github.sh
|
|
----
|
|
|
|
./Users/wangshaoping/Documents/etc/crontab-github.sh
|
|
[source,bash]
|
|
----
|
|
#!/bin/bash
|
|
source /etc/profile
|
|
|
|
# 替换 /Users/wangshaoping/Documents/etc/hosts 文件中以下部分
|
|
# GitHub520 Host Start
|
|
# .......
|
|
# Github520 Host End
|
|
sed -i "" "/# GitHub520 Host Start/,/# Github520 Host End/d" /Users/wangshaoping/Documents/etc/hosts
|
|
|
|
# 从 https://raw.hellogithub.com 下载 hosts 文件并将其内容追加到 /Users/wangshaoping/Documents/etc/hosts 文件的最后
|
|
curl https://raw.hellogithub.com/hosts >> /Users/wangshaoping/Documents/etc/hosts
|
|
|
|
# 将 /Users/wangshaoping/Documents/etc/hosts 文件复制到 /etc/hosts 文件
|
|
cp /Users/wangshaoping/Documents/etc/hosts /etc/hosts
|
|
----
|
|
|
|
./Users/wangshaoping/Documents/etc/hosts
|
|
[source,bash]
|
|
----
|
|
##
|
|
# Host Database
|
|
#
|
|
# localhost is used to configure the loopback interface
|
|
# when the system is booting. Do not change this entry.
|
|
##
|
|
127.0.0.1 localhost
|
|
255.255.255.255 broadcasthost
|
|
::1 localhost
|
|
|
|
# Added by Docker Desktop
|
|
# To allow the same kube context to work on the host and the container:
|
|
127.0.0.1 kubernetes.docker.internal
|
|
# End of section
|
|
|
|
# sonatype nexus repository and gitlab source code repository
|
|
127.0.0.1 platform.sc.io
|
|
----
|
|
|
|
.修改 /etc/hosts 文件权限
|
|
[source,bash]
|
|
----
|
|
# 修改 /etc/hosts 文件权限
|
|
sudo chmod a+rw /etc/hosts
|
|
|
|
# 修改 /Users/wangshaoping/Documents/etc/crontab-github.sh 文件权限
|
|
chmod a+x /Users/wangshaoping/Documents/etc/crontab-github.sh
|
|
----
|
|
|
|
== 微软 Windows 云桌面
|
|
微软学习平台的这个云桌面是微软家的,是用来进行学习微软相关课程知识的。
|
|
|
|
* 众所周知,国内是可以直接访问微软的!
|
|
* 众所不周知,微软的学习平台提供了云桌面服务。
|
|
* 众所不周知,微软的云桌面的ip地址是全球各地的CDN。
|
|
|
|
所以,我们可以借助微软的云桌面,协助我们的办公工作。
|
|
|
|
=== 申请网址
|
|
https://learn.microsoft.com/zh-cn/training/modules/implement-common-integration-features-finance-ops/10-exercise-1
|
|
|
|
image::9999-appendix/mac/001.png[,80%]
|
|
|
|
访问上述网址,点击【登录以启动 VM 模式】登录微软账号,完成授权。授权里面可能需要你填写一些信息,能跳过就跳过,随便填。国家一栏当然是填美国了。
|
|
|
|
=== 限制
|
|
每次可连续使用2小时,超过2小时则会自动断开,并且清空云桌面的内容,无法保存数据。毕竟这本来是用于学习的工具。
|