在学习过程中的一些命令行的掌握

重启虚拟机:reboot(init 6)
查看主机名:hostname
临时更改主机名(重启后失效):hostname 新主机名 (主机名不能用下划线)
关机:init 0(proweroff、halt)
图形界面切换到命令行界面:init 3
查看Linux版本:cat /etc/os-release
查看内核:uname -r
查看硬盘情况:
[root@xia ~]# 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 93.1G 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 7.7G 0 rom
查看网卡 例
[root@xia ~]# ip a 1: lo: 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: ens160: mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:c4:78:51 brd ff:ff:ff:ff:ff:ff inet 192.168.174.130/24 brd 192.168.174.255 scope global dynamic noprefixroute ens160 valid_lft 1508sec preferred_lft 1508sec inet6 fe80::9f85:340a:28d4:ddea/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: virbr0: mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:34:06:9b brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000 link/ether 52:54:00:34:06:9b brd ff:ff:ff:ff:ff:ff
以上1为系统自带的虚拟网卡、2是物理网卡、3.4是其他软件带的虚拟网卡。
查看当前运行的软件(相当与window的任务管理器):ps aux
查看CPU型号:lscpu
查看内存使用情况:free -h (图形界面的内存使用远远大于命令行界面)
查看终端设备名:tty
[root@xia ~]# tty /dev/pts/1
查看当前使用的shell
[root@xia ~]# echo $SHELL /bin/bash
查看这个shell的大小:ll /bin/bash
查看系统中的所以shell
[root@xia ~]# cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /usr/bin/bash
查看IP:还可以用config、if config、ip -a、ifconfig也可以用下面这个
[root@xia ~]# hostname -I 192.168.174.130 192.168.122.1

windows命令提示符界面连接虚拟机 例:
`C:\Users\xiaxiangming>ssh [email protected]
The authenticity of host '192.168.174.130 (192.168.174.130)' can't be established.
ECDSA key fingerprint is SHA256:zbTaAui3E6VzDRkBXyqyWqSTz06KrV+F4Op7gFFae0U.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.174.130' (ECDSA) to the list of known hosts.
[email protected]'s password:
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sat Jun 20 17:37:01 2020 from 192.168.174.1
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sat Jun 20 17:37:01 2020 from 192.168.174.1
[root@xia ~]#`

Ubuntu进入root模式:sudo -i 例:
xiaxiangming@ubuntu-1804:~$ sudo -i [sudo] password for xiaxiangming: root@ubuntu-1804:~#

查看提示符的变量
[root@xia ~]# echo $PS1 [\u@\h \W]\$
修改提示符(临时修改):[]里面的显示内容和样式
[root@xia ~]#PS1="\[\e[1;41;33m\][\u@\h \w]\\$\[\e[0m\]" /给变量赋值
修改后颜色会有所变化。
永久保存 范例:
[root@xia ~]#echo 'PS1="\[\e[1;34m\][\u@\h \w]\\$\[\e[0m\]"' > /etc/profile.d/env.sh /变量写入硬盘 [root@xia ~]#cat /etc/profile.d/env.sh /查看是否写入成功 PS1="\[\e[1;34m\][\u@\h \w]\\$\[\e[0m\]" /查看结果 [root@xia ~]#exit /退出就可以看到效果了 logout
不想要可以删除evn.sh文件
[root@xia ~]#rm -f /etc/profile.d/env.sh /删除 [root@xia ~]#cat /etc/profile.d/env.sh /查看 cat: /etc/profile.d/env.sh: No such file or directory [root@xia ~]#exit logout

~表示当前所在的文件夹例:
[root@xiaxiangming ~]# cd /etc
[root@xiaxiangming etc]# cd /etc/sysconfig
[root@xiaxiangming sysconfig]#

你可能感兴趣的:(在学习过程中的一些命令行的掌握)