1.基础三剑客题目
环境准备:
[root@oldboy62-0 ~]# cat >> oldboy.txt <<EOF
> I am oldboy teacher!
> I teach linux.
>
> I like badminton ball ,billiard ball and chinese chess!
> my blog is http://oldboy.blog.51cto.com
> our site is http://www.etiantian.org
> my qq num is 49000448.
>
> not 4900000448.
> my god ,i am not oldbey,but OLDBOY!
> EOF
1. ^$ -- 查找出空行
root@oldboy62-0 ~]# grep '^$' oldboy.txt
排除空行
[root@oldboy62-0 ~]# grep -v '^$' oldboy.txt
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our site is http://www.etiantian.org
my qq num is 49000448.
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
排除前一个字符出现0次或多次

匹配一个字符出现一次或多次
[root@oldboy62-0 ~]# egrep '0+' oldboy.txt
my qq num is 49000448.
not 4900000448.
2.如何批量添加用户--并免交互设置密码
[root@oldboy62-0 ~]# seq -w 10|sed -r 's#(.*)#useradd linux\1;echo 123456|passwd --stdin linux\1#g'|bash
Changing password for user linux01.
passwd: all authentication tokens updated successfully.
Changing password for user linux02.
passwd: all authentication tokens updated successfully.
Changing password for user linux03.
passwd: all authentication tokens updated successfully.
Changing password for user linux04.
passwd: all authentication tokens updated successfully.
Changing password for user linux05.
passwd: all authentication tokens updated successfully.
Changing password for user linux06.
网友评论