第五周作业

1、编写脚本createuser.sh

#!/bin/sh
if [ $# -eq 0 ];then
    echo "please input one parameter"
else
    username=$1
    if id -u $username >/dev/null 2>&1; then
        echo "$username existed!"
    else
       useradd $username >/dev/null
       echo `id -u $username`
    fi
fi

2、编写生成脚本基本格式的脚本

cat ~/.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:                kau")
            call setline(5,"#QQ:                    1")
            call setline(6,"#email:                 1@qq.com")
            call setline(7,"#version:               1.0")
            call setline(8,"#date:                  ".strftime("%Y-%m-%d"))
            call setline(9,"#description:           studytest.")
            call setline(10,"#*************************************")
    endif
endfunc

3、查找/etc目录下大于1M且类型为普通文件的所有文件

find /etc/ -size +1M -type f

4、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天实际。并拷贝到/usr/local/src/ 目录备份

tar zcvf /usr/local/src/`date +"%Y%m%d"`.tar.gz $(find /etc -name "*.conf")

5、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录

find / -nouser -o -nogroup -a atime +7

6、查找/etc目录下至少有一类用户没有执行权限的文件

find /etc/ ! -perm 111 -type f
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容