培训、环境、资料、考证
公众号:波比网络公众号2:波比网络工作室
网络建设与运维群:685678820波比网络专注于技能提升,赋能
13.shell 脚本
任务描述:请采用 shell 脚本,实现快速批量的操作。
在 linux4 上编写/root/createfile.sh 的 shell 脚本,创建 20 个文件/root/shell/file00 至/root/shell/file19,如 果文件存在,则删除再创建;每个文件的内容同文件名,如 file00 文件的内容为“file00”。用/root/createfile.sh 命令测试。
[root@localhost ~]# cat creatfile.sh #!/bin/bash mkdir /root/shell cd /root/shell for num in {00..19} do if [ -e file${num} ];then rm -rf file${num} touch file${num} echo "file${num}">>file${num} else touch file${num} echo "file${num}">>file${num} fi done [root@localhost ~]# chmod 777 creatfile.sh //设置读写执行权限 [root@localhost ~]# ./creatfile.sh //运行脚本文件 |
创建名为test.sh的脚本文件,实现批量创建99个用户,用户名为user1,user2...user99
所有用户密码为 chinaskill20!