1、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
[root@localhost ~]# vim createuser.sh
#!/bin/bash
if [ $# -eq 1 ];then
if id $1 &> /dev/null;then
echo "$1已存在"
else
useradd $1 && echo "$(id $1)"
fi
else
echo "请输入一个用户名作为参数"
fi
[root@localhost ~]# chmod +x createuser.sh
[root@localhost ~]# bash createuser.sh user
user已存在
[root@localhost ~]# bash createuser.sh user1
uid=1001(user1) gid=1001(user1) groups=1001(user1)
2、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[root@localhost ~]# vim ~/.vimrc
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e")=='sh'
call setline(1,"#!/bin/bash")
call setline(2,"#")
call setline(3,"#****************************************")
call setline(4,"#author: xxxxxx *")
call setline(5,"#email: xxxxxx@xxxxxx *")
call setline(6,"#version: 1.0 *")
call setline(7,"#date: ".strftime("%Y-%m-%d *"))
call setline(8,"#description: test script *")
call setline(9,"#****************************************")
endif
endfunc
[root@localhost ~]# vim test.sh
#!/bin/bash
#
#****************************************
#author: xxxxxx *
#email: xxxxxx@xxxxxx *
#version: 1.0 *
#date: 2021-03-14 *
#description: test script *
#****************************************
3、查找/etc目录下大于1M且类型为普通文件的所有文件
[root@localhost ~]# find /etc -size +1M -a -type f -ls
4、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
[root@localhost ~]# cd /etc/
[root@localhost etc]# tar -zcvf /usr/local/src/$(date "+%F").tar.gz *.conf
[root@localhost etc]# ls /usr/local/src/
2021-03-14.tar.gz
5、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
[root@localhost ~]# find / -nouser -o -nogroup -a -atime -7
6、查找/etc目录下至少有一类用户没有执行权限的文件
[root@localhost ~]# find /etc ! -perm /111 -ls