Một tài liệu tham khảo Bash / shell có thể tìm kiếm và in được — điều hướng, tệp, pipe, biến, vòng lặp, điều kiện và các one-liner tiện dụng. Miễn phí.

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

Không có mục nào khớp với “:q”.


Giới thiệu về Bảng tra cứu Shell

Bảng tra cứu Bash và shell này bao gồm dòng lệnh từ những bước đầu tiên đến viết script: điều hướng, tệp và thư mục, tìm kiếm, xử lý văn bản, pipe và redirection, quyền và chủ sở hữu, tiến trình và thông tin hệ thống, biến và mở rộng, cùng các cấu trúc viết shell script.

Nó kết hợp các lệnh dùng hằng ngày — ls, cp, grep, find, chmod, ps — với các cờ giúp chúng phát huy tác dụng, cùng cú pháp pipe, redirection và expansion biến các lệnh đơn lẻ thành one-liner. Phần viết script nhắc bạn cú pháp loop, điều kiện và hàm khi bạn chỉ viết script vài lần một năm.

Tất cả nằm trên một trang miễn phí, chạy phía client: ô tìm kiếm lọc các dòng theo thời gian thực, mục lục cố định nhảy giữa các phần, một cú click sao chép bất kỳ lệnh nào và nút in cho bạn một tài liệu tham khảo terminal để dùng tại bàn làm việc.

Cách sử dụng Bảng tra cứu Shell

  1. Duyệt qua các phần, từ Navigation và Files & directories đến Pipes & redirection rồi Scripting.
  2. Gõ tên lệnh như grep hoặc chmod vào ô tìm kiếm để lọc bảng ngay lập tức.
  3. Nhảy đến một phần như Text processing qua thanh bên cố định.
  4. Nhấp vào một lệnh hoặc biểu tượng sao chép của nó để sao chép, rồi dán vào terminal của bạn.
  5. In trang để có tài liệu tham khảo lệnh Bash ngoại tuyến.

Câu hỏi thường gặp

Bảng được viết cho Bash và các shell kiểu POSIX, nên gần như mọi thứ đều hoạt động y nguyên trên bash, zsh và các shell tương tự trên Linux và macOS.

Cả hai. Bên cạnh các lệnh tệp, tìm kiếm, xử lý văn bản và tiến trình, các phần riêng biệt bao gồm biến và mở rộng cùng các cấu trúc viết script — vòng lặp, điều kiện và cú pháp bạn hay quên giữa các lần viết script.

Có. Nhấp vào lệnh hoặc biểu tượng sao chép trên dòng của nó và nó sẽ được đặt vào clipboard, sẵn sàng để dán vào terminal.

Luôn đọc kỹ một lệnh trước khi chạy, đặc biệt là bất cứ điều gì liên quan đến rm, quyền hoặc redirection. Mỗi dòng đều có mô tả một câu về chính xác lệnh đó làm gì.

Có, hoàn toàn miễn phí — đây là trang tham khảo chạy phía client, không cần tài khoản và không giới hạn.


Tìm kiếm phổ biến
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
Cần trợ giúp?
Gặp sự cố với công cụ này? Hãy cho đội ngũ của chúng tôi biết.
Báo cáo sự cố

Thêm công cụ miễn phí này vào trang web của riêng bạn — sao chép và dán mã bên dưới.