玩转Mac系列
1、终端命令
1.1、隐藏与显示隐藏文件
# 显示开启
defaults write com.apple.finder AppleShowAIIFiles -bool true
killall Finder
# 显示关闭
defaults write com.apple.finder AppleShowAIIFiles -bool false
killall Finder
其实有更简单的做法就是封装Linuxll
命令,例如:
1、新建一个.command
文件(专门封装自定义的命令),文件内容如下
laizhenghua@laizhenhuadeAir ~ % cat .command
# command
alias ll='ls -alF'
2、修改.zshrc
文件,使其封装命令生效
laizhenghua@laizhenhuadeAir ~ % cat .zshrc
# command
source ~/.command
3、最后在命令行source .zshrc
一下即可
laizhenghua@laizhenhuadeAir ~ % source .zshrc
laizhenghua@laizhenhuadeAir ~ % ll
total 128
drwxr-x---+ 42 laizhenghua staff 1344 3 1 13:12 ./
...
# 这样不管是隐藏的还是其他文件就能全部列举出来
4、查看所有占用端口jps
laizhenghua@laizhenhuadeAir ~ % jps
65122
82219 Jps
93855
23087
82126 RemoteMavenServer36
81182 RemoteJdbcServer
# 杀死对应的进程
kill -9 端口号
1.2、查看Java安装目录
/usr/libexec/java_home -V
1.3、打开Finder
# 打开当前目录
opne .
# 打开父目录
open ..
1.4、查看端口占用情况(Linux同理)
# lsof (list open file) 列出当前系统打开文件的工具
# 查看端口就是 lsof -i:端口号
# 如
lsof -i:8000
1.5、使用指定的软件打开某个文件
# 查看应用名称(在/Applications目录下每个应用都有对应的名称)
laizhenghua@laizhenhuadeAir /Applications % pwd
/Applications
laizhenghua@laizhenhuadeAir /Applications % ls
360Chrome.app SunloginClient.app
360画报.app TencentMeeting.app
CleanMyMac X.app Typora.app
# 使用wps打开excel文件(wps应用名称为 wpsoffice.app )
open -a wpsoffice prod-env.xlsx
# 使用Typora打开 .md 文件
open -a Typora spring6.md
# 使用 默认的 text editor 打开文件
open -t password.txt
1.6、Node多版本安装与切换
# node多版本问题是通过 n 实现
# 1.全局安装 n
npm install n -g
# 2.安装指定的node
sudo n 10.12.0
# 最新版本
sudo n latest
# 3.查看安装的node
n list
# 4.切换node版本(上下箭头选择版本,回车切换)
sudo n
# 5.删除指定的node版本
n rm 16.20.1
1.7、查看CPU信息
# 使用 sysctl -n machdep.cpu.brand_string 可查看mac的CPU信息例如
laizhenghua@laizhenhuadeAir ~ % sysctl -n machdep.cpu.brand_string
Apple M2
# 而在linux中则是
lscpu
2、Jetbrains软件快捷键
1、全局搜索
// shift + Command + F
2、移动代码行
// 方式一 shift + command + ⬆️ 或者 ⬇️
// 方式二 shift + option + ⬆️ 或者 ⬇️
3、单行注释
// commond + /
4、多行注释
// control + shift + /
// option + commond + /
5、返回上一次光标所在位置
// option + commond + ⬅️ 或 ➡️
// command + 【 或 】
6、包围代码块(if,try,while 等)
// option + commond + t
7、自动导包
// options + return
8、删除没有使用到的包
// control + option + o