MacOS Terminal 常用快捷键大全

常用功能键

在macOS中有一些“特殊”的按键,被称之为 “modifier keys”,中文一般称为 “功能键”,部分常用的功能键如下表所示。

Modifier keySymbol
Command (or Cmd)
Shift
Option (or Alt)
Control (or Ctrl)
Caps Lock
FnFn
Left Arrow
Right Arrow
Up Arrow
Down Arrow

控制窗体和页 | Work with Terminal windows and tabs

Shortcut 快捷键Action 动作
⌘ + NNew window
⌘ + TNew tab
⇧ + ⌘ + Backslash (\)Show all tabs or exit tab overview
⇧ + ⌘ + NNew command
⇧ + ⌘ + KNew remote connection
⌘ + IShow or hide Inspector
⇧ + ⌘ + IEdit title
⌥ + ⌘ + IEdit background color
⌘ + Plus (+)Make fonts bigger
⌘ + Minus (–)Make fonts smaller
⌘ + Grave Accent (`)Circle through witndows
⌘ + ⇧ + Tilde (~)Previous window
⌃ + TabNext Tab
⌃ + ⇧ + TabPrevious Tab
⌘ + 1Select the first tab (also available for ⌘+2, ⌘ + 3, …, if corresponding tabs existed).
⌘ + DSplit window into two panes
⇧ + ⌘ + DClose split pane
⌘+ + WClose tab
⇧ + ⌘ + WClose window
⌥ + ⌘ + WClose other tabs
⌥ + ⇧ + ⌘ + WClose all
⌘ + HomeScroll to top
⌘ + EndScroll to bottom
⌘ + Page UpPage up
⌘ + Page DownPage down
⌘ + ⌥ + Page UpLine up
⌘ + ⌥ + Page DownLine down

编辑命令行 | Edit a command line

ShortcutAction
⌃ + AMove the insertion point to the beginning of the line
⌃ + EMove the insertion point to the end of the line
Move the insertion point forward one character
Move the insertion point backward one character
⌥ + →Move the insertion point forward one word
⌥ + ←Move the insertion point backward one word
⌃ + UDelete to the beginning of the line
⌃ + KDelete to the end of the line
⌥ + DDelete forward to the end of the word
⌃ + WDelete backward to the beginning of the word
DeleteDelete one character
Fn + DeleteForward+ delete one character
⌃ + TTranspose two characters

选择操作 | Select and find text in a Terminal window

快捷键组合 | Key Combinations

ShortcutAction
⌘ + XCut
⌘ + CCopy
⌃ + ⇧ + ⌘ + CCopy without background color
⌥ + ⇧ + ⌘ + CCopy plain text
⌘ + VPaste
⇧ + ⌘ + VPaste the selection
⌃ + ⌘ + VPaste escaped text
⌃ + ⇧ + ⌘ + VPaste escaped selection
⌘ + FFind
⌘ + GFind next
⌘ + ⇧ + GFind previous
⌘ + EFind using the selected text
⌘ + JJump to the selected text
⌘ + ASelect all
⌃ + ⌘ + SpaceOpen the character viewer

操作 | Operations

  • Press and hold the ⇧ and ⌘ keys and double+ click the path/URL
    Select a complete file path/URL
  • Triple+ click the line
    Select a complete line of text
  • Double+ click the word
    Select a word
  • Press and hold the ⌥ key and drag to select text
    Select a rectangular block

标记和书签 | Work with marks and bookmarks

ShortcutAction
⌘ + UMark
⌥ + ⌘ + UMark as bookmark
⇧ + ⌘ + UUnmark
⌘ + ReturnMark line and send return
⇧ + ⌘ + ReturnSend return without marking
⇧ + ⌘ + MInsert bookmark
⌥ + ⇧ + ⌘ + MInsert bookmark with name
⌘ + ↑Jump to previous mark
⌘ + ↓Jump to next mark
⌥ + ⌘ + ↑Jump to previous bookmark
⌥ + ⌘ + ↓Jump to next bookmark
⌘ + LClear to previous mark
⌥ + ⌘ + LClear to previous bookmark
⌘ + KClear to start
⇧ + ⌘ + ASelect between marks

其他 | Other shortcuts

ShortcutAction
⌃ + ⌘ + FEnter or exit full screen
⇧ + ⌘ + CShow or hide colors
⌘ + Comma (,)Open Terminal preferences
⌥ + ⌘ + RSoft reset terminal emulator state
⌃ + ⌥ + ⌘ + RHard reset terminal emulator state
⌘ + SExport text as
⌘ + PPrint
⇧ + ⌘ + SExport selected text as
⌃ + RReverse search ⌘ history
⌘ + RToggle “Allow Mouse Reporting” ⌥
⌘ + ⌥ + OToggle “Use ⌥ as Meta Key” ⌥
⌥ + ⌘ + Page DownShow alternate screen
⌥ + ⌘ + Page UpHide alternate screen
⌃ + ⇧ + ⌘ + Question Mark (?)Open man page for selection
⌃ + ⌥ + ⌘ + Slash (/)Search man page index for selection

操作 | Operations

  • Typing ⌘ + Period (.) is equivalent to entering ⌃ + C on the ⌘ line
    Break
  • Hold down the ⌘ key and double + click the URL
    Open a URL
  • Drag the file from the Finder into the Terminal window
    Add the complete path to a file
  • On a ⌘ line, type one or more characters, then press Tab
    Complete directory or file name
  • On a ⌘ line, type one or more characters, then press Tab twice
    Display a list of possible directory or file name completions

常用命令

按键/命令描述
Ctrl + A移动光标至行首,也适用于大多数文本编辑器
Ctrl + E移动光标至行尾,也适用于大多数文本编辑器
Ctrl + Q清除当前行中的所有内容
Ctrl + L清屏
⌘ + K清屏
Ctrl + U剪切光标前的所有字符
Ctrl + K剪切光标后的所有字符
Ctrl + W剪切光标前的内容,直到遇到为止
Ctrl + Y粘贴上一次剪切的字符
Ctrl + H与退格键相同
Ctrl + C终止当前执行的进程
Ctrl + D当没有进程在执行时退出当前终端,如果当前有进程就发送 EOF 命令给当前进程
Ctrl + Z将执行中的任何东西放入后台进程。fg 可以将其恢复。
Ctrl + _撤销最后一条命令(因为是下划线,所以实际上是 Ctrl + ⇧ + _)
Ctrl + T将光标前的两个文字进行互换
Ctrl + F将将光标向前移动一个字符
Ctrl + B将将光标向后移动一个字符
⌥ + →光标向前移动一个单词
⌥ + ←光标向后移动一个单词
Esc + T将光标前的两个单词进行互换
Tab自动补全文件或文件夹的名称

核心命令

按键/命令描述
cd [folder]切换目录,例如 cd Documents
cdHome目录
cd ~Home目录
cd /根目录
cd +上一个目录
ls文件列表
ls + l文件详细列表
ls + a列出隐藏文件
ls + lh详细文件列表中文件大小以更友好的形式列出
ls + R递归显示文件夹中的内容
sudo [⌘ ]以超级用户身份执行命令
open [file]打开文件 ( 相当于双击一个文件 )
top显示运行中的进程,按q终止
nano [file]使用 nano 打开编辑
vim[file]
clear清屏
reset重置终端显示

命令链

Key/CommandDescription
[⌘ + a]; [⌘ + b]不管命令 a 是否执行成功,执行完命令 a 后再执行命令 b
[⌘ + a] && [⌘ + b]如果命令 a 执行成功就执行命令 b
[⌘ + a]
[⌘ + a] &在后台执行命令 a

命令管道

Key/CommandDescription
[⌘ + a] / [⌘ + b]运行命令 a,然后将结果给命令 b,例如 ps auxwww

管道命令

按键/命令描述
history n列出最近执行过的 n 条命令
ctrl+ r检索之前执行过的命令
![value]执行最近以 value 开始的命令
![value]:p显示最近以 value 开始的命令
!!执行最后一次执行的命令
!!:p显示最后一次执行的命令

命令历史

按键/命令描述
history n列出最近执行过的n条命令
ctrl+ r交互式检索之前执行过的命令
![value]执行最近以’value’开始的命令
![value]:p将最近以’value’开始的命令打印到终端
!!执行上一条命令
!!:p将上一条命令打印到终端

文件管理

按键/命令描述
touch [file]创建一个新文件
pwd显示当前工作目录
.当前目录, 例如 ls .
上级目录, 例如 ls …
ls + l …上级目录的文件详细列表
cd …/…/向上移动两个层级
cat连接或打印文件到屏幕上
rm [file]移除文件, 例如 rm data.tmp
rm + i [file]移除时出现确认提示
rm + r [dir]移除文件及内容
rm + f [file]强制移除
cp [file] [newfile]复制文件
cp [file] [dir]复制文件到指定目录
mv [file] [new filename]移动/重命名, 例如 mv file1.ad /tmp
pbcopy < [file]把内容复制到剪切板中
pbpaste粘贴剪切板中的内容
pbpaste > [file]把剪切板中的内容复制到文件里 pbpaste > paste+ test.txt

目录管理

按键/命令描述
mkdir [dir]创建新目录
mkdir + p [dir]/[dir]创建子目录
rmdir [dir]移除目录 ( 仅限目录下没有内容时 )
rm + R [dir]移除目录及内容
less [file]根据当前终端窗口大小来输出文件内容
[⌘ ] > [file]将命令输出的内容覆盖�到文件里
[⌘ ] >> [file]将命令输出的内容附加到文件里
[⌘ ] < [file]告诉命令从文件中读取内容

搜索

Key/⌘ | Description
|:+ + ?:+ + |
find [dir] + name [search_pattern] | 搜索文件, 例如 find /Users + name “file.txt”
grep [search_pattern] [file] | 搜索文件中含有关键字的所有行, e.g. grep “Tom” file.txt
grep + r [search_pattern] [dir] | 递归搜索目录的所有文件中包含该关键字的所有行
grep + v [search_pattern] [file] | 搜索文件中不含有关键字的所有行
grep + i [search_pattern] [file] | 搜索文件中含有关键字(不区分大小写)的所有行
mdfind [search_pattern] | 用 Spotlight 搜搜文件 (搜索范围包涵名字、内容、其他文件数据), 例如 mdfind skateboard
mdfind + onlyin [dir] + name [pattern] | 用 Spotlight 搜索制定目录中名字包涵关键字的文件

帮助

按键/命令描述
⌘ + h显示帮助信息
⌘ + help显示帮助信息
info [⌘ ]提供帮助
man [⌘ ]显示指定命令的帮助信息
whatis [⌘ ]显示指定命令的简述
apropos [search+ pattern]使用关键字搜索描述内容

引用

[1] 0nn0, terminal-mac-cheatsheet, https://github.com/0nn0/terminal-mac-cheatsheet/tree/master/中文
[2] Apple Official Support, Keyboard shortcuts for Terminal on Mac, https://support.apple.com/guide/terminal/keyboard-shortcuts-trmlshtcts/mac
[3] Apple Official Support, Mac keyboard shortcuts, https://support.apple.com/en-us/HT201236

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值