首页 Linux教程linux命令

linux shell介绍

linux帮助

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

常见命令

查看硬件信息
查看cpu

lscpu命令可以查看cpu信息

cat /proc/cpuinfo也可看查看到

范例:

[root@centos8 ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1 #每个core 有几个线程
Core(s) per socket:    4 #每个槽位有4个core 
Socket(s):             2 #服务器面板上有2个cpu 槽位
NUMA node(s):          2 #nodes的数量
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 44
Stepping:              2
CPU MHz:               2128.025
BogoMIPS:              4256.03
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K
NUMA node0 CPU(s):     0,2,4,6 #对应的core
NUMA node1 CPU(s):     1,3,5,7

[root@centos8 ~]# cat /proc/cpuinfo
查看内存大小
[root@centos8 ~]#free
              total        used        free      shared  buff/cache   available
Mem:         816188      156888      412660        5792      246640      527024
Swap:       2097148           0     2097148
[root@centos8 ~]#cat /proc/meminfo 
MemTotal:         816188 kB
MemFree:          412780 kB
MemAvailable:     527144 kB
Buffers:            5304 kB
Cached:           208252 kB
SwapCached:            0 kB
Active:           138976 kB
Inactive:         127508 kB
Active(anon):      53348 kB
Inactive(anon):     5368 kB
Active(file):      85628 kB
Inactive(file):   122140 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         52964 kB
Mapped:            78456 kB
Shmem:              5792 kB
KReclaimable:      33084 kB
Slab:              69144 kB
SReclaimable:      33084 kB
SUnreclaim:        36060 kB
KernelStack:        4428 kB
PageTables:         5888 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2505240 kB
Committed_AS:     250040 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:      6144 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      108416 kB
DirectMap2M:      940032 kB
DirectMap1G:           0 kB
[root@centos8 ~]#
查看硬盘和分区情况
[root@centos8 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1    7G  0 rom  
[root@centos8 ~]#cat /proc/partitions 
major minor  #blocks  name

   8        0  209715200 sda
   8        1    1048576 sda1
   8        2  104857600 sda2
   8        3   52428800 sda3
   8        4          1 sda4
   8        5    2097152 sda5
  11        0    7377920 sr0
查看系统版本信息
查看内核版本
[root@centos8 ~]#uname -r
4.18.0-147.el8.x86_64

[root@centos7 ~]#uname -r
3.10.0-1062.el7.x86_64

[root@centos6 ~]# uname -r
2.6.32-754.el6.x86_64

[root@ubuntu1804 ~]#uname -r
4.15.0-29-generic
查看操作系统发行版本
#CentOS8 查看发行版本
[root@centos8 ~]#cat /etc/redhat-release 
CentOS Linux release 8.1.1911 (Core) 
[root@centos8 ~]#cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

[root@centos8 ~]#lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 8.1.1911 (Core) 
Release:    8.1.1911
Codename:   Core
[root@centos8 ~]#

#ubuntu查看发行版本
[root@ubuntu1804 ~]#cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
[root@ubuntu1804 ~]#cat /etc/is
iscsi/     issue      issue.net  
[root@ubuntu1804 ~]#cat /etc/is
iscsi/     issue      issue.net  
[root@ubuntu1804 ~]#cat /etc/issue
Ubuntu 18.04.1 LTS \n \l

[root@ubuntu1804 ~]#lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:    18.04
Codename:   bionic
[root@ubuntu1804 ~]#
日期和时间

Linux的两种时钟
系统时钟:由Linux内核通过CPU的工作频率进行的
硬件时钟:主板

相关命令

  • date 显示和设置系统时间

    范例:

    [root@centos8 ~]#date +%s
    1584689051
    [root@centos8 ~]#date -d @date +%s
    Fri Mar 20 15:24:18 CST 2020
    
    [root@centos8 ~]#date -d @1584689051
    Fri Mar 20 15:24:11 CST 2020
    
    [root@centos8 ~]#date -d @1584689051 +%F_%T
    2020-03-20_15:24:11
  • clock,hwclock: 显示硬件时钟
    -s, –hctosys 以硬件时钟为准,校正系统时钟
    -w, –systohc 以系统时钟为准,校正硬件时钟

时区:

/etc/localtime

范例:

[root@centos8 ~]#timedatectl set-timezone Asia/Shanghai

[root@centos8 ~]#ll /etc/localtime 
lrwxrwxrwx. 1 root root 35 Dec 11 11:19 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

root@ubuntu1804:~# cat /etc/timezone 
Asia/Shanghai

显示日历:

cal –y 

范例:

[16:47:36 root@centos8 ~]#cal 9 1752
   September 1752   
Su Mo Tu We Th Fr Sa
       1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30                    
关机和重启

关机:

  • halt
  • poweroff

重启:

​ reboot
​ -f: 强制,不调用shutdown
​ -p: 切断电源

关机或重启:shutdown

shutdown [OPTION]...  [TIME] [MESSAGE]

​ -r: reboot
​ -h: halt
​ -c:cancel
​ TIME:无指定,默认相当于+1(CentOS7)
​ now: 立刻,相当于+0
​ +#: 相对时间表示法,几分钟之后;例如 +3
​ hh:mm: 绝对时间表示,指明具体时间

用户登录信息查看命令
  • whoami: 显示当前登录有效用户
  • who: 系统当前所有的登录会话
  • w: 系统当前所有的登录会话及所做的操作

本文链接:https://www.yunweipai.com/33855.html

linux shell介绍

linux帮助

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

暂无评论

Copyright © 2012-2022 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部