1、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
[root@Centos7 data]# vim createuser.sh
read -p "请输入用户名:" name
if `id $name &>/dev/null` ;then
echo "用户名已存在!"
else
`useradd $name &>/dev/null`
echo "用户: $name 已创建"
echo "用户信息:`id $name`"
fi
[root@Centos7 data]# . craeteuser.sh
请输入用户名:my
用户: my 已创建
[root@Centos7 data]# . craeteuser.sh
请输入用户名:ai
用户: ai 已创建
用户信息:uid=2012(ai) gid=2012(ai) groups=2012(ai)
2、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
set ts=4
set ignorecase
set cursorline
set autoindent
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: Wu")
call setline(5,"#Date: ".strftime("%Y-%m-%d"))
call setline(6,"#FileName: ".expand("%"))
call setline(7,"#********************************************************************")
call setline(8,"")
endif
endfunc
autocmd BufNewFile * normal G
3、查找/etc目录下大于1M且类型为普通文件的所有文件
[root@Centos7 ~]# find /etc/ -size +1M -a -type f -ls
134663964 8668 -r--r--r-- 1 root root 8873994 Nov 25 10:38 /etc/udev/hwdb.bin
819019 3816 -rw------- 1 root root 3905807 Oct 1 01:39 /etc/selinux/targeted/active/policy.kern
67672503 1384 -rw-r--r-- 1 root root 1416505 Oct 1 01:45 /etc/selinux/targeted/contexts/files/file_contexts.bin
819039 3816 -rw-r--r-- 1 root root 3905807 Oct 1 01:39 /etc/selinux/targeted/policy/policy.31
4、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
[root@Centos7 etc]# find /etc/ -name "*.conf" |xargs tar -cpvf `date +%F`.tar && cp `date +%F`.tar /usr/local/src/
tar: Removing leading `/' from member names
/etc/resolv.conf
/etc/pki/ca-trust/ca-legacy.conf
/etc/yum/pluginconf.d/fastestmirror.conf
/etc/yum/pluginconf.d/langpacks.conf
/etc/yum/protected.d/systemd.conf
/etc/yum/version-groups.conf
/etc/lvm/lvm.conf
/etc/lvm/lvmlocal.conf
/etc/asound.conf
/etc/openldap/ldap.conf
/etc/logrotate.conf
/etc/depmod.d/dist.conf
/etc/yum.conf
/etc/dracut.conf
[root@Centos7 etc]# cd /usr/local/src/
[root@Centos7 src]# ls
2020-12-28.tar
5、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
[root@Centos7 ~]# find / -nouser -o -nogroup -a -atime +7
find: ‘/proc/8869/task/8869/fd/6’: No such file or directory
find: ‘/proc/8869/task/8869/fdinfo/6’: No such file or directory
find: ‘/proc/8869/fd/5’: No such file or directory
find: ‘/proc/8869/fdinfo/5’: No such file or directory
/var/spool/mail/mandriva
/home/mandriva
/home/mandriva/.bash_logout
/home/mandriva/.bash_profile
/home/mandriva/.bashrc
6、查找/etc目录下至少有一类用户没有执行权限的文件
[root@Centos7 ~]# find /etc -not -perm /111 |wc -l
1650