centos

CentOS常用命令大全

小樊
34
2025-07-10 21:04:16
栏目: 智能运维

CentOS是一个基于Red Hat Enterprise Linux(RHEL)源代码的开源Linux发行版。以下是一些在CentOS系统中常用的命令:

基本命令

  1. ls - 列出目录内容

    ls -l # 以长格式显示
    ls -a # 显示所有文件,包括隐藏文件
    
  2. cd - 更改当前目录

    cd /path/to/directory # 进入指定目录
    cd ~ # 返回用户主目录
    cd - # 返回上一个目录
    
  3. pwd - 显示当前工作目录

    pwd
    
  4. cp - 复制文件或目录

    cp source destination # 复制文件
    cp -r source destination # 递归复制目录
    
  5. mv - 移动或重命名文件或目录

    mv oldname newname # 重命名文件
    mv file directory/ # 移动文件到目录
    
  6. rm - 删除文件或目录

    rm file # 删除文件
    rm -r directory # 递归删除目录
    
  7. mkdir - 创建新目录

    mkdir directory
    
  8. rmdir - 删除空目录

    rmdir directory
    
  9. touch - 创建空文件或更新文件时间戳

    touch file
    
  10. cat - 显示文件内容

    cat file
    
  11. more / less - 分页显示文件内容

    more file
    less file
    
  12. head - 显示文件开头内容

    head file
    
  13. tail - 显示文件结尾内容

    tail file
    tail -f file # 实时跟踪文件更新
    
  14. grep - 在文件中搜索文本

    grep "text" file
    
  15. find - 在目录中查找文件

    find /path/to/search -name filename
    
  16. chmod - 更改文件权限

    chmod 755 file
    
  17. chown - 更改文件所有者

    chown user:group file
    
  18. df - 显示磁盘空间使用情况

    df -h # 以人类可读的格式显示
    
  19. du - 显示目录空间使用情况

    du -sh directory # 显示目录总大小
    
  20. ps - 显示当前进程状态

    ps aux # 显示所有进程的详细信息
    
  21. top - 实时显示系统进程和资源使用情况

    top
    
  22. kill - 终止进程

    kill PID # 终止指定PID的进程
    kill -9 PID # 强制终止进程
    
  23. tar - 打包和解包文件

    tar -czvf archive.tar.gz directory # 打包目录
    tar -xzvf archive.tar.gz # 解包文件
    
  24. wget - 从网络下载文件

    wget http://example.com/file
    
  25. curl - 用于传输数据

    curl http://example.com
    

系统管理命令

  1. yum / dnf - 包管理器

    yum update # 更新所有包
    yum install package # 安装包
    dnf install package # 使用DNF安装包(CentOS 8+)
    
  2. systemctl - 系统和服务管理

    systemctl start service # 启动服务
    systemctl stop service # 停止服务
    systemctl restart service # 重启服务
    systemctl enable service # 设置开机自启
    systemctl disable service # 禁用开机自启
    
  3. firewall-cmd - 防火墙管理(CentOS 7+)

    firewall-cmd --list-all # 列出所有防火墙规则
    firewall-cmd --add-service=http --permanent # 添加HTTP服务
    firewall-cmd --reload # 重新加载防火墙配置
    
  4. hostnamectl - 主机名管理(CentOS 8+)

    hostnamectl set-hostname new-hostname
    
  5. timedatectl - 时间和日期管理

    timedatectl set-timezone Asia/Shanghai # 设置时区
    timedatectl status # 查看时间同步状态
    
  6. useradd / usermod - 用户管理

    useradd username # 添加用户
    usermod -aG group username # 将用户添加到组
    
  7. passwd - 更改用户密码

    passwd username
    
  8. groupadd / groupmod - 组管理

    groupadd groupname
    groupmod -n newgroupname groupname
    
  9. crontab - 定时任务管理

    crontab -e # 编辑当前用户的定时任务
    
  10. ssh - 安全外壳协议(SSH)

    ssh user@host # 连接到远程主机
    

这些命令是CentOS系统管理和日常操作中非常常用的。当然,CentOS还有许多其他命令和工具,具体使用可以根据实际需求进行查询和学习。

0
看了该问题的人还看了