1歉提、編寫腳本 createuser.sh,實現(xiàn)如下功能:使用一個用戶名做為參數(shù)区转,如果 指定參數(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 已創(chuàng)建"
echo "用戶信息:`id $name`"
fi
[root@Centos7 data]# . craeteuser.sh
請輸入用戶名:my
用戶: my 已創(chuàng)建
[root@Centos7 data]# . craeteuser.sh
請輸入用戶名:ai
用戶: ai 已創(chuàng)建
用戶信息:uid=2012(ai) gid=2012(ai) groups=2012(ai)
2侄泽、編寫生成腳本基本格式的腳本,包括作者蜻韭,聯(lián)系方式悼尾,版本,時間肖方,描述等
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結(jié)尾的文件窥妇,壓縮包名稱為當天的時間舷胜,并拷貝到/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活翩、查找當前系統(tǒng)上沒有屬主或?qū)俳M烹骨,且最近一個周內(nèi)曾被訪問過的文件或目錄
[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目錄下至少有一類用戶沒有執(zhí)行權(quán)限的文件
[root@Centos7 ~]# find /etc -not -perm /111 |wc -l
1650