Bash脚本

2019-08-10  本文已影响0人  Oooyzx

Shell_01_认识Bash
https://www.jianshu.com/p/02ad4dbd9161
Shell_02_变量
https://www.jianshu.com/p/6cbb93ff9d4e
Shell_03_文件描述符
https://www.jianshu.com/p/db5a19fb582a

认识 Bash

shell保存于 /etc/shell中

image.png

Bash的功能

  • 1.命令别名: alias, unalias:
image.png
1.1 取消grep的--color 用 \ 转义:
\grep 转义

=======================================================

2.stty 隐藏输入
image.png
2.1 从键盘输入并用cat显示出来
image.png
2.2 将键盘输入的内容输出到inputinfo里面:
image.png
2.3 将家目录下的.bashrc的文件输入到inputinfo里:
image.png

=====================================================

bash 的登录主机欢迎信息: /etc/issue, /etc/motd

image.png
image.png

cut补充

image.png

变量

image.png
![image.png](https://upload-images.jianshu
.io/upload_images/125327-587ed7b0fdd4a7bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

[root@oyzx]vim .bashrc


image.png

[root@oyzx]. .bashrc
[root@oyzx]echo $username
oyzx

=====================================================

image.png
image.png

作业

写个脚本,执行后输出如下结果:

目前的登录用户数:
w |head -1 | cut -d "," -f 2
服务器名称:
hostname
服务器的物理 CPU 颗数
grep 'physical id' /proc/cpuinfo | sort -u | wc -l
1
服务器每颗物理 CPU 的核心数是
grep 'cpu cores' /proc/cpuinfo | uniq
cpu cores : 1

内存总容量
cat /proc/meminfo|head -1 |cut -d ":" -f 2
999696 kB

硬盘总容量
fdisk -l |grep Disk|head -1|cut -d "," -f 1
Disk /dev/sda: 21.5 GB

上一篇 下一篇

猜你喜欢

热点阅读