shell脚本显示文本内容及相关的常用命令有cat.more.less.head.tail.nl 首先是cat,cat最常用的就是一次性显示文件的所有内容,如果一个文件的内容很多的话,那么就不是很方便了,所以一样用于查看内容比较少的文本文件: cat另外一个很有用的方法就是可以原样输出想要保留特定格式的内容. [root@localhost ~]# cat <<A > this is test > hello world > hello Linux PHP MySQL Apa
此脚本是用来批量创建用户并设置用户密码,在企业用非常实用. 脚本一 #!/bin/bash for name in $( seq 1 100 ) do useradd "user$name" if [ $? -eq 0 ];then echo -e "\n创建 "user$name" 成功!" fi done 添加100用户在users组,并设置密码为user 脚本二 i=1 for (1..100) do groupadd users addu
编写脚本/root/bin/systeminfo.sh, 当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小. vim /root/bin/systeminfo.sh echo "The hostname is: $(hostname)" echo "The IPv4 address is: $(ifconfig ens33|grep netmask|tr -s " "|cut -d" "
查看当前日期以及登陆用户: cat test1: #!/bin/bash # This script displays the date and who's logged on echo -n The time and date are: date echo "Let's see who's logged into the system:" who 添加执行权限:chmod u+x test1 执行./test1,得带结果如下: The :: CST Let's see who's l
写在前面:案例.常用.归类.解释说明.(By Jim) 使用多条命令shell脚本的关键是可以输入多条命令,甚至可以将一条命令的结果传递给另一条命令.date;who(两个命令shell脚本的写法) 创建shell脚本1.将shell命令放置到一个文本文件中2.指明所使用的shell,比如#!/bin/bash3.可以用#注释,但是一般注释不会被读取,第一行除外案例#!/bin/bash#This script displays the date and who's logged ondatew