linux150个基础命令主要案列
-
1. ls
2. cd
3. pwd
4. mkdir
5. rmdir
6. cp
7. mv
8. rm
9. touch
10. cat
11. less
12. more
13. head
14. tail
15. grep
16. find
17. du
18. df
19. tar
20. gzip
21. unzip
22. awk
23. sed
24. cut
25. sort
26. wc
27. diff
28. patch
29. ps
30. top
31. kill
32. systemctl
33. service
34. ifconfig
35. ip
36. ping
37. netstat
38. hostname
39. dig
40. ss
41. lsof
42. tcpdump
43. mount
44. umount
45. fdisk
46. mkfs
47. chown
48. chmod
49. chgrp
50. useradd
51. userdel
52. passwd
53. groupadd
54. groupdel
55. su
56. sudo
57. cron
58. at
59. history
60. date
61. cal
62. uptime
63. who
64. w
65. last
66. wc
67. tar
68. ps
69. netstat
70. chmod
71. chown
72. chgrp
73. ping
74. dig
75. ifconfig
76. ip
77. route
78. nslookup
79. ssh
80. scp
81. rsync
82. ftp
83. sftp
84. curl
85. wget
86. telnet
87. nc
88. sed
89. awk
90. cut
91. paste
92. diff
93. patch
94. awk
95. sort
96. uniq
97. tr
98. expr
99. grep
100. head
101. tail
102. file
103. cd
104. ls
105. pwd
106. mkdir
107. rmdir
108. rm
109. cp
110. mv
111. touch
112. cat
113. less
114. more
115. tar
116. gzip
117. bzip2
118. unzip
119. basename
120. dirname
121. find
122. locate
123. whereis
124. which
125. wc
126. tee
127. echo
128. read
129. test
130. expr
131. sed
132. awk
133. sort
134. cut
135. head
136. tail
137. join
138. split
139. paste
140. grep
141. uniq
142. comm
143. diff
144. patch
145. bc
146. uptime
147. shutdown
148. reboot
149. exit
150. help2年前 -
在Linux操作系统中,我们可以使用许多命令来执行各种任务。以下是150个常见的基础命令,每个命令都附带了简短的说明和示例。
1. pwd:显示当前工作目录。
示例:pwd2. ls:列出当前目录的文件和子目录。
示例:ls3. cd:更改当前工作目录。
示例:cd /home/user4. mkdir:创建新目录。
示例:mkdir mydir5. touch:创建新文件。
示例:touch myfile.txt6. cp:复制文件或目录。
示例:cp file1.txt file2.txt7. mv:移动或重命名文件和目录。
示例:mv file1.txt newfile.txt8. rm:删除文件和目录。
示例:rm myfile.txt9. cat:查看文件内容。
示例:cat myfile.txt10. less:逐页查看文件内容。
示例:less myfile.txt11. head:显示文件的前几行。
示例:head -n 5 myfile.txt12. tail:显示文件的后几行。
示例:tail -n 5 myfile.txt13. grep:在文件中搜索指定的模式。
示例:grep “hello” myfile.txt14. find:在文件系统中搜索文件。
示例:find / -name myfile.txt15. chmod:更改文件或目录的权限。
示例:chmod 755 myfile.txt16. chown:更改文件或目录的所有者。
示例:chown user myfile.txt17. chgrp:更改文件或目录的组。
示例:chgrp group myfile.txt18. tar:打包和解包文件。
示例:tar -cvf archive.tar myfile.txt19. gzip:压缩文件。
示例:gzip myfile.txt20. unzip:解压缩文件。
示例:unzip archive.zip21. ping:测试与远程主机的连接。
示例:ping google.com22. ifconfig:显示网络接口信息。
示例:ifconfig23. netstat:显示网络连接状态。
示例:netstat -tuln24. ssh:远程登录到另一台主机。
示例:ssh user@host25. scp:在本地主机和远程主机之间复制文件。
示例:scp myfile.txt user@host:/path/to/destination26. wget:下载文件。
示例:wget http://example.com/file.txt27. curl:发送HTTP请求和接收响应。
示例:curl http://example.com28. su:切换到其他用户。
示例:su user29. sudo:以管理员权限执行命令。
示例:sudo apt-get update30. apt-get:包管理器,用于安装、升级和删除软件包。
示例:apt-get install package31. yum:RHEL/CentOS的包管理器。
示例:yum install package32. dnf:Fedora的包管理器。
示例:dnf install package33. systemctl:管理系统服务。
示例:systemctl start service34. service:管理系统服务(旧版本)。
示例:service service start35. top:实时显示系统资源使用情况。
示例:top36. ps:显示当前运行的进程。
示例:ps -ef37. kill:终止进程。
示例:kill PID38. df:显示磁盘空间使用情况。
示例:df -h39. du:显示目录或文件的磁盘使用情况。
示例:du -sh /path/to/directory40. mount:挂载文件系统。
示例:mount /dev/sdb1 /mnt41. umount:卸载文件系统。
示例:umount /mnt42. ln:创建链接。
示例:ln -s /path/to/file linkname43. history:显示最近执行的命令。
示例:history44. date:显示日期和时间。
示例:date45. cal:显示日历。
示例:cal46. uname:显示系统信息。
示例:uname -a47. whoami:显示当前用户名。
示例:whoami48. passwd:更改用户密码。
示例:passwd49. useradd:创建新用户。
示例:useradd newuser50. userdel:删除用户。
示例:userdel user51. groupadd:创建新用户组。
示例:groupadd newgroup52. groupdel:删除用户组。
示例:groupdel group53. adduser:交互式创建用户。
示例:adduser newuser54. deluser:交互式删除用户。
示例:deluser user55. ifup:启动网络接口。
示例:ifup eth056. ifdown:停止网络接口。
示例:ifdown eth057. iptables:配置防火墙规则。
示例:iptables -A INPUT -p tcp –dport 22 -j ACCEPT58. sshd:SSH服务器配置文件。
示例:service sshd restart59. crontab:定时运行任务。
示例:crontab -e60. at:在指定时间运行一次任务。
示例:at 12:00 -f script.sh61. tar:打包和解包文件。
示例:tar -cvf archive.tar myfile.txt62. gzip:压缩文件。
示例:gzip myfile.txt63. unzip:解压缩文件。
示例:unzip archive.zip64. ssh-keygen:生成SSH密钥。
示例:ssh-keygen65. rsync:远程同步文件。
示例:rsync -avz source/ dest/66. yum:RHEL/CentOS的包管理器。
示例:yum install package67. dnf:Fedora的包管理器。
示例:dnf install package68. apt-get:包管理器,用于安装、升级和删除软件包。
示例:apt-get install package69. ps:显示当前运行的进程。
示例:ps -ef70. top:实时显示系统资源使用情况。
示例:top71. kill:终止进程。
示例:kill PID72. systemctl:管理系统服务。
示例:systemctl start service73. service:管理系统服务(旧版本)。
示例:service service start74. netstat:显示网络连接状态。
示例:netstat -tuln75. wget:下载文件。
示例:wget http://example.com/file.txt76. curl:发送HTTP请求和接收响应。
示例:curl http://example.com77. scp:在本地主机和远程主机之间复制文件。
示例:scp myfile.txt user@host:/path/to/destination78. tracert:跟踪数据包经过的路由路径(Windows)。
示例:tracert google.com79. nslookup:查询域名对应的IP地址。
示例:nslookup google.com80. host:查询域名对应的IP地址。
示例:host google.com81. dig:查询域名相关信息。
示例:dig google.com82. ifconfig:显示网络接口信息。
示例:ifconfig83. ping:测试与远程主机的连接。
示例:ping google.com84. route:显示和管理IP路由表。
示例:route -n85. hostname:显示或设置主机名。
示例:hostname86. ssh:远程登录到另一台主机。
示例:ssh user@host87. su:切换到其他用户。
示例:su user88. sudo:以管理员权限执行命令。
示例:sudo apt-get update89. which:显示可执行文件的路径。
示例:which ls90. uname:显示系统信息。
示例:uname -a91. df:显示磁盘空间使用情况。
示例:df -h92. du:显示目录或文件的磁盘使用情况。
示例:du -sh /path/to/directory93. mount:挂载文件系统。
示例:mount /dev/sdb1 /mnt94. umount:卸载文件系统。
示例:umount /mnt95. ln:创建链接。
示例:ln -s /path/to/file linkname96. grep:在文件中搜索指定的模式。
示例:grep “hello” myfile.txt97. sed:流式文本编辑器。
示例:sed ‘s/foo/bar/’ myfile.txt98. awk:处理文本文件。
示例:awk ‘{print $1}’ myfile.txt99. sort:对文本文件进行排序。
示例:sort myfile.txt100. cut:提取文本文件的指定字段。
示例:cut -d”,” -f1 myfile.csv101. join:在两个文件中基于共同字段进行匹配。
示例:join file1.txt file2.txt102. uniq:删除或仅显示文件中的重复行。
示例:uniq myfile.txt103. tar:打包和解包文件。
示例:tar -cvf archive.tar myfile.txt104. gzip:压缩文件。
示例:gzip myfile.txt105. unzip:解压缩文件。
示例:unzip archive.zip106. fg:将后台作业切换到前台。
示例:fg %jobid107. bg:将作业放在后台运行。
示例:bg %jobid108. jobs:列出当前作业。
示例:jobs109. nohup:在后台运行命令,并将输出重定向到文件。
示例:nohup command > output.log &110. screen:创建多个虚拟终端会话。
示例:screen111. clear:清屏。
示例:clear112. echo:显示文本。
示例:echo “Hello, world!”113. printf:格式化并显示文本。
示例:printf “Hello, %s!” name114. exit:退出当前Shell会话。
示例:exit115. break:在循环中退出。
示例:for i in 1 2 3; do if [ $i -eq 2 ]; then break; fi; echo $i; done116. continue:在循环中跳过当前迭代。
示例:for i in 1 2 3; do if [ $i -eq 2 ]; then continue; fi; echo $i; done117. return:从函数中返回值。
示例:return 0118. alias:创建命令别名。
示例:alias ll=’ls -l’119. source:在当前Shell会话中运行脚本。
示例:source script.sh120. script:记录和回放Shell会话。
示例:script session.log121. bash:Bourne Again Shell。
示例:bash script.sh122. sh:Bourne Shell。
示例:sh script.sh123. grep:在文件中搜索指定的模式。
示例:grep “hello” myfile.txt124. find:在文件系统中搜索文件。
示例:find / -name myfile.txt125. sed:流式文本编辑器。
示例:sed ‘s/foo/bar/’ myfile.txt126. awk:处理文本文件。
示例:awk ‘{print $1}’ myfile.txt127. sort:对文本文件进行排序。
示例:sort myfile.txt128. cut:提取文本文件的指定字段。
示例:cut -d”,” -f1 myfile.csv129. diff:比较两个文件的差异。
示例:diff file1.txt file2.txt130. patch:应用补丁到文件。
示例:patch -p1 < patch.diff131. xargs:将标准输入作为命令参数。 示例:find /path/to/directory -type f | xargs grep "pattern"132. tee:将标准输入写入文件和标准输出。 示例:command | tee output.txt133. nohup:在后台运行命令,并将输出重定向到文件。 示例:nohup command > output.log &134. crontab:定时运行任务。
示例:crontab -e135. at:在指定时间运行一次任务。
示例:at 12:00 -f script.sh136. watch:定期运行命令并显示结果。
示例:watch ls137. ssh-keygen:生成SSH密钥。
示例:ssh-keygen138. ssh-copy-id:复制SSH公钥到远程主机。
示例:ssh-copy-id user@host139. rsync:远程同步文件。
示例:rsync -avz source/ dest/140. scp:在本地主机和远程主机之间复制文件。
示例:scp myfile.txt user@host:/path/to/destination141. curl:发送HTTP请求和接收响应。
示例:curl http://example.com142. wget:下载文件。
示例:wget http://example.com/file.txt143. nc:网络工具,用于发送和接收数据。
示例:echo “hello” | nc host port144. telnet:与远程主机建立Telnet连接。
示例:telnet host port145. ftp:与远程主机建立FTP连接。
示例:ftp host146. sftp:与远程主机建立SSH FTP连接。
示例:sftp user@host147. lsof:列出打开的文件。
示例:lsof -i :port148. iostat:查看系统的输入输出统计信息。
示例:iostat149. vmstat:显示系统的虚拟内存统计信息。
示例:vmstat150. sar:系统活动报告。
示例:sar -u2年前 -
Linux是一种开源的操作系统,广泛应用于服务器、嵌入式设备等领域。Linux提供了许多基础命令,用于管理文件系统、进程、网络等。本文将列举150个常用的Linux基础命令,并对其用法做简要说明。
一、文件系统相关命令
1. cd:切换当前目录
示例:cd /home/user2. ls:列出当前目录下的文件和子目录
示例:ls -l3. pwd:显示当前工作目录的绝对路径
示例:pwd4. mkdir:创建新目录
示例:mkdir newdir5. rm:删除文件或目录
示例:rm file.txt6. cp:复制文件或目录
示例:cp file.txt newfile.txt7. mv:移动或重命名文件或目录
示例:mv oldname newname8. touch:创建新文件
示例:touch file.txt9. cat:将文件内容输出到终端
示例:cat file.txt10. echo:将指定内容输出到终端或文件
示例:echo “hello” > file.txt11. find:按指定条件搜索文件
示例:find /home -name “*.txt”12. grep:按指定模式搜索文件中的内容
示例:grep “pattern” file.txt13. head:显示文件的前几行
示例:head -n 10 file.txt14. tail:显示文件的后几行
示例:tail -n 10 file.txt15. chmod:修改文件权限
示例:chmod 755 file.txt16. chown:修改文件所有者
示例:chown user file.txt17. chgrp:修改文件所属组
示例:chgrp group file.txt二、系统管理命令
1. ps:查看当前运行的进程
示例:ps -ef2. top:实时监控系统资源使用情况
示例:top3. kill:终止指定进程
示例:kill -9 pid4. shutdown:关机或重启系统
示例:shutdown -h now5. reboot:重新启动系统
示例:reboot6. ifconfig:显示和配置网络接口信息
示例:ifconfig eth07. ping:测试网络连通性
示例:ping http://www.google.com8. netstat:显示网络相关信息
示例:netstat -an9. route:查看和配置网络路由表
示例:route -n10. uname:显示系统信息
示例:uname -a11. date:显示当前日期和时间
示例:date12. who:显示当前登录的用户信息
示例:who13. df:查看文件系统使用情况
示例:df -h14. du:计算文件或目录的磁盘空间使用量
示例:du -sh /path/to/directory15. free:显示内存使用情况
示例:free -m三、压缩与解压命令
1. tar:打包和解包文件
示例:tar -cvf archive.tar file1 file2
tar -xvf archive.tar2. gzip:压缩文件
示例:gzip file.txt3. gunzip:解压缩文件
示例:gunzip file.txt.gz4. zip:压缩文件和目录
示例:zip archive.zip file1 file2
zip -r archive.zip directory5. unzip:解压缩zip文件
示例:unzip archive.zip四、用户与权限管理命令
1. useradd:创建新用户
示例:useradd newuser2. passwd:设置用户密码
示例:passwd newuser3. userdel:删除用户
示例:userdel olduser4. groupadd:创建新组
示例:groupadd newgroup5. groupdel:删除组
示例:groupdel oldgroup6. su:切换用户
示例:su – anotheruser7. sudo:以管理员权限执行命令
示例:sudo command8. visudo:编辑sudoers文件
示例:visudo9. chage:修改用户密码过期规则
示例:chage -M 90 user10. id:显示用户和组的身份信息
示例:id user五、网络相关命令
1. ssh:远程登录到另一台计算机
示例:ssh user@hostname2. scp:在本地和远程计算机间拷贝文件
示例:scp file.txt user@hostname:/path/to/destination3. ftp:使用FTP协议从远程计算机拷贝文件
示例:ftp hostname
get file.txt4. wget:从网络下载文件
示例:wget https://example.com/file.txt5. curl:从网络获取数据
示例:curl https://example.com/api/data6. ifup:启动网络接口
示例:ifup eth07. ifdown:关闭网络接口
示例:ifdown eth0六、软件包管理命令
1. apt-get:Debian和Ubuntu系统的软件包管理工具
示例:apt-get install package2. yum:Red Hat和CentOS系统的软件包管理工具
示例:yum install package3. pacman:Arch Linux系统的软件包管理工具
示例:pacman -S package4. dpkg:Debian系统的软件包管理工具
示例:dpkg -i package.deb5. rpm:Red Hat系统的软件包管理工具
示例:rpm -i package.rpm七、其他常用命令
1. ln:创建链接文件
示例:ln -s /path/to/file link2. history:显示历史命令
示例:history3. alias:为命令设置别名
示例:alias ll=’ls -l’4. clear:清屏
示例:clear5. tar:打包和解包文件
示例:tar -cvf archive.tar file1 file2
tar -xvf archive.tar以上是150个常用的Linux基础命令及其用法的简要说明。掌握这些命令能够帮助用户更好地管理和操作Linux系统。
2年前