Linux系统100条命令:关于Ubuntu和 CentOS 7 相同功能的不同的终端操作命令

在这里插入图片描述

  1. 安装软件包:

Ubuntu:apt-get install package_name
CentOS 7:yum install package_name

  1. 更新软件包列表:

Ubuntu:apt-get update
CentOS 7:yum update

  1. 卸载软件包:

Ubuntu:apt-get remove package_name
CentOS 7:yum remove package_name

  1. 查找文件:

Ubuntu:find /path/to/search -name “filename”
CentOS 7:find /path/to/search -name “filename”

  1. 显示系统信息:

Ubuntu:lsb_release -a
CentOS 7:cat /etc/centos-release

  1. 查看网络接口信息:

Ubuntu:ifconfig
CentOS 7:ip addr

  1. 启动服务:

Ubuntu:systemctl start service_name
CentOS 7:systemctl start service_name

  1. 停止服务:

Ubuntu:systemctl stop service_name
CentOS 7:systemctl stop service_name

  1. 重新启动服务:

Ubuntu:systemctl restart service_name
CentOS 7:systemctl restart service_name

  1. 查看服务状态:

Ubuntu:systemctl status service_name
CentOS 7:systemctl status service_name

  1. 启用服务(开机自启动):

Ubuntu:systemctl enable service_name
CentOS 7:systemctl enable service_name

  1. 禁用服务(开机不自启动):

Ubuntu:systemctl disable service_name
CentOS 7:systemctl disable service_name

  1. 防火墙规则操作:

Ubuntu:ufw allow port_number
CentOS 7:firewall-cmd --zone=public --add-port=port_number/tcp --permanent

  1. 用户管理 - 创建用户:

Ubuntu:adduser username
CentOS 7:useradd username

  1. 用户管理 - 修改密码:

Ubuntu:passwd username
CentOS 7:passwd username

  1. 用户管理 - 删除用户:

Ubuntu:deluser username
CentOS 7:userdel username

  1. 用户管理 - 用户组管理:

Ubuntu:addgroup groupname
CentOS 7:groupadd groupname

  1. 用户管理 - 用户属性修改:

Ubuntu:usermod -aG groupname username
CentOS 7:usermod -aG groupname username

  1. 显示磁盘空间使用情况:

Ubuntu:df -h
CentOS 7:df -h

  1. 显示内存使用情况:

Ubuntu:free -m
CentOS 7:free -m

  1. 显示系统日历:

Ubuntu:cal
CentOS 7:cal
22. 查看系统运行时间和平均负载:

Ubuntu:uptime
CentOS 7:uptime
23. 显示当前登录用户列表:

Ubuntu:who
CentOS 7:who
24. 显示系统启动日志:

Ubuntu:journalctl -b
CentOS 7:journalctl -b
25. 查看系统日志:

Ubuntu:less /var/log/syslog
CentOS 7:less /var/log/messages
26. 显示系统主机名:

Ubuntu:hostname
CentOS 7:hostname
27. 显示文件和目录的权限:

Ubuntu:ls -l file_or_directory
CentOS 7:ls -l file_or_directory
28. 创建目录:

Ubuntu:mkdir directory_name
CentOS 7:mkdir directory_name
29. 删除目录:

Ubuntu:rmdir directory_name
CentOS 7:rmdir directory_name
30. 创建空文件:

Ubuntu:touch filename.txt
CentOS 7:touch filename.txt
31. 复制文件或目录:

Ubuntu:cp source destination
CentOS 7:cp source destination
32. 移动文件或目录:

Ubuntu:mv source destination
CentOS 7:mv source destination
33. 删除文件或目录:

Ubuntu:rm file_or_directory
CentOS 7:rm file_or_directory
34. 查看文件内容:

Ubuntu:cat filename.txt
CentOS 7:cat filename.txt
35. 逐页查看文件内容:

Ubuntu:less filename.txt
CentOS 7:less filename.txt
36. 查看文件的前几行:

Ubuntu:head filename.txt
CentOS 7:head filename.txt
37. 查看文件的最后几行:

Ubuntu:tail filename.txt
CentOS 7:tail filename.txt
38. 在文件中搜索文本:

Ubuntu:grep “pattern” filename.txt
CentOS 7:grep “pattern” filename.txt
39. 测试与远程主机的网络连接:

Ubuntu:ping hostname_or_ip
CentOS 7:ping hostname_or_ip
40. 显示网络接口配置信息:

Ubuntu:ifconfig
CentOS 7:ip addr

  1. 显示进程信息:

Ubuntu:ps aux
CentOS 7:ps aux
42. 终止进程:

Ubuntu:kill process_id
CentOS 7:kill process_id
43. 显示当前用户信息:

Ubuntu:id
CentOS 7:id
44. 创建软链接:

Ubuntu:ln -s source_file link_name
CentOS 7:ln -s source_file link_name
45. 显示系统内核版本:

Ubuntu:uname -r
CentOS 7:uname -r
46. 显示可用磁盘空间:

Ubuntu:df -h
CentOS 7:df -h
47. 显示可用内存和交换空间:

Ubuntu:free -m
CentOS 7:free -m
48. 显示系统进程的内存使用情况:

Ubuntu:ps aux --sort -%mem
CentOS 7:ps aux --sort -%mem
49. 显示系统进程的CPU使用情况:

Ubuntu:ps aux --sort -%cpu
CentOS 7:ps aux --sort -%cpu
50. 显示系统当前时间:

Ubuntu:date
CentOS 7:date
51. 显示日历:

Ubuntu:cal
CentOS 7:cal
52. 显示系统的启动时间:

