美文网首页
CentOS 常规操作

CentOS 常规操作

作者: saronic | 来源:发表于2018-01-28 09:51 被阅读6次

    查看命令

    # uname -sr //查看内核版本
    # cat /etc/redhat-release //查看centos发行版版本
    $ps -el |grep ssh //查看进程,比如查看 ssh 是否在运行
    free -h //查看内存
    df -h // 查看硬盘使用
    du -sh //查看目录总的占用大小
    du -sh /path/* /path 下所有文件和文件夹分别占用的容量大小
    cat /proc/cpuinfo //查看 cpu 信息

    grep

    grep 'abc' sth.txt 从 sth.txt 中查找包含 abc 的行。abc的单引号不是必须的
    -i //不区分大小写
    -v // 取反
    -n //显示行号
    -A2 -B1 // 把目标行的 before 1 和 after 2 都显示。如果只写一个数字,比如-2,会把前后2行都显示
    -R // grep -R 'root' /etc 递归查找 /etc下所有的文件,显示包含 root 的行

    find

    find /etc -name "*conf*" 单引号可以省略
    find /etc -name *th0 -type f // -f file; -d directory

    wc

    wc -l filename // 统计filename的行数

    su

    su - username

    查看系统负载

    w 显示最近 1 分钟,5 分钟, 15 分钟的负载,一般负载低于0.6或者0.7是正常的。
    top 查看占用系统资源多的进程

    查看端口开放情况

    ss -lntp4 l:listening n: 端口显示为数字 p:显示进程名
    sudo lsof -i 4 -P -n: lsof本来是显示打开的文件,-i 4显示IPv4,-n:no hostname, -P:no port name。我觉的这个命令显示的更清楚

    yum 操作

    yum update //centos 升级
    yum install epel-release //安装 epel
    yum list 查看可以安装的package
    yum install package-name 安装
    yum erase package-name 卸载
    yum search xxx 在 repo 中搜索名字和summary中包含 xxx 的包,模糊搜索

    文件操作

    tail -f //动态显示文件末尾
    grep -n "11" test.txt //在 test.txt 中查找关键字 “11”,-n 表示显示关键字所在的行号
    cat test.txt | wc -l //显示 test.txt 一共有多少行
    find /etc/ -name "?ysconfig"
    find . -type f //f: file; d:directory
    find . -type f -exec ls -l {} \; //查找当前目录的文件,并显示详细信息,参考菜鸟教程,注意不同 linux 发行版,此命令格式稍有不同

    bash 操作

    自动补全 auto completion

    centos 7 最小化安装,装完默认的自动补全功能很少,比如 "sudo yum inst",这是 tab 键不能自动补全。需要下面命令
    # yum install bash-completion bash-completion-extras
    source /etc/profile.d/bash_completion.sh //运行此命令,或者 logout & login again.

    tar

    tar -cf target.tar source.c sourc.h //把 source.c 和 source.h 压缩到 target.tar 中
    tar -czvf target.tar.gz source.c //压缩成 gzip 格式
    tar -xzvf target.tar.gz //解压 gzip

    user 操作

    userdel -r username //连同 username 在 home 目录里的文件夹一起删除

    相关文章

      网友评论

          本文标题:CentOS 常规操作

          本文链接:https://www.haomeiwen.com/subject/azsaaxtx.html