Shell 速查表
一份可搜索、可打印的 Bash / shell 参考——导航、文件、管道、变量、循环、条件判断和实用的单行命令。免费。
Navigation
8pwd
Print the working directory
ls -la
List all files with details
cd /path
Change directory
cd -
Go to the previous directory
cd ~
Go to the home directory
tree -L 2
Show directory tree (2 levels)
pushd / popd
Push and pop the directory stack
ls -lhS
List by size, human-readable
Files & directories
10touch file.txt
Create an empty file
mkdir -p a/b/c
Create nested directories
cp -r src dest
Copy recursively
mv old new
Move or rename
rm -rf dir
Remove recursively (careful!)
ln -s target link
Create a symbolic link
cat file.txt
Print file contents
head -n 20 / tail -n 20
First / last 20 lines
tail -f log.txt
Follow a file as it grows
less file.txt
Page through a file
Search & find
8grep 'pattern' file
Search for a pattern in a file
grep -rin 'text' .
Recursive, case-insensitive, numbered
find . -name '*.php'
Find files by name
find . -type f -mtime -1
Files modified in the last day
find . -size +10M
Files larger than 10 MB
which node
Locate an executable
locate file.txt
Find by indexed database
grep -v 'skip' file
Invert match (exclude lines)
Text processing
9wc -l file
Count lines
sort file | uniq -c
Sort then count duplicates
cut -d',' -f1 file
Extract a CSV column
awk '{print $1}' file
Print the first field
sed 's/old/new/g' file
Substitute text
tr 'a-z' 'A-Z'
Translate characters
diff a.txt b.txt
Compare two files
tee out.txt
Write to a file and stdout
xargs -I{} cmd {}
Build commands from input
Pipes & redirection
9a | b
Pipe output of a into b
cmd > file
Redirect stdout (overwrite)
cmd >> file
Redirect stdout (append)
cmd 2> err.log
Redirect stderr
cmd > out 2>&1
Redirect both streams
cmd < input.txt
Read stdin from a file
cmd1 && cmd2
Run cmd2 only if cmd1 succeeds
cmd1 || cmd2
Run cmd2 only if cmd1 fails
cmd &
Run in the background
Permissions & ownership
8chmod 755 file
Set rwx for owner, rx for others
chmod +x script.sh
Make a file executable
chmod -R 644 dir
Recursive permission change
chown user:group file
Change owner and group
umask 022
Default permission mask
sudo cmd
Run a command as root
stat file
Show file metadata
ls -l file
View permission bits
Processes & system
9ps aux
List running processes
top / htop
Live process monitor
kill -9 PID
Force-kill a process
pkill -f name
Kill processes by name
jobs / fg / bg
Manage background jobs
df -h
Disk space usage
du -sh dir
Size of a directory
free -h
Memory usage
uname -a
System and kernel info
Variables & expansion
9NAME='value'
Set a variable (no spaces)
echo \"$NAME\"
Use a variable
export PATH=\"$PATH:/x\"
Export to child processes
$(command)
Command substitution
${VAR:-default}
Default if unset
$1 $2 $@
Script positional arguments
$?
Exit status of the last command
read -p 'Name: ' x
Read user input
echo {1..5}
Brace expansion
Scripting
9#!/usr/bin/env bash
Shebang line
set -euo pipefail
Safer strict mode
if [ -f file ]; then ...; fi
Conditional on a file test
[ \"$a\" = \"$b\" ]
String comparison
for f in *.txt; do ...; done
Loop over files
while read line; do ...; done < file
Read a file line by line
case \"$x\" in a) ...;; esac
Multi-way branch
function greet() { echo hi; }
Define a function
trap cleanup EXIT
Run a handler on exit
没有条目匹配“:q”。
关于 Shell 速查表
这份 Bash 和 Shell 速查表涵盖了从入门到脚本编写的命令行知识:目录导航、文件和目录操作、搜索和查找、文本处理、管道和重定向、权限和所有权、进程和系统信息、变量与展开,以及 Shell 脚本结构。
它把 ls、cp、grep、find、chmod、ps 等日常命令和让它们发挥作用的参数配对在一起,再加上把单条命令变成一行流水线的管道、重定向和展开语法。脚本部分则在你一年才写一次脚本时,帮你重新记起循环、条件和函数的语法。
所有内容都在一个免费的纯客户端页面上:搜索可实时过滤各行,粘性目录可在各章节间跳转,点击即可复制任意命令,打印按钮还能生成一份可放在桌上的终端参考表。
如何使用 Shell 速查表
- 浏览各章节,从「导航」「文件与目录」到「管道与重定向」再到「脚本编写」。
- 在搜索框中输入 grep 或 chmod 等命令名,即可即时过滤速查表。
- 通过粘性侧边栏跳转到「文本处理」等章节。
- 点击命令或其复制图标即可复制,然后粘贴到终端中使用。
- 打印本页,获得一份离线的 Bash 命令参考表。
常见问题
本表是为 Bash 和 POSIX 风格的 Shell 编写的,因此几乎所有内容都可以原样用于 Linux 和 macOS 上的 bash、zsh 等 Shell。
两者都有。除了文件、搜索、文本处理和进程相关命令外,还有专门的章节讲解变量与展开以及脚本结构:循环、条件语句,以及那些你在两次写脚本之间容易忘记的语法。
可以。点击命令或该行的复制图标,它就会被放入剪贴板,可直接粘贴到终端中使用。
在运行任何命令之前一定要先看清楚,尤其是涉及 rm、权限或重定向的命令。每一行都附有一句话说明,准确描述该命令的作用。
是的,完全免费——这是一个纯客户端参考页面,无需账户,也没有使用次数限制。
热门搜索
linux 命令速查表
bash 速查表
shell 命令列表
grep 和 find 示例
bash 脚本参考手册
chmod 权限速查表
bash 管道和重定向
终端命令列表
需要帮助?
使用此工具时遇到问题?请告诉我们的团队。