MacOS自用命令及操作总结
自己常用的 Mac 命令,记录一下。
📟命令部分
文件或者文件夹加密
# 加密文件夹
zip -er ./archive.zip ./backup
# 加密文件
zip -e
# 预览删除空文件夹
find . -type d -empty -print
# 删除空文件夹
find . -type d -empty -delete
重命名之添加后缀
# 统一添加png后缀
for i in *; do mv "$i" "$i.png"; done
finder
隐藏桌面图标
defaults write com.apple.finder CreateDesktop -bool FALSE; killall Finder
显示桌面图标
defaults write com.apple.finder CreateDesktop -bool TRUE; killall Finder
hexo 相关命令
# hexo
# 带目录的新建文章
hexo new -p 2020/MacOS自用命令总结 MacOS自用命令总结
# 发现新建标题带.无法生成正确的文章,必须手动添加.md
hexo new -p 2020/"React.js入门篇.md" "React.js入门篇"
其他
# 打包的时候带上时间后缀
git archive -o ../project_tm`date +%m%d%H%M`.zip medical0808
# 打包的时候带上时间和git commit hash短前缀
git archive -o ~/Desktop/workspace/project_"`date +"%m%d"`"_$(git rev-parse --short HEAD).zip master
# 查看压缩包内容
unzip -vl ../archive.zip
# grep
# 找到多个匹配项输出,这里有 id 和 dwmc 两行
grep -w "id\|dwmc" ~/Documents/list.json
# grep 找到匹配项,包括目标行的上一行
grep -B 1 "match pattern" ~/Documents/listAll.txt
# 只显示当前目录的文件夹大小而不显示子文件夹
du -h -d 1
# 删除长路径的文件夹,尤其是无限嵌套循环的目录,rm -rf 都不行的时候
echo *|xargs rm -rf
# How to use 'find' to return parent directory,找到文件的文件夹路径,不包括文件名
find / -name 'myfile' -type f -exec dirname {} \;
如何删除长路径的文件
命令行移动复制,带进度条,速度
There isn’t. See here as to why. Although it does more than you need, rsync has a --progress parameter. The -a will keep permissions,etc, and -h will be human readable.
rsync -ah --progress <source destination>
如果目标路径有非法字符的话可以这样
rsync -ah --progress user@xx.xx.xx.xx:"<source destination>" <destination path>
也就是用引号括起来。
Pictures/1.jpg
2.13M 100% 2.28MB/s 0:00:00 (xfr#5898, to-chk=1/5905)
Pictures/2.jpg
1.68M 100% 1.76MB/s 0:00:00 (xfr#5899, to-chk=0/5905)
💾配置部分
oh-my-zsh 提示 Insecure completion-dependent directories detected
-
在
.zshrc
文件首行添加# setting ${ZSH_DISABLE_COMPFIX:=true}
-
然后运行
source ~/.zshrc
macOS壁纸路径
macOS壁纸路径是/System/Library/Desktop Pictures
⌨️操作部分
🍋复制图片到剪贴板【这部分先打问号,big sur 好像有点问题。】
初看这个标题好像没什么了不起的,不就是 command + c
么,其实不是。
一般我们截图的时候如果直接想要保留在剪贴板而不是放在桌面,会用到这个截图快捷键 + control 就可以了,类似 Shift+Control+Command+4
能通过拖动鼠标来截取部分屏幕,并复制图片到剪贴板。
但是,你想在截图里标注一些内容然后再复制到剪贴板呢?
找到了这个方法,使用的就是 alfred 的 keyword to applescript
:
最近使用Mac中的Alfred实现一个截图复制到剪贴板的功能,这个命令比较特殊,记录一下。
#!/usr/bin/osascript on run args set the clipboard to POSIX file (first item of args) return the clipboard end
🍏出现无法启动的时候,包括问号文件夹之类的,有几个操作
- 开机按 command + R,这时候可以抹盘安装随机附送的系统版本,比如15年是el captain。
- 开机按 command + option + R,这时候是可以抹盘安装最新的兼容版本,比如catalina。
- 开机按 command + option + shift + R,自己没用,类似 1。
- 开机长按 option 这时候可以选择启动盘。
🍎送修Mac前 万能的两个自救方法:重置 NVRAM(PRAM)与 重置 SMC
如标题所示。