文章目录
- 基础命令
- 1. `ls`
- 2. `cd`
- 3. `pwd`
- 4. `cp`
- 5. `mv`
- 6. `rm`
- 7. `echo`
- 8. `cat`
- 9. `head`
- 10. `tail`
 
- 系统信息与管理命令
- 11. `ps`
- 12. `top`
- 13. `htop`
- 14. `kill`
- 15. `df`
- 16. `du`
- 17. `uname`
- 18. `hostname`
- 19. `uptime`
- 20. `who`
- 21. `man`
 
- 文件权限与所有权命令
- 22. `chmod`
- 23. `chown`
 
- 网络管理命令
- 24. `ping`
- 25. `ifconfig`
- 26. `netstat`
- 27. `scp`
- 28. `curl`
- 29. `wget`
- 30. `ssh`
 
- 高级命令
- 31. `awk`
- 32. `sed`
- 33. `grep`
- 34. `strace`
- 35. `lsof`
- 36. `tcpdump`
- 37. `rsync`
- 38. `iptables`
- 39. `systemctl`
- 40. `journalctl`
- 41. `ncdu`
- 42. `vmstat`
- 43. `iostat`
- 44. `crontab`
- 45. `ufw`
- 46. `nc` (Netcat)
- 47. `tar`
- 48. `find`
- 49. `chmod`
- 50. `zip` 和 `unzip`
- 51. `mount` 和 `umount`
- 52. `rsyslog`
- 53. `dd`
 
 
 
基础命令
1. ls
 
功能:列出目录内容。
 用法:
ls [options] [directory]
示例:
ls -lah
2. cd
 
功能:更改当前工作目录。
 用法:
cd [directory]
示例:
cd /home/user/documents
3. pwd
 
功能:显示当前工作目录的路径。
 用法:
pwd
示例:
pwd
4. cp
 
功能:复制文件或目录。
 用法:
cp [options] source destination
示例:
cp -r dir1 dir2
5. mv
 
功能:移动或重命名文件或目录。
 用法:
mv [options] source destination
示例:
mv oldname.txt newname.txt
6. rm
 
功能:删除文件或目录。
 用法:
rm [options] file
示例:
rm -rf unwanted_directory
7. echo
 
功能:在终端打印文本或变量值。
 用法:
echo [options] [string]
示例:
echo "Hello, World!"
8. cat
 
功能:连接文件并在终端输出内容。
 用法:
cat [options] [file]
示例:
cat file.txt
9. head
 
功能:输出文件的前部分内容。
 用法:
head [options] [file]
示例:
head -n 10 file.txt
10. tail
 
功能:输出文件的后部分内容。
 用法:
tail [options] [file]
示例:
tail -n 10 file.txt
系统信息与管理命令
11. ps
 
功能:显示当前运行的进程。
 用法:
ps [options]
示例:
ps -ef
ps -ef | grep nginx
ps aux
ps aux | grep nginx
12. top
 
功能:实时显示系统任务信息。
 用法:
top
示例:
top
13. htop
 
功能:交互式的系统监控工具,比 top 更友好。
 用法:
htop
示例:
htop
14. kill
 
功能:终止进程。
 用法:
kill [options] pid
示例:
kill -9 1234
15. df
 
功能:报告文件系统的磁盘空间使用情况。
 用法:
df [options]
示例:
df -h
16. du
 
功能:估算文件和目录的磁盘使用情况。
 用法:
du [options] [file]
示例:
du -sh /home/user
17. uname
 
功能:显示系统信息。
 用法:
uname [options]
示例:
uname -a
18. hostname
 
功能:显示或设置系统的主机名。
 用法:
hostname [options] [name]
示例:
hostname
19. uptime
 
功能:显示系统运行时间和负载。
 用法:
uptime
示例:
uptime
20. who
 
功能:显示当前登录的用户。
 用法:
who
示例:
who
21. man
 
功能:显示命令的手册页(manual)。
 用法:
man [command]
示例:
man ls
文件权限与所有权命令
22. chmod
 
功能:更改文件或目录的权限。
 用法:
chmod [options] mode file
示例:
chmod 755 script.sh
23. chown
 
功能:更改文件或目录的所有者和群组。
 用法:
chown [options] owner:group file
示例:
chown user:group filename
网络管理命令
24. ping
 
功能:测试网络连通性。
 用法:
ping [options] host
示例:
ping -c 4 google.com
25. ifconfig
 
功能:配置网络接口(现代系统上常用ip命令替代)。
 用法:
ifconfig [interface] [options]
示例:
ifconfig
26. netstat
 
功能:显示网络连接、路由表和网络接口统计信息。
 用法:
netstat [options]
示例:
netstat -tuln
27. scp
 
功能:通过SSH复制文件。
 用法:
scp [options] source destination
示例:
scp -r localdir user@remotehost:/remotedir
28. curl
 
功能:用于从服务器传输数据。
 用法:
