week4 作业

week4 作业

1、定义一个对所有用户都生效的命令别名,例如:lftps='lftp 172.168.0.1 /pub'
在 ~/.bashrc中添加命令:
alias = 'rm -i'

2、显示/etc/passwd文件中不已/bin/bash结尾的行
grep -v ".*/bin/bash$" /etc/passwd

3、找出/etc/passwd文件中,包含两位数和三位数的行
grep "\<[0-9]\{2,3\}\>" /etc/passwd
egrep "\<[0-9]{2,3}\>" /etc/passwd

4、显示/proc/meminfo中以大写或小写s开头的行,三种方法:
grep -i ^s /proc/meminfo
grep ^[Ss] /proc/meminfo
grep -E "^(s|S)" /proc/meminfo

5、使用echo输出一个绝对路径,使用egrep取出路径名,类似执行dirname /etc/passwd 的效果。
echo /etc/sysconfig/network-scripts/ifcfg-ens33/ | egrep -o "[^/]+/?$"
echo /etc/sysconfig/network-scripts/ifcfg-ens33/ | egrep -o ".*/\<"

6、找出ifconfig中的ip地址,要求结果只显示ip地址。
ifconfig | grep -o "\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}"

7、vim定制自动缩进4个字符

vim  /etc/vimrc
添加
set tabstop=4
保存退出

8、编写脚本,实现自动添加三个用户,并计算三个用户的UID之和。

#!/bin/bash
[ $# -ne 3 ] && echo -e "\e[1;31mArgs num must be 3 \e[0m" && exit
useradd $1 &> /dev/null
[ `echo $?` -ne 0 ] && echo -e  "\e[1;31mthe username $1  is exist,please change another! \e[0m" && exit
useradd $2 &>  /dev/null
[ `echo $?` -ne 0 ] && echo -e  "\e[1;31mthe username $2  is exist,please change another! \e[0m" && exit
useradd $3 &>  /dev/null
[ `echo $?` -ne 0 ] && echo -e  "\e[1;31mthe username $3  is exist,please change another! \e[0m" && exit
ID1="`id $1 -u`"
ID2="`id $2 -u`"
ID3="`id $3 -u`"
sumid=$[ID1+ID2+ID3]
echo $sumid

此脚本有问题,创建 1 2 3 三个用户,假如1 2 以前未创建,3已创建,当执行这个脚本的时候会创建用户1和用户2,到创建用户3时退出,未达到一旦发现有任何一个用户已经创建就退出的目的。

9、find用法及实例演示
见博文find详解

猜你喜欢

转载自www.cnblogs.com/sstjustdoit/p/10050719.html
今日推荐