免费转换器

Linux / Bash 命令速查表

全面的Linux和Bash命令速查表。搜索80+个常用命令,附带示例、描述和一键复制功能。

ls
List directory contents
示例:ls -la /home/user
ls -la
List all files including hidden, with details
示例:ls -la ~/Documents
cd
Change directory
示例:cd /var/log
pwd
Print working directory path
示例:pwd
mkdir
Create a new directory
示例:mkdir -p /tmp/mydir/subdir
rm
Remove files or directories
示例:rm -rf /tmp/oldfiles
cp
Copy files or directories
示例:cp -r /src/dir /dst/dir
mv
Move or rename files/directories
示例:mv oldname.txt newname.txt
touch
Create an empty file or update timestamp
示例:touch newfile.txt
find
Search for files in a directory hierarchy
示例:find /home -name '*.log' -mtime -7
locate
Find files by name using a prebuilt database
示例:locate nginx.conf
ln
Create hard or symbolic links
示例:ln -s /path/to/target /path/to/link
df
Report disk space usage of file systems
示例:df -h
du
Estimate file space usage
示例:du -sh /var/log/*
stat
Display file or file system status
示例:stat /etc/passwd
file
Determine file type
示例:file /usr/bin/bash
cat
Concatenate and display file contents
示例:cat /etc/hosts
less
View file content one screen at a time
示例:less /var/log/syslog
more
View file content page by page
示例:more /etc/passwd
head
Output the first part of a file
示例:head -n 20 /var/log/auth.log
tail
Output the last part of a file
示例:tail -f /var/log/syslog
grep
Search text using patterns
示例:grep -rn 'error' /var/log/
sed
Stream editor for filtering and transforming text
示例:sed 's/old/new/g' file.txt
awk
Pattern scanning and text processing language
示例:awk '{print $1, $3}' access.log
sort
Sort lines of text files
示例:sort -k2 -n data.txt
uniq
Report or omit repeated lines
示例:sort file.txt | uniq -c
wc
Print newline, word, and byte counts
示例:wc -l /etc/passwd
cut
Remove sections from each line of files
示例:cut -d: -f1 /etc/passwd
tr
Translate or delete characters
示例:echo 'hello' | tr 'a-z' 'A-Z'
echo
Display a line of text
示例:echo "Hello, World!"
printf
Format and print data
示例:printf "%s\t%d\n" name 42
diff
Compare files line by line
示例:diff file1.txt file2.txt
tee
Read from stdin and write to stdout and files
示例:ls | tee output.txt
ps
Report a snapshot of current processes
示例:ps aux | grep nginx
top
Display Linux processes in real time
示例:top -u www-data
htop
Interactive process viewer (ncurses-based)
示例:htop
kill
Send a signal to a process
示例:kill -9 1234
killall
Kill processes by name
示例:killall firefox
bg
Resume a suspended job in the background
示例:bg %1
fg
Bring a job to the foreground
示例:fg %1
jobs
List active jobs in the current shell
示例:jobs -l
nohup
Run a command immune to hangups
示例:nohup ./script.sh &
nice
Run a command with modified scheduling priority
示例:nice -n 10 ./heavy_task.sh
systemctl
Control the systemd system and service manager
示例:systemctl restart nginx
service
Run a System V init script
示例:service apache2 status
ping
Send ICMP ECHO_REQUEST to network hosts
示例:ping -c 4 google.com
curl
Transfer data from or to a server
示例:curl -L -o file.zip https://example.com/file.zip
wget
Non-interactive network downloader
示例:wget -q https://example.com/file.tar.gz
ssh
OpenSSH remote login client
示例:ssh -i ~/.ssh/key.pem user@host
scp
Secure copy files between hosts
示例:scp user@host:/path/file.txt ./local/
rsync
Remote file copying tool with delta transfer
示例:rsync -avz /src/ user@host:/dst/
netstat
Print network connections and routing tables
示例:netstat -tulpn
ss
Utility to investigate sockets
示例:ss -tulwn
ifconfig
Configure a network interface
示例:ifconfig eth0
ip
Show and manipulate routing, devices, and tunnels
示例:ip addr show
nmap
Network exploration tool and port scanner
示例:nmap -sV 192.168.1.0/24
dig
DNS lookup utility
示例:dig +short A google.com
nslookup
Query Internet name servers interactively
示例:nslookup example.com
chmod
Change file mode bits (permissions)
示例:chmod 755 script.sh
chown
Change file owner and group
示例:chown -R www-data:www-data /var/www
chgrp
Change group ownership
示例:chgrp developers project/
sudo
Execute a command as another user (superuser)
示例:sudo systemctl restart nginx
su
Change user ID or become superuser
示例:su - postgres
passwd
Change user password
示例:passwd username
umask
Set or display the file mode creation mask
示例:umask 022
id
Print user and group information
示例:id username
whoami
Print the current effective user name
示例:whoami
groups
Print the groups a user is in
示例:groups username
tar
Archive files using tape archive format
示例:tar -czvf archive.tar.gz /path/to/dir
tar -x
Extract files from a tar archive
示例:tar -xzvf archive.tar.gz -C /target/
gzip
Compress files using GNU zip
示例:gzip -9 large_file.log
gunzip
Decompress gzip compressed files
示例:gunzip archive.tar.gz
zip
Package and compress files into a ZIP archive
示例:zip -r output.zip /path/to/dir
unzip
Extract files from a ZIP archive
示例:unzip archive.zip -d /target/
bzip2
Compress files using bzip2 algorithm
示例:bzip2 -z large_file.txt
xz
Compress files using the XZ algorithm
示例:xz -z -9 file.txt
uname
Print system information
示例:uname -a
uptime
Tell how long the system has been running
示例:uptime
free
Display amount of free and used memory
示例:free -h
lscpu
Display information about the CPU architecture
示例:lscpu
lsblk
List information about block devices
示例:lsblk -o NAME,SIZE,TYPE,MOUNTPOINT
lspci
List all PCI devices
示例:lspci -v | grep VGA
dmesg
Print or control the kernel ring buffer
示例:dmesg | tail -50
journalctl
Query and display messages from the journal
示例:journalctl -u nginx --since '1 hour ago'
history
Display the command history list
示例:history | grep docker
env
Print environment variables
示例:env | grep PATH
if / then / fi
Conditional execution in shell scripts
示例:if [ -f file.txt ]; then echo exists; fi
for
Loop over a list of items
示例:for i in 1 2 3; do echo $i; done
while
Execute commands while a condition is true
示例:while read line; do echo $line; done < file
case
Multi-branch conditional matching pattern
示例:case "$var" in a) echo A;; b) echo B;; esac
function
Define a shell function
示例:greet() { echo "Hello, $1!"; }; greet World
export
Set environment variables for child processes
示例:export MY_VAR=value
source
Execute commands from a file in current shell
示例:source ~/.bashrc
alias
Create an alias for a command
示例:alias ll='ls -la'
cron / crontab
Schedule commands to run periodically
示例:crontab -e # 0 * * * * /path/to/script.sh
at
Execute commands at a specified time
示例:echo 'ls /tmp' | at 14:30

关于此工具

Linux bash 的综合快速参考指南。浏览按类别组织的常用命令、语法和示例。可搜索且适合移动设备 - 将此页面添加为书签,以便在需要快速提醒时即时访问。

使用方法

  1. 浏览分类的参考部分。
  2. 使用搜索栏查找特定命令或语法。
  3. 单击任意条目即可查看使用示例和说明。
  4. 直接复制命令以在终端或编辑器中使用。

常见问题

该参考文献是最新的吗?
该参考涵盖了广泛使用的命令和语法,这些命令和语法在各个版本中都是稳定的。有关最新添加或特定于版本的功能,请查看官方文档。
我可以离线使用吗?
加载后,该页面无需互联网连接即可运行。将其添加为书签以便快速访问 - 所有内容都在浏览器中呈现,无需进一步的网络请求。
这是全面的还是只是基础知识?
它涵盖了处理 90% 日常任务的最常用命令和模式。对于利基或高级功能,请参阅官方文档。
我可以建议补充吗?
我们定期更新我们的参考资料。如果您发现缺少命令或有建议,请通过我们的联系页面告知我们。