curl [options] [url]
示例:
curl -O http://example.com/file.zip
29. wget
 
功能:从网络下载文件。
 用法:
wget [options] url
示例:
wget -c http://example.com/file.zip
30. ssh
 
功能:通过SSH协议远程登录到另一个计算机。
 用法:
ssh [user@]hostname [command]
示例:
ssh user@remotehost
高级命令
31. awk
 
功能:一种强大的文本处理工具,用于模式扫描和处理。
 用法:
awk 'pattern {action}' file
示例:
awk '{print $1, $3}' file.txt
32. sed
 
功能:流编辑器,用于对文件或输入流进行文本转换。
 用法:
sed 's/pattern/replacement/' file
示例:
sed 's/oldword/newword/g' file.txt
33. grep
 
功能:在文件中搜索匹配正则表达式的行。
 用法:
grep [options] pattern [file]
示例:
grep -r "search_term" /path/to/directory
34. strace
 
功能:跟踪系统调用和信号。
 用法:
strace [options] command
示例:
strace -o output.txt ls
35. lsof
 
功能:列出当前系统打开的文件。
 用法:
lsof [options]
示例:
lsof -i :80
36. tcpdump
 
功能:抓取网络数据包并显示详细信息。
 用法:
tcpdump [options]
示例:
tcpdump -i eth0
37. rsync
 
功能:远程同步工具,用于文件和目录同步。
 用法:
rsync [options] source destination
示例:
rsync -avz /local/dir remote:/remote/dir
38. iptables
 
功能:配置Linux内核防火墙,用于数据包过滤。
 **用
法**:
iptables [options] [command]
示例:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
39. systemctl
 
功能:用于管理systemd系统和服务管理器。
 用法:
systemctl [command] [unit]
示例:
systemctl start nginx
40. journalctl
 
功能:查询和管理systemd日志。
 用法:
journalctl [options]
示例:
journalctl -u nginx
41. ncdu
 
功能:基于文本界面的磁盘使用分析器。
 用法:
ncdu [options] [directory]
示例:
ncdu /home/user
42. vmstat
 
功能:报告虚拟内存统计信息。
 用法:
vmstat [options] [delay [count]]
示例:
vmstat 1 5
43. iostat
 
功能:报告CPU和I/O统计信息。
 用法:
iostat [options]
示例:
iostat -x 2 3
44. crontab
 
功能:定时任务调度。
 用法:
crontab [options] [file]
示例:
crontab -e
45. ufw
 
功能:简化的防火墙管理工具(用于配置iptables)。
 用法:
ufw [command]
示例:
ufw enable
ufw allow 22/tcp
46. nc (Netcat)
 
功能:网络工具,用于读写网络连接。
 用法:
nc [options] [hostname] [port]
示例:
nc -zv google.com 80
好的,下面再列举四个常用的Linux命令,完成50个常用命令的总结:
47. tar
 
功能:用于创建和解压归档文件。
 用法:
tar [options] archive file
常用选项:
- -c:创建新归档。
- -x:解压归档。
- -v:详细模式,显示处理文件。
- -f:指定归档文件名。
- -z:通过gzip压缩/解压归档。
 示例:
tar -czvf archive.tar.gz directory
tar -xzvf archive.tar.gz
48. find
 
功能:在目录树中搜索文件和目录。
 用法:
find [path] [expression]
常用选项:
- -name:按名称搜索文件。
- -type:按类型搜索文件(如- f表示文件,- d表示目录)。
 示例:
find /home/user -name "*.txt"
find /var/log -type f -name "*.log"
49. chmod
 
功能:更改文件或目录的权限。
 用法:
chmod [options] mode file
常用选项:
- u:用户权限。
- g:组权限。
- o:其他用户权限。
- a:所有用户权限。
 示例:
chmod 755 script.sh
chmod u+x file.sh
明白了,再补充四个不同的命令,确保没有重复:
50. zip 和 unzip
 
功能:用于压缩和解压缩文件。
 用法:
zip [options] zipfile files
unzip [options] zipfile
示例:
zip -r archive.zip directory
unzip archive.zip
51. mount 和 umount
 
功能:挂载和卸载文件系统。
 用法:
mount [options] device directory
umount [options] directory
示例:
mount /dev/sda1 /mnt
umount /mnt
52. rsyslog
 
功能:系统日志记录和传输。
 用法:
service rsyslog start
service rsyslog stop
service rsyslog restart
示例:
service rsyslog status
53. dd
 
功能:用于转换和复制文件,特别是磁盘克隆。
 用法:
dd [options] if=inputfile of=outputfile
示例:
dd if=/dev/sda of=/dev/sdb bs=4M
dd if=/dev/zero of=/tmp/test.img bs=1M count=100
这些命令可以帮助你完成更多样化的任务,提升Linux系统的管理和操作效率。通过掌握这些命令,能够更有效地管理文件、监控系统、处理网络连接和自动化任务。