查看主机名
[root@centos7 ~]#hostname
centos7.localdomain
查看内核版本
[root@centos7 ~]#uname -r
3.10.0-1062.el7.x86_64
查看操作系统的版本信息(只支持redhat系列的操作系统 不支持ubantu)
[root@centos7 ~]#cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
列出CPU
[root@centos7 ~]#lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 2
显示当前系统版本信息
[root@centos7 ~]#lsb_release -a
找到存放bc的文件夹路径
[root@centos7 ~]#which bc
/usr/bin/bc
查看当前主机IP地址
[root@centos7 ~]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:99:78:21 brd ff:ff:ff:ff:ff:ff
inet 192.168.16.137/24 brd 192.168.16.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe99:7821/64 scope link
valid_lft forever preferred_lft forever
查看内存
[root@centos7 ~]#free
total used free shared buff/cache available
Mem: 1475008 189252 1127868 10576 157888 1133252
Swap: 3145724 0 3145724
在linux里判断一个用户是管理员还是普通用户 看id id为0就是管理员用户 id为1000为普通用户
[root@centos7 ~]#id #默认查看当前用户id
uid=0(root) gid=0(root) groups=0(root)
[root@centos7 ~]#id wang #查看王用户id
uid=1000(wang) gid=1000(wang) groups=1000(wang)
whereis显示详细的文件路径和man帮助路径
[root@centos8 ~]# whereis date
date: /usr/bin/date /usr/share/man/man1/date.1.gz /usr/share/man/man1p/date.1p.gz
which显示外部命令所在的磁盘路径
[root@centos8 ~]# which date
/usr/bin/date
显示当前时间 格式为2020-02-05
[root@centos8 ~]# date +"%F %T"
2020-02-05 15:35:16
显示今天是星期几
[root@centos8 ~]# date +%w
3
显示前天星期几
[root@centos8 ~]# date -d '-2 day' +%u
1
设置当前日期为2020年2月5日15时43分10秒
date 月日时分年秒
[root@centos8 ~]# date 020515432020.10
Wed Feb 5 15:43:10 CST 2020
参考硬件时间修正错误的系统时间
[root@centos8 ~]# clock -s
查看当前多支持的时区所有列表
[root@centos8 ~]# timedatectl list-timezones
查看当前操作系统时区的状态
[root@centos8 ~]# timedatectl status
Local time: Wed 2020-02-05 15:54:06 CST
Universal time: Wed 2020-02-05 07:54:06 UTC
RTC time: Wed 2020-02-05 07:54:06
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
修改时区
[root@centos8 ~]# timedatectl set-time 加要修改的时区名称
查看当前日历
[root@centos8 ~]# cal
February 2020
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
查看2019年10月份的日历
[root@centos8 ~]# cal 10 2019
October 2019
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
定时5分钟后自动关机
[root@centos8 ~]# shutdown +5 -r "System will be reboot in 5 minutes"
Shutdown scheduled for Wed 2020-02-05 16:09:14 CST, use 'shutdown -c' to cancel.
撤销关机
[root@centos8 ~]# shutdown -c
w显示所有终端用户正在做什么
[root@centos8 ~]# w
16:06:41 up 17 min, 2 users, load average: 0.06, 0.05, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty2 tty2 15:49 17:46 10.15s 0.00s /usr/libexe
root pts/0 192.168.180.1 15:49 1.00s 0.07s 0.02s w
查看当前运行级别
[root@centos7 ~]#runlevel
5 3
#5代表上次运行模式图形界面 现在是3 字符界面
查看当前的终端设备
[root@centos7 ~]#tty
/dev/pts/0
#tty 虚拟终端 Ctrl+Alt+F#
pts 伪终端 如:SSH远程连接
查看当前用户名
[root@centos7 ~]#whoami
root
查看当前用户在哪个终端上什么时间登陆的
[root@centos7 ~]#who am i
root pts/0 2020-01-18 15:29 (192.168.16.1)
查看这台机器所有登陆用户信息
[root@centos7 ~]#who
root tty1 2020-01-18 16:10
root pts/0 2020-01-18 15:29 (192.168.16.1)
#linux 是一个多用户的操作系统 它可以同时让不同的用户在不同的终端上同时登陆在系统上进行使用
查看光盘
[root@centos6 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 100660656 3638684 91901972 4% /
tmpfs 501508 76 501432 1% /dev/shm
/dev/sda1 999320 34092 912800 4% /boot
/dev/sda3 50264772 53064 47651708 1% /data
/dev/sr0 6049912 6049912 0 100% /media/CDROM
显示当前用的SHELL类型
[root@centos7 ~]#echo $SHELL
/bin/bash
#在linux默认用的bash SHELL
显示当前系统支持的shell
[root@centos7 ~]#cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/tcsh
/bin/csh
#shell本身是一个程序 放在bin目录下 bin代表2进制 bin目录下放的都是二进制应用程序 bash是其中的一种shell 在linux中默认用的是bash
可以把shell理解成生活中用的语言
命令提示符
[root@centos7 ~]#
root 当前用户名
@ 固定的字符串
centos6 当前主机名
~ 表示当前在家目录里
#管理员
$普通用户
显示提示符格式
[root@centos7 ~]#echo $PS1
bash的快捷键
Ctrl + l 清屏,相当于clear命令
Ctrl + o 执行当前命令,并重新显示本命令
Ctrl + s 阻止屏幕输出,锁定
Ctrl + q 允许屏幕输出
Ctrl + c 终止命令
Ctrl + z 挂起命令
Ctrl + u 从光标处删除至命令行首
Ctrl + k 从光标处删除至命令行尾
Alt + r 删除当前整行
Alt + N 提示输入指定字符后,重复显示该字符N次