Ubuntu:systemctl show -p ActiveEnterTimestamp --value
CentOS 7:systemd-analyze
53. 显示系统中的硬件信息:

Ubuntu:lshw
CentOS 7:lshw
54. 显示可用网络接口:

Ubuntu:ip link show
CentOS 7:ip link show
55. 显示系统中的PCI设备:

Ubuntu:lspci
CentOS 7:lspci
56. 显示系统中的USB设备:

Ubuntu:lsusb
CentOS 7:lsusb
57. 显示系统中的SCSI设备:

Ubuntu:lsscsi
CentOS 7:lsscsi
58. 显示系统中的CPU信息:

Ubuntu:lscpu
CentOS 7:lscpu
59. 显示系统中的内存信息:

Ubuntu:lsmem
CentOS 7:lsmem
60. 显示系统中的文件系统信息:

Ubuntu:df -T
CentOS 7:df -T

  1. 查看系统运行的进程和资源使用情况:

Ubuntu:htop
CentOS 7:top
62. 定时执行任务(cron):

Ubuntu:crontab -e
CentOS 7:crontab -e
63. 显示系统主机名:

Ubuntu:hostname
CentOS 7:hostname
64. 查看系统中已安装的软件包:

Ubuntu:dpkg --list
CentOS 7:rpm -qa
65. 显示系统环境变量:

Ubuntu:printenv
CentOS 7:env
66. 显示系统日志文件:

Ubuntu:cat /var/log/syslog
CentOS 7:cat /var/log/messages
67. 显示网络路由表:

Ubuntu:ip route
CentOS 7:route -n
68. 显示系统硬盘分区信息:

Ubuntu:lsblk
CentOS 7:fdisk -l
69. 创建压缩文件(tar):

Ubuntu:tar -czvf archive.tar.gz /path/to/directory
CentOS 7:tar -czvf archive.tar.gz /path/to/directory
70. 解压缩文件(tar):

Ubuntu:tar -xzvf archive.tar.gz
CentOS 7:tar -xzvf archive.tar.gz
71. 安装软件包(snap):

Ubuntu:snap install package_name
CentOS 7:Snap 不是 CentOS 7 默认支持的包管理器。
72. 切换用户:

Ubuntu:su username
CentOS 7:su username
73. 切换用户并保留环境变量:

Ubuntu:su - username
CentOS 7:su - username
74. 显示系统内核模块:

Ubuntu:lsmod
CentOS 7:lsmod
75. 列出已安装的文件包及其信息:

Ubuntu:dpkg -l
CentOS 7:rpm -qa
76. 设置静态IP地址(命令行方式):

Ubuntu:编辑 /etc/network/interfaces 文件
CentOS 7:编辑 /etc/sysconfig/network-scripts/ifcfg-eth0 文件
77. 启用和禁用网络接口:

Ubuntu:ifconfig interface_name up 或 ifconfig interface_name down
CentOS 7:ip link set interface_name up 或 ip link set interface_name down
78. 显示用户登陆历史记录:

Ubuntu:last
CentOS 7:last
79. 显示系统开机时间:

Ubuntu:uptime -s
CentOS 7:uptime -s
80. 显示系统CPU信息(详细):

Ubuntu:lscpu
CentOS 7:lscpu

  1. 查看系统的DNS配置:

Ubuntu:cat /etc/resolv.conf
CentOS 7:cat /etc/resolv.conf
82. 显示系统时间同步状态:

Ubuntu:timedatectl status
CentOS 7:timedatectl status
83. 显示系统开机启动服务:

Ubuntu:systemctl list-unit-files | grep enabled
CentOS 7:systemctl list-unit-files | grep enabled
84. 显示系统环境变量的值:

Ubuntu:echo $VAR_NAME
CentOS 7:echo $VAR_NAME
85. 显示当前用户的家目录:

Ubuntu:echo $HOME
CentOS 7:echo $HOME
86. 显示系统启动的进程:

Ubuntu:systemctl list-units --type=service
CentOS 7:systemctl list-units --type=service
87. 显示已安装的内核包列表:

Ubuntu:dpkg -l | grep linux-image
CentOS 7:rpm -qa | grep kernel
88. 显示系统的默认编辑器:

Ubuntu:update-alternatives --display editor
CentOS 7:alternatives --display editor
89. 显示当前登录用户的组:

Ubuntu:groups
CentOS 7:groups
90. 显示系统启动时运行的脚本(系统d服务):

Ubuntu:systemctl list-dependencies multi-user.target
CentOS 7:systemctl list-dependencies multi-user.target
91. 显示文件的inode号:

Ubuntu:ls -i filename
CentOS 7:ls -i filename
92. 显示系统开机启动的级别:

Ubuntu:runlevel
CentOS 7:systemctl get-default
93. 显示系统内核参数:

Ubuntu:sysctl -a
CentOS 7:sysctl -a
94. 显示已加载的内核模块:

Ubuntu:lsmod
CentOS 7:lsmod
95. 显示用户账户的详细信息:

Ubuntu:finger username
CentOS 7:finger username
96. 显示系统的电源状态:

Ubuntu:upower -i /org/freedesktop/UPower/devices/battery_BAT0
CentOS 7:cat /sys/class/power_supply/BAT0/status
97. 显示系统的默认编辑器:

Ubuntu:update-alternatives --config editor
CentOS 7:alternatives --config editor
98. 显示系统中的网络连接:

Ubuntu:ss -tuln
CentOS 7:netstat -tuln
99. 显示系统中的CPU负载:

Ubuntu:cat /proc/loadavg
CentOS 7:cat /proc/loadavg
100. 显示系统的启动日志:

Ubuntu:journalctl -b
CentOS 7:journalctl -b

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

源代码杀手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值