工作中常用的Linux命令

作者: 消失黎明 | 来源:发表于2019-05-30 14:57 被阅读99次

    一、linux CPU大小

    cat /proc/cpuinfo |grep "model name" && cat /proc/cpuinfo |grep "physical id"

    dp_user@rqalnxg*:/sapmnt/HOME/****/dpagent_193> cat /proc/cpuinfo |grep "model name" && cat /proc/cpuinfo |grep "physical id"
    model name      : Intel(R) Xeon(R) CPU           X5650  @ 2.67GHz
    model name      : Intel(R) Xeon(R) CPU           X5650  @ 2.67GHz
    physical id     : 1
    physical id     : 0
    

    说明:Linux下可以在/proc/cpuinfo中看到每个cpu的详细信息。但是对于双核的cpu,在cpuinfo中会看到两个cpu。常常会让人误以为是两个单核的cpu。
    其实应该通过Physical Processor ID来区分单核和双核。而Physical Processor ID可以从cpuinfo或者dmesg中找到. flags 如果有 ht 说明支持超线程技术 判断物理CPU的个数可以查看physical id 的值,相同则为

    二、内存大小

    cat /proc/meminfo | grep MemTotal

    dp_user@rqalnxgr*:/sapmnt/HOME/i***/dpagent_193> cat /proc/meminfo | grep MemTotal
    MemTotal:       49266728 kB
    

    三、硬盘大小

    df -h

    dp_user@rqalnxgr*:/sapmnt/HOME/i**97/dpagent_193> df -h
    Filesystem                                 Size  Used Avail Use% Mounted on
    devtmpfs                                    24G  8.0K   24G   1% /dev
    tmpfs                                       51G   76K   51G   1% /dev/shm
    tmpfs                                       24G  194M   24G   1% /run
    tmpfs                                       24G     0   24G   0% /sys/fs/cgroup
    /dev/mapper/vg00-lv_root                   254G  124G  129G  50% /
    /dev/sdc1                                  979M   99M  814M  11% /boot
    ns01vs012.pal.sap.corp:/vol/vol_eiminfra1   26T   17T  9.9T  63% /pal/eiminfra1
    ns01vs012.pal.sap.corp:/vol/vol_eiminfra2   26T   16T   11T  60% /pal/eiminfra2
    

    四、 查看内核/操作系统/CPU信息的linux系统信息命令

    uname -a

    dp_user@rqalnxg*:/sapmnt/HOME/i3**7/dpagent_193> uname -a
    Linux rqalnxgrid4 4.4.120-92.70-default #1 SMP Wed Mar 14 15:59:43 UTC 2018 (52a83de) x86_64 x86_64 x86_64 GNU/Linux
    

    五、查看操作系统版本

    Note:是数字1不是字母L
    head -n 1 /etc/issue

    f0da8fee192d:/ # head -n 1 /etc/issue
    Welcome to openSUSE Leap 42.3 - Kernel \r (\l).
    

    或者也可以执行lsb_release -a

    dp_user@rqalnx*:/usr/sap/wwpTools> lsb_release -a
    LSB Version:    n/a
    Distributor ID: SUSE
    Description:    SUSE Linux Enterprise Server 12 SP2
    Release:        12.2
    Codename:       n/a
    

    六、查看CPU信息的linux系统信息命令

    cat /proc/cpuinfo

    dp_user@rqalnxg*:/usr/sap/wwpTools> cat /proc/cpuinfo
    processor       : 0
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 44
    model name      : Intel(R) Xeon(R) CPU           X5650  @ 2.67GHz
    stepping        : 2
    microcode       : 0x10
    cpu MHz         : 2660.098
    cache size      : 12288 KB
    ...
    

    七、查看计算机名的linux系统信息命令

    dp_user@rqalnxg*:/usr/sap/wwpTools> hostname
    rqalnxgrid4
    

    八、列出所有PCI设备

    lspci -tv

    dp_user@rqalnxgr***:/usr/sap/wwpTools> lspci -tv
    Absolute path to 'lspci' is '/sbin/lspci', so running it may require superuser privileges (eg. root).
    dp_user@rqalnxgr***:/usr/sap/wwpTools> /sbin/lspci -tv
    -+-[0000:ff]-+-00.0  Intel Corporation Xeon 5600 Series QuickPath Architecture Generic Non-core Registers
     |           +-00.1  Intel Corporation Xeon 5600 Series QuickPath Architecture System Address Decoder
     |           +-02.0  Intel Corporation Xeon 5600 Series QPI Link 0
     |           +-02.1  Intel Corporation Xeon 5600 Series QPI Physical 0
     |           +-02.2  Intel Corporation Xeon 5600 Series Mirror Port Link 0
    

    九、列出所有USB设备的linux系统信息命令

    lsusb -tv

    dp_user@rqalnxg**:/usr/sap/wwpTools> lsusb -tv
    /:  Bus 07.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
    /:  Bus 06.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
        |__ Port 2: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 2: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
    /:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
        |__ Port 2: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
    ...
    

    十、列出加载的内核模块

    lsmod

    dp_user@rqalnxg***:/usr/sap/wwpTools> lsmod
    Module                  Size  Used by
    nfsv3                  45056  0
    nfs_acl                16384  1 nfsv3
    rpcsec_gss_krb5        36864  0
    auth_rpcgss            65536  1 rpcsec_gss_krb5
    nfsv4                 528384  1
    dns_resolver           16384  1 nfsv4
    nfs                   274432  4 nfsv3,nfsv4
    lockd                  98304  2 nfs,nfsv3
    ...
    

    十一、查看环境变量资源

    env

    dp_user@rqalnxg***:/usr/sap/wwpTools> env
    LESSKEY=/etc/lesskey.bin
    NNTPSERVER=news
    MANPATH=/usr/local/man:/usr/share/man
    VIRTUALENVWRAPPER_SCRIPT=/home/dp_user/.local/bin/virtualenvwrapper.sh
    VIRTUALENVWRAPPER_PROJECT_FILENAME=.project
    HOSTNAME=rqalnxgrid4
    XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
    HOST=rqalnxgrid4
    TERM=xterm
    SHELL=/bin/bash
    ...
    

    十二、查看内存使用量和交换区使用量

    free -m

    dp_user@rqalnxgrid4:/usr/sap/wwpTools> free -m
                 total       used       free     shared    buffers     cached
    Mem:         48112      40909       7202        181        345      37191
    -/+ buffers/cache:       3372      44739
    Swap:        20480        144      20336
    

    下面就不一一演示了

    十四、du -sh # 查看指定目录的大小
    十五、grep MemTotal /proc/meminfo # 查看内存总量
    十六、grep MemFree /proc/meminfo # 查看空闲内存量
    十七、uptime # 查看系统运行时间、用户数、负载
    十八、cat /proc/loadavg # 查看系统负载磁盘和分区
    十九、mount | column -t # 查看挂接的分区状态
    二十、fdisk -l # 查看所有分区
    二十一、swapon -s # 查看所有交换分区
    二十二、hdparm -i /dev/hda # 查看磁盘参数(仅适用于IDE设备)
    二十三、dmesg | grep IDE # 查看启动时IDE设备检测状况网络
    二十四、ifconfig # 查看所有网络接口的属性
    二十五、iptables -L # 查看防火墙设置
    二十六、route -n # 查看路由表
    二十七、netstat -lntp # 查看所有监听端口
    二十八、netstat -antp # 查看所有已经建立的连接
    二十九、netstat -s # 查看网络统计信息进程
    三十、ps -ef # 查看所有进程
    三十一、top # 实时显示进程状态用户
    三十二、w # 查看活动用户
    三十三、id # 查看指定用户信息
    三十四、last # 查看用户登录日志
    三十五、cut -d: -f1 /etc/passwd # 查看系统所有用户
    三十六、cut -d: -f1 /etc/group # 查看系统所有组
    三十七、crontab -l # 查看当前用户的计划任务服务
    三十七、chkconfig –list # 列出所有系统服务
    三十八、chkconfig –list | grep on # 列出所有启动的系统服务程序
    三十九、rpm -qa # 查看所有安装的软件包
    四十、cat /proc/cpuinfo :查看CPU相关参数的linux系统命令
    四十一、cat /proc/partitions :查看linux硬盘和分区信息的系统信息命令
    四十二、cat /proc/meminfo :查看linux系统内存信息的linux系统命令
    四十三、cat /proc/version :查看版本,类似uname -r
    四十四、cat /proc/ioports :查看设备io端口
    四十五、cat /proc/interrupts :查看中断
    四十六、cat /proc/pci :查看pci设备的信息
    四十七、cat /proc/swaps :查看所有swap分区的信息

    相关文章

      网友评论

        本文标题:工作中常用的Linux命令

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