1、编写脚本 createuser.sh,实现如下功能:使用一个用户名作为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
read -p " input the user: " USER
if id $USER &> /dev/null ; then
echo -e " User already exists:\nid $USER"
else
sudo useradd $USER -g 2021 -m
echo -e " $USER created successfully:\n User info id $USER "
fi
2、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
sudo vi ~./vimrc
set ts=4
set autoindent
set cursorline
set ignorecase
set et
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: lime")
call setline(5,"#QQ: 171285296")
call setline(6,"#FileName ".expand("%)"))
call setline(7,"#Date: ".strftime("%Y-%m-$d"))
call setline(8,"#*")
call setline(9,"")
endfunc
autocmd BufNewFile * normal G
3、查找/etc目录下大于1M且类型为普通文件的所有文件
[23:26:26 root@centos8[~]#find /etc/ -type f -size +1M -ls
202230743 8672 -rw-r--r-- 1 root root 8877606 Feb 2 00:36 /etc/selinux/targeted/policy/policy.31
70661395 9172 -r--r--r-- 1 root root 9389332 Feb 2 00:55 /etc/udev/hwdb.bin
4、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
[23:52:04 root@centos8[ ~]#find /etc/ -name "*.conf" |xargs tar zcvf /usr/local/src/$(date +%F).tar.gz
[23:52:31 root@centos8[ ~]#cd /usr/local/src/
[23:52:33 root@centos8[ src]#ll
total 216
-rw-r--r--. 1 root root 220046 Apr 17 23:52 2021-04-17.tar.gz
5、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
[23:59:27 root@centos8[ ~]#find / \( -nogroup -o -nouser -a -atime -7 \)
find: ‘/proc/2582’: No such file or directory
find: ‘/proc/2588/task/2588/fd/8’: No such file or directory
find: ‘/proc/2588/task/2588/fdinfo/8’: No such file or directory
find: ‘/proc/2588/fd/9’: No such file or directory
find: ‘/proc/2588/fdinfo/9’: No such file or directory
find: ‘/run/user/1000/gvfs’: Permission denied
6、查找/etc目录下至少有一类用户没有执行权限的文件
root@ubuntu1804:~# find /etc/ ! -perm 111 |wc -l
1505