Mac 是一款开发利器,对开发者是相当友好的。
比如系统自带终端(Terminal)对 vim 命令的支持,就大幅提升了日常开发的便捷度。
一、常见命令
pwd
显示当前目录示例:
1
2LeoMacBookPro:~ Leo$ pwd
/Users/Leo显示文件列表命令:
ls
显示当前目录下的所有文件示例:
1
2
3
4LeoMacBookPro:~ Leo$ ls
Applications Downloads Music gitosis-admin
Desktop Library Pictures node_modules
Documents Movies Publicls -al
详细显示当前目录下的所有文件示例:
1
2
3
4
5
6
7LeoMacBookPro:~ Leo$ ls -al
total 144
# ...
drwx------+ 7 Leo staff 238 2 19 19:00 Pictures
drwxr-xr-x+ 6 Leo staff 204 12 19 17:58 Public
drwxr-xr-x 5 Leo staff 170 1 8 13:02 gitosis-admin
drwxr-xr-x 2 Leo staff 68 12 30 18:04 node_modulesls -G
黑/白色的表示普通文件
蓝色的表示文件夹或者目录
红色表示可执行程序示例:
1
2
3
4LeoMacBookPro:~ Leo$ ls -G
Applications Downloads Music gitosis-admin
Desktop Library Pictures node_modules
Documents Movies Public不截图了哈,在终端中是有颜色的。
你可以结合多个参数使用 ls 命令,如
ls -G -al
会详细显示所有文件并颜色处理。
cd
进入或者退出某个目录(文件夹)示例:
1
2
3
4
5LeoMacBookPro:~ Leo$ cd Library/ # 进入 Library 目录
LeoMacBookPro:Library Leo$
LeoMacBookPro:Library Leo$ cd .. # 退出 Library 目录 / 返回父目录
LeoMacBookPro:~ Leo$mkdir
创建文件夹示例:
1
mkdir MyProject
touch
创建新文件示例:
1
touch 1.txt
cp
拷贝示例:
1
2
3# 把 1.txt 拷贝到 MyProject 目录
cp 1.txt MyProject # 相对路径,拷贝到当前目录下的 MyProject 目录
cp 1.txt /Users/Leo/MyProject # 绝对路径rm
删除命令示例:
1
2rm 1.txt # 删除文件 1.txt
rm -rf MyProject # 删除目录 MyProjectmv
改名和移动示例:
1
2mv 1.txt 2.txt # 改名,把 1.txt 重命名为 2.txt
mv 1.txt MyProject # 移动,把 1.txt 移动到当前目录下的 MyProject 目录网络命令:
ifconfig
查看当前网络配置,Windows 系统下是ipconfig
示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33LeoMacBookPro:~ Leo$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=4<VLAN_MTU>
ether 00:00:00:00:6a:1c
inet6 fe80::200:ff:fe00:6a1c%en4 prefixlen 64 scopeid 0x4
inet 192.168.4.100 netmask 0xffffff00 broadcast 192.168.4.255
nd6 options=1<PERFORMNUD>
media: autoselect (100baseTX <full-duplex,flow-control>)
status: active
# ...
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 02:00:00:00:ba:00
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 6 priority 0 path cost 0
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 7 priority 0 path cost 0
nd6 options=1<PERFORMNUD>
media: <unknown type>
status: inactiveping
检查网络是否联通示例:
1
2
3
4
5
6
7
8
9LeoMacBookPro:~ Leo$ ping -c 3 www.baidu.com # ping 百度,`-c 3` 表示三次
PING www.a.shifen.com (220.181.112.244): 56 data bytes
64 bytes from 220.181.112.244: icmp_seq=0 ttl=55 time=2.329 ms
64 bytes from 220.181.112.244: icmp_seq=1 ttl=55 time=2.651 ms
64 bytes from 220.181.112.244: icmp_seq=2 ttl=55 time=9.731 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 2.329/4.904/9.731/3.416 ms
whereis
查看命令路径示例:
1
2LeoMacBookPro:~ Leo$ whereis ls
/bin/ls
二、小技巧
clear
清屏
直接按 Ctrl + L按 tab 键会自动补全
按 ↑ 键会显示上一次使用过的命令
Ctrl + C 终端下操作的强制退出
history
显示历史命令⌘ + +/- 终端下放大/缩小字体
编辑状态下的退出命令
wq
保存并退出wq!
强制保存并退出q!
强制退出,不保存
设置终端语法高亮等
1
2
3
4
5
6vim ~/.vimrc # 创建一个编译环境的脚本的副本
# 编辑输入以下内容
syntax on # 开启语法高亮
set tabstop=4 # 设置tab缩进 一次4个字节
set number # 设置行号
联系与支持
- Mail:
echo bGVvZGF4aWFAZ21haWwuY29tCg== | base64 -D
- GitHub: iTofu
如果你想对我的开发或是开源项目进行支持捐助,请扫描下方二维码,谢谢!👇