所有工具
免費

一份可搜尋、可列印的 Bash / shell 參考——導覽、檔案、管道、變數、迴圈、條件判斷和實用的單行指令。免費。

Navigation

8
pwd
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

10
touch 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

8
grep '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

9
wc -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

9
a | 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

8
chmod 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

9
ps 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

9
NAME='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 速查表

  1. 瀏覽各章節,從導覽、檔案與目錄,經管線與重新導向,到腳本撰寫。
  2. 在搜尋框輸入指令名稱,例如 grep 或 chmod,即可即時篩選小抄內容。
  3. 透過固定式側邊欄跳到文字處理等章節。
  4. 點擊指令或其複製圖示以複製,然後貼到終端機中。
  5. 列印本頁即可取得離線的 Bash 指令參考資料。

常見問題

此小抄以 Bash 及 POSIX 風格的 shell 為對象撰寫,因此幾乎所有內容都能原封不動用在 Linux 與 macOS 上的 bash、zsh 及類似 shell。

兩者皆有。除了檔案、搜尋、文字處理與行程相關指令外,還有專門章節涵蓋變數與展開,以及迴圈、條件式等腳本語法結構——那些你在腳本之間容易忘記的東西。

可以。點擊指令或其列上的複製圖示,指令即會放入剪貼簿,隨時可貼到終端機中使用。

執行任何指令前都應先仔細閱讀,尤其是涉及 rm、權限或重新導向的指令。每一列都附有一行說明,清楚寫明該指令的作用。

是的,完全免費——這是一個不需帳號、無使用次數限制的純用戶端參考頁面。


熱門搜尋
linux commands cheat sheet bash cheat sheet shell commands list grep and find examples bash scripting reference chmod permissions cheat sheet pipes and redirection bash terminal commands list
需要協助?
使用此工具時遇到問題?請告訴我們的團隊。
回報問題

將此免費工具新增到你自己的網站 — 複製並貼上下面的程式碼。