ข้อมูลอ้างอิง Bash / shell ที่ค้นหาและพิมพ์ได้ — การนำทาง ไฟล์ pipes ตัวแปร ลูป เงื่อนไข และ one-liners ที่มีประโยชน์ ฟรี

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 นี้ครอบคลุมคำสั่งไลน์ตั้งแต่ขั้นพื้นฐานจนถึงการเขียนสคริปต์: การนำทาง ไฟล์และไดเรกทอรี การค้นหา การประมวลผลข้อความ pipe และ redirection สิทธิ์และความเป็นเจ้าของ โปรเซสและข้อมูลระบบ ตัวแปรและการขยายค่า รวมถึงโครงสร้างการเขียนสคริปต์ shell

มันจับคู่คำสั่งที่ใช้ทุกวัน — ls, cp, grep, find, chmod, ps — เข้ากับแฟล็กที่ทำให้คำสั่งเหล่านั้นมีประโยชน์ พร้อมทั้งไวยากรณ์ pipe, redirection และการขยายค่าที่เปลี่ยนคำสั่งเดี่ยว ๆ ให้กลายเป็น one-liner ส่วนการเขียนสคริปต์ก็ช่วยทบทวนไวยากรณ์ loop, เงื่อนไข และฟังก์ชันสำหรับตอนที่คุณเขียนสคริปต์แค่ปีละสองครั้ง

ทุกอย่างอยู่ในหน้าเดียว ฟรี และทำงานฝั่งไคลเอนต์ทั้งหมด: ช่องค้นหากรองแถวแบบเรียลไทม์ สารบัญแบบ sticky ช่วยกระโดดไปยังแต่ละหมวด คลิกครั้งเดียวเพื่อคัดลอกคำสั่งใด ๆ และปุ่มพิมพ์ก็มอบชีทอ้างอิงเทอร์มินัลไว้ใช้บนโต๊ะทำงาน

วิธีใช้ ชีตสรุป Shell

  1. ไล่ดูหมวดต่าง ๆ ตั้งแต่ Navigation และ Files & directories ไปจนถึง Pipes & redirection และ Scripting
  2. พิมพ์ชื่อคำสั่งอย่าง grep หรือ chmod ลงในช่องค้นหาเพื่อกรองชีทได้ทันที
  3. กระโดดไปยังหมวดอย่าง Text processing ผ่านแถบข้าง sticky sidebar
  4. คลิกคำสั่งหรือไอคอนคัดลอกเพื่อคัดลอก แล้ววางลงในเทอร์มินัลของคุณ
  5. พิมพ์หน้านี้ออกมาเพื่อเก็บไว้เป็นชีทอ้างอิงคำสั่ง Bash แบบออฟไลน์

คำถามที่พบบ่อย

ชีทนี้เขียนขึ้นสำหรับ Bash และ shell แบบ POSIX ดังนั้นเกือบทุกอย่างใช้ได้โดยไม่ต้องแก้ไขใน bash, zsh และ shell ที่คล้ายกันบน Linux และ macOS

มีทั้งสองอย่าง นอกจากคำสั่งเกี่ยวกับไฟล์ การค้นหา การประมวลผลข้อความ และโปรเซส ยังมีหมวดเฉพาะสำหรับตัวแปรและการขยายค่า รวมถึงโครงสร้างการเขียนสคริปต์ — loop, เงื่อนไข และไวยากรณ์ที่มักลืมระหว่างการเขียนสคริปต์แต่ละครั้ง

ได้ คลิกที่คำสั่งหรือไอคอนคัดลอกในแถวนั้น ระบบจะวางคำสั่งลงในคลิปบอร์ดของคุณ พร้อมนำไปวางในเทอร์มินัลได้ทันที

ควรอ่านคำสั่งทุกครั้งก่อนรัน โดยเฉพาะคำสั่งที่เกี่ยวข้องกับ rm สิทธิ์การเข้าถึง หรือ redirection แต่ละแถวมีคำอธิบายสั้น ๆ ว่าคำสั่งนั้นทำอะไรบ้าง

ใช่ ฟรีทั้งหมด — เป็นหน้าอ้างอิงที่ทำงานฝั่งไคลเอนต์ ไม่ต้องมีบัญชีและไม่มีข้อจำกัดใด ๆ

แชร์สิ่งนี้

การค้นหายอดนิยม
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
ต้องการความช่วยเหลือ?
พบปัญหากับเครื่องมือนี้หรือไม่? แจ้งทีมงานของเรา
รายงานปัญหา

เพิ่มเครื่องมือฟรีนี้ลงในเว็บไซต์ของคุณเอง — คัดลอกและวางโค้ดด้านล่าง