1、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
read -p "please input user name:" NAME
id $NAME &> /dev/null && echo "$NAME is exist " || (useradd $NAME ; id $NAME)
[22:09:20 root@bear data]#bash createuser.sh
please input user name:wang
wang is exist
[22:09:30 root@bear data]#bash createuser.sh
please input user name:wang12
uid=2005(wang12) gid=2005(wang12) groups=2005(wang12)
2、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
[22:20:20 root@bear data]#vim test.sh
1 #!/bin/bash
2 #
3 #***********************
4 #Author: stellatang
5 #Contact: 123456789
6 #Version: 1.0
7 #Date: 2020-12-21
8 #Description: The test script
9 #***********************
3、查找/etc目录下大于1M且类型为普通文件的所有文件
[22:27:35 root@bear data]#find /etc -size +1M -type f -ls
68640765 9124 -r--r--r-- 1 root root 9339625 Nov 8 23:45 /etc/udev/hwdb.bin
729587 8640 -rw-r--r-- 1 root root 8844650 Nov 8 23:28 /etc/selinux/targeted/policy/policy.31
4、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
[20:25:25 root@bear src]#tar zcvf /usr/local/src/`date +"%F-%T"`.tar.gz /etc/*.conf
tar: Removing leading `/' from member names
/etc/asound.conf
tar: Removing leading `/' from hard link targets
/etc/autofs.conf
/etc/autofs_ldap_auth.conf
/etc/brltty.conf
/etc/chrony.conf
/etc/dleyna-server-service.conf
/etc/dnsmasq.conf
/etc/dracut.conf
/etc/fprintd.conf
/etc/fuse.conf
/etc/host.conf
/etc/idmapd.conf
/etc/kdump.conf
/etc/krb5.conf
/etc/ksmtuned.conf
/etc/ld.so.conf
/etc/libaudit.conf
/etc/libuser.conf
/etc/locale.conf
/etc/logrotate.conf
/etc/man_db.conf
/etc/mke2fs.conf
/etc/mtools.conf
/etc/nfs.conf
/etc/nfsmount.conf
/etc/nsswitch.conf
/etc/oddjobd.conf
/etc/pbm2ppa.conf
/etc/pnm2ppa.conf
/etc/radvd.conf
/etc/request-key.conf
/etc/resolv.conf
/etc/rsyslog.conf
/etc/sestatus.conf
/etc/sos.conf
/etc/sudo.conf
/etc/sudo-ldap.conf
/etc/sysctl.conf
/etc/tcsd.conf
/etc/updatedb.conf
/etc/usb_modeswitch.conf
/etc/vconsole.conf
/etc/xattr.conf
/etc/yum.conf
[20:25:58 root@bear src]#ll
total 1144
-rw-r--r--. 1 root root 47128 Dec 23 20:25 2020-12-23-20:25:58.tar.gz
5、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
[22:43:15 root@bear ~]#find /home \( -nouser -o -nogroup \) -a -atime -7 \( -type d -o -type f \)
/home/mandriva
/home/mandriva/.mozilla
/home/mandriva/.mozilla/extensions
/home/mandriva/.mozilla/plugins
[22:44:09 root@bear ~]#find /home \( -nouser -o -nogroup \) -a -atime -7
/home/mandriva
/home/mandriva/.mozilla
/home/mandriva/.mozilla/extensions
/home/mandriva/.mozilla/plugins
6、查找/etc目录下至少有一类用户没有执行权限的文件
[22:51:24 root@bear ~]#find /etc ! -perm -111