? 前言 Linux命令行是嵌入式开发和系统管理的核心工具。本手册整理了最常用、最实用的Linux命令,按功能分类,便于快速查找和学习。
? 使用说明 ? 快速查找 : 使用目录快速定位所需命令 ? 实用示例 : 每个命令都配有实际使用示例 ? 效率优先 : 重点介绍高频使用的参数和技巧 ? 嵌入式友好 : 特别标注嵌入式开发中的常用场景 ? 文件和目录操作 基础文件操作 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ls ls -la ls -lh ls -lt ls -lS cd /path/to/dir cd ~ cd - cd .. pwd mkdir dirname mkdir -p a/b/c mkdir -m 755 dirname
文件复制、移动、删除 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 cp file1 file2 cp -r dir1 dir2 cp -p file1 file2 cp -u file1 file2 mv file1 file2 mv file1 /path/ mv dir1 dir2 rm file rm -f file rm -r dir rm -rf dir ln file link ln -s file link
文件查找 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 find /path -name "*.c" find /path -type f find /path -type d find /path -size +100M find /path -mtime -7 find /path -user username find /path -perm 755 locate filename updatedb which command whereis command
? 文件内容操作 查看文件内容 1 2 3 4 5 6 7 8 9 10 11 12 13 cat file cat -n file cat -A file less file more file head file head -n 20 file tail file tail -n 20 file tail -f file
文本搜索和处理 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 grep "pattern" file grep -i "pattern" file grep -r "pattern" dir grep -n "pattern" file grep -v "pattern" file grep -E "pattern1|pattern2" file sed 's/old/new/g' file sed -i 's/old/new/g' file sed -n '1,10p' file sed '5d' file awk '{print $1}' file awk -F: '{print $1}' /etc/passwd awk 'NR==5' file awk 'length > 80' file
文件比较和排序 1 2 3 4 5 6 7 8 9 10 11 12 diff file1 file2 diff -u file1 file2 cmp file1 file2 sort file sort -n file sort -r file sort -u file uniq file uniq -c file
? 系统信息和监控 系统基本信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 uname -a uname -r hostname uptime whoami id date cal lscpu lsblk lsusb lspci dmidecode
进程管理 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ps aux ps -ef pstree top htop kill PID kill -9 PID killall process_name pkill pattern nohup command & jobs bg %1 fg %1 Ctrl+Z Ctrl+C
内存和磁盘 1 2 3 4 5 6 7 8 9 10 11 12 13 free -h cat /proc/meminfo df -h du -h dir du -sh * du -h --max-depth=1 iostat iotop
? 网络工具 网络配置和状态 1 2 3 4 5 6 7 8 9 10 11 ifconfig ip addr show ip route show ip link show netstat -tuln netstat -an ss -tuln lsof -i :80
网络测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ping host ping -c 4 host traceroute host mtr host nslookup domain dig domain host domain wget url curl url curl -O url scp file user@host:path rsync -av src dest
? 权限和用户管理 文件权限 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ls -l file chmod 755 file chmod u+x file chmod g-w file chmod o=r file chmod -R 644 dir chown user file chown user:group file chgrp group file
用户管理 1 2 3 4 5 6 7 8 9 10 11 who w last finger user su user su - sudo command sudo -u user command
? 软件包管理 APT (Debian/Ubuntu) 1 2 3 4 5 6 7 8 9 10 11 12 apt update apt upgrade apt install package apt remove package apt purge package apt autoremove apt search keyword apt show package apt list --installed
YUM/DNF (RedHat/CentOS/Fedora) 1 2 3 4 5 6 7 8 9 10 11 yum update yum install package yum remove package yum search keyword yum info package dnf update dnf install package dnf remove package
? 系统服务管理 Systemd (现代Linux发行版) 1 2 3 4 5 6 7 8 9 10 11 12 13 systemctl start service systemctl stop service systemctl restart service systemctl reload service systemctl enable service systemctl disable service systemctl status service systemctl is-active service systemctl list-units systemctl list-unit-files
?? 压缩和归档 tar归档 1 2 3 4 5 6 7 8 9 10 tar -cvf archive.tar files tar -czvf archive.tar.gz files tar -cjvf archive.tar.bz2 files tar -xvf archive.tar tar -xzvf archive.tar.gz tar -xjvf archive.tar.bz2 tar -tf archive.tar
其他压缩工具 1 2 3 4 5 6 7 8 9 zip -r archive.zip files unzip archive.zip unzip -l archive.zip gzip file gunzip file.gz zcat file.gz
? 系统监控和调试 性能监控 1 2 3 4 5 6 7 8 9 10 11 12 13 top htop atop vmstat 1 iostat 1 sar -u 1 10 iftop nethogs tcpdump wireshark
日志查看 1 2 3 4 5 6 7 8 9 10 journalctl journalctl -u service journalctl -f journalctl --since "1 hour ago" tail -f /var/log/syslog tail -f /var/log/messages grep ERROR /var/log/syslog
?? 嵌入式开发专用 交叉编译环境 1 2 3 4 5 6 7 8 9 10 export CROSS_COMPILE=arm-linux-gnueabihf-export ARCH=armexport PATH=$PATH :/opt/toolchain/binmake ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
设备调试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 minicom -D /dev/ttyUSB0 screen /dev/ttyUSB0 115200 picocom -b 115200 /dev/ttyUSB0 lsmod modinfo module_name dmesg dmesg | tail cat /proc/cpuinfo cat /proc/meminfo cat /proc/version ls /sys/class/gpio
文件系统操作 1 2 3 4 5 6 7 8 9 10 mount /dev/sdb1 /mnt umount /mnt mount -t nfs server:/path /mnt mount -o loop image.img /mnt fsck /dev/sdb1 fsck -f /dev/sdb1 df -h
? 实用技巧和快捷键 命令行快捷键 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Ctrl+A Ctrl+E Ctrl+F Ctrl+B Alt+F Alt+B Ctrl+U Ctrl+K Ctrl+W Ctrl+Y Ctrl+R Ctrl+P Ctrl+N !! !n
管道和重定向 1 2 3 4 5 6 7 8 9 10 11 command > file command >> file command < file command 2> file command &> file command1 | command2 command | tee file command | xargs
别名和函数 1 2 3 4 5 6 7 8 9 10 11 12 alias ll='ls -la' alias grep='grep --color=auto' alias ..='cd ..' function mkcd () { mkdir -p "$1 " && cd "$1 " } alias
? 安全和备份 系统安全 1 2 3 4 5 6 7 8 9 10 ufw enable ufw status ufw allow 22 ufw deny 80 find / -perm -4000 find / -perm -2000 find / -type f -perm 777
备份和同步 1 2 3 4 5 6 7 8 rsync -av source / dest/ rsync -av source / user@host:dest/ rsync -av --delete source / dest/ tar -czf backup.tar.gz /important/data tar -czf backup-$(date +%Y%m%d).tar.gz /data
? 学习资源 手册和帮助 1 2 3 4 5 man command info command command --help which command type command
推荐学习资源 ? 总结 这份Linux命令手册涵盖了日常开发和系统管理中最常用的命令。建议:
循序渐进 : 从基础命令开始,逐步掌握高级功能多加练习 : 在安全环境中多实践,熟能生巧善用手册 : 遇到问题时多查看man手册自定义环境 : 根据需要设置别名和函数安全意识 : 特别是在生产环境中,谨慎使用危险命令掌握这些命令,你将能够高效地进行Linux系统管理和嵌入式开发工作!
? 提示 : 建议将常用命令制作成速查卡片,放在工作台旁边,方便随时查阅。
相关文章推荐 :