第1章 回顾昨天

1.1 linux如何让一个服务/脚本开机自启动?

chkconfig

/etc/rc.local

 

1.2 被chkconfig管理 需要什么条件

1.2.1 必须放在/etc/init.d/

1.2.2 这个脚本要有执行权限

1.2.3 加上chkconfig要求的内容

chkconfig: 2345 99 99

1.2.4 chkconfig --add 把脚本添加到开机自启动

1.2.5 检查

/etc/rc.local

[root@oldboyedu-40-nb ~]# ls -l /etc/rc3.d/ |grep rc.local

lrwxrwxrwx. 1 root root 11 Aug 10 18:36 S99local -> ../rc.local

 

1.3 磁盘空间不足 no space left on device

1.3.1 block满了 500G 3*200G视频

df -h

du -sh /*

du -sh /* |grep G

 

1.3.2 block满了 文件没有被彻底删除  硬链接数为0,进程调用数不为零

1.3.2.1  检查:

lsof|grep delete

文件的删除原理(条件)

硬链接数为0

进程调用数为0

1.3.2.2  日志

/var/log/messages

/var/log/secure

rsyslog

 

access.log

 

1.3.3 inode满了

创建一个文件要占用一个inode和至少一个block

大量的小文件

1.3.4 检查

df -i

找出系统中比较大的目录(1M)

 

1.4 软硬链接区别

 

 

 

 

第2章 通配符

含义:方便我们查找文件 通配符是用来找文件名字

 

2.1 例子

2.1.1 /oldboy  以.sh结尾的  修改时间是7天之前的 大于100k 小于10M的文件

find /oldboy -type f -name "*.sh" -mtime +7  -size +100k  -size -10M

 

通配符大家族常用的符号

所有  任何内容 任何符号 任何文字

2.1.2 准备环境

mkdir -p /oldboy/20170118

cd /oldboy/20170118

touch stu{00..10}.txt oldboy{00..10}.log

touch linux-oldboy{00..5}.txt

touch oldboy.txt stu.txt

2.1.2.1  找出 所有以stu开头的文件

[root@oldboyedu-40-nb 20170118]# ls -l stu*

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu00.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu01.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu02.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu03.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu04.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu05.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu06.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu07.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu08.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu09.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu10.txt

-rw-r--r-- 1 root root 0 Aug 31 09:09 stu.txt

[root@oldboyedu-40-nb 20170118]# find -type f -name "stu*"

./stu07.txt

./stu00.txt

./stu02.txt

./stu01.txt

./stu.txt

./stu06.txt

./stu10.txt

./stu04.txt

./stu03.txt

./stu09.txt

./stu05.txt

./stu08.txt

ls -l stu*.*

以stu开头的 任意字符 小数点 任意字符

 

2.1.2.2  找出文件名中包含 oldboy 的文件

oldboy.txt

linux-oldboy.txt

 

ls -l *oldboy*

 

 

 

 

2.1.3 {} 生成序列 下蛋

{开始..结束}

 

{开始..结束..每次变化多少}

[root@oldboyedu-40-nb 20170118]# echo oldboy{a..e}.txt

oldboya.txt oldboyb.txt oldboyc.txt oldboyd.txt oldboye.txt

[root@oldboyedu-40-nb 20170118]#

[root@oldboyedu-40-nb 20170118]# echo a c d f 1 2 9 100

a c d f 1 2 9 100

[root@oldboyedu-40-nb 20170118]# echo {a,c,d,f}

a c d f

[root@oldboyedu-40-nb 20170118]# echo {a ,c,d,f}

{a ,c,d,f}

[root@oldboyedu-40-nb 20170118]# echo {a..z}

a b c d e f g h i j k l m n o p q r s t u v w x y z

[root@oldboyedu-40-nb 20170118]# echo {a..z} {A..Z}

a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

[root@oldboyedu-40-nb 20170118]# seq 1 2 10

1

3

5

7

9

[root@oldboyedu-40-nb 20170118]# seq 10 -2  1

10

8

6

4

2

[root@oldboyedu-40-nb 20170118]# echo {a..z}

a b c d e f g h i j k l m n o p q r s t u v w x y z

[root@oldboyedu-40-nb 20170118]# echo {1..10}

1 2 3 4 5 6 7 8 9 10

[root@oldboyedu-40-nb 20170118]# echo {1..10..2}

1 3 5 7 9

[root@oldboyedu-40-nb 20170118]# echo {10..1..2}

10 8 6 4 2

 

用来备份

[root@oldboyedu-40-nb 20170118]# echo A{B,C}

AB AC

[root@oldboyedu-40-nb 20170118]# echo A{,C}

A AC

[root@oldboyedu-40-nb 20170118]#

[root@oldboyedu-40-nb 20170118]# echo oldboy.txt{,C}

oldboy.txt oldboy.txtC

[root@oldboyedu-40-nb 20170118]# echo oldboy.txt{,bak}

oldboy.txt oldboy.txtbak

[root@oldboyedu-40-nb 20170118]# echo oldboy.txt{,.bak}

oldboy.txt oldboy.txt.bak

[root@oldboyedu-40-nb 20170118]# #cp oldboy.txt{,.bak}

[root@oldboyedu-40-nb 20170118]# ls -l oldboy.txt*

-rw-r--r-- 1 root root 0 Aug 31 09:09 oldboy.txt

[root@oldboyedu-40-nb 20170118]# cp oldboy.txt{,.bak}

[root@oldboyedu-40-nb 20170118]# ls -l oldboy.txt*

-rw-r--r-- 1 root root 0 Aug 31 09:09 oldboy.txt

-rw-r--r-- 1 root root 0 Aug 31 09:38 oldboy.txt.bak

 

2.2 通配符

找出文件

大部分命令都支持

ls    *.txt

touch {a..z}

mkdir {a..z}dir

3. * {}

 

2.2.1 特殊符号

2.2.1.1  重定向符号:

>   标准输出重定向 先把文件内容清空 然后向文件中放入内容

>>  标准追加重定向 然后向文件中放入内容

<   标准输入       xargs

<<  追加输入    

cat >/oldboy/oldboy.txt <<EOF

oldboy

linux

oldboyedu.com

EOF                 

2.2.1.2  其他重要符号:

.  当前目录

   linux下面隐藏文件

   ~/.bashrc   

.. 当前目录的上一层目录 

~  当前用户的家目录

/root

/home/oldboy   

/  根目录  路径分隔符

   ../../..

   /etc/hosts

\  取消别名

|  管道

1) vi/vim :wq! :q! 强制

2) find里面 awk里面表示 取反

3) 表示使用你用过的命令 使用历史命令

   !ls   ===== history |grep ls 

#  注释

$  取出变量里面的内容

&& 并且 前一个命令运行成功,然后再运行后面的命令

ifdown eth0 && ifup eth0

;  分开多条命令 在同一行里面放入多个命令

ls; pwd; hostname

 

2.2.1.3  特殊符号小结:

      &&

      >> 

      >

      /

      $

      .

      ..

      ~

      |

    !

      #

 

2.2.1.4  单引号 双引号 不加引号的区别  

   

单引号 吃啥吐啥 所见即所得

[root@oldboyedu-40-nb 20170118]# echo '$LANG $(pwd) `hostname` {a..e}'

$LANG $(pwd) `hostname` {a..e}

 

 

双引号 把双引号里面的特殊符号进行解析 

[root@oldboyedu-40-nb 20170118]# echo "$LANG $(pwd) `hostname` {a..e}"

en_US.UTF-8 /oldboy/20170118 oldboyedu-40-nb {a..e}

 

 

不加引号 和双引号类似 支持通配符 

[root@oldboyedu-40-nb 20170118]# echo $LANG $(pwd) `hostname` {a..e}

en_US.UTF-8 /oldboy/20170118 oldboyedu-40-nb a b c d e

 

 

反引号 ``  $()  先运行小括号里面的内容 把显示到屏幕上的内容留下  

   

 

 

第3章 正则表达式

lidao.身份证

汤 610702199107053598

邹 371481199403259478

莫 52020319810613433X

韩 460106199111137270

荣 530124197504135438

荣 oldboy

荣 babygirl

荣 530124197504135438

阮 360702197902169951

翁 331002198504132813

任 621223198708245176

姜 370602198507189574

霍 320904198403048179

 

3.1 正则表达式

[0-9]

3.1.1 什么是正则

特殊符号表示文字 文本

^     开头

[0-9] 数字

3.1.2 作用

提高效率   省事 懒

3.1.3 分类

基础正则表达式

^ $ ^$ .  *  .*  [0-9]  [^0-9]

扩展正则表达式

| () + {} ?

 

3.2 正则表达式与通配符区别?

3.2.1 通配符是用来找文件 名字 ls *.txt

3.2.2 正则表达式用来在文件中找文字(内容)  文本

 

 

3.3 中文符号预警准备

1.预警-中文符号

2.grep/egrep

 

cat >>/etc/profile<<EOF

alias grep='grep --color=auto'

alias egrep='egrep --color=auto'

EOF

source /etc/profile

 

3.4 环境准备-oldboy.txt

 

[root@oldboyedu-40-nb oldboy]# vim 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!

 

 

[root@oldboyedu-40-nb oldboy]# cat -A 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!$

 

 

3.5 基础正则表达式

3.5.1  ^oldboy    以oldboy开头的行 以......开头的行

[root@oldboyedu-40-nb oldboy]# grep "^m" oldboy.txt

my blog is http://oldboy.blog.51cto.com

my qq num is 49000448.

my god ,i am not oldbey,but OLDBOY!

 

 

3.5.2   $          以.....结尾的行

m$    以m结尾的行

[root@oldboyedu-40-nb oldboy]# cat -A 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!$

[root@oldboyedu-40-nb oldboy]# grep "m$" oldboy.txt

my blog is http://oldboy.blog.51cto.com

 

3.5.3  ^$  空行 这一行里面什么符号都没有 

 

[root@oldboyedu-40-nb oldboy]# grep "^$" oldboy.txt

 

 

 

 

[root@oldboyedu-40-nb oldboy]# grep -n "^$" oldboy.txt

3:

6:

8:

10:

[root@oldboyedu-40-nb oldboy]# cat -A 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!$

[root@oldboyedu-40-nb oldboy]# cat -An oldboy.txt

     1  I am oldboy teacher!$

     2  I teach linux.$

     3  $

     4  I like badminton ball ,billiard ball and chinese chess!$

     5  my blog is http://oldboy.blog.51cto.com$

     6  $

     7  our site is http://www.etiantian.org$

     8  $

     9  my qq num is 49000448.$

    10  $

    11  not 4900000448.$

    12  my god ,i am not oldbey,but OLDBOY!$

[root@oldboyedu-40-nb oldboy]#

 

排除文件中的空行

 

3.5.4   .(点)  任意一个字符

[root@oldboyedu-40-nb oldboy]# grep "." 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!

[root@oldboyedu-40-nb oldboy]# #grep到底如何找的文字---花儿为什么这样红

[root@oldboyedu-40-nb oldboy]# grep -o "." oldboy.txt

I

 

a

省略......

 

 

[root@oldboyedu-40-nb oldboy]# grep "oldb.y" oldboy.txt

I am oldboy teacher!

my blog is http://oldboy.blog.51cto.com

 

my god ,i am not oldbey,but OLDBOY!

[root@oldboyedu-40-nb oldboy]# grep -o "oldb.y" oldboy.txt

oldboy

oldboy

oldbey

 

grep/egrep  -o 显示grep每一次找到什么东西   grep命令执行过程

 

3.5.5 \  撬棍  转义字符 脱掉马甲打回原形

找出文件中以小数点(.) 结尾的行

 

[root@oldboyedu-40-nb oldboy]# grep "\.$" oldboy.txt

I teach linux.

my qq num is 49000448.

not 4900000448.

 

3.5.6   前一个文本连续出现了0次或1次以上  >=0

00000

00000000000000

000000000000000000000000000000000000000000000000000000000000000

 

连续出现了0次就是 没出现

 

[root@oldboyedu-40-nb oldboy]# grep "0*" 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!

[root@oldboyedu-40-nb oldboy]# grep -o "0*" oldboy.txt

000

00000

贪婪性---能有多 我吃多少

 

 

3.5.7 .*   所有内容 包括空行

贪婪性---能有多 我吃多少

正则表达式表示.*(所有)  连续出现的时候 贪婪性

 

[root@oldboyedu-40-nb oldboy]# grep "^.*o"  oldboy.txt

I am oldboy teacher!

I like badminton ball ,billiard ball and chinese chess!

my blog is http://oldboy.blog.51cto.com

our site is http://www.etiantian.org

not 4900000448.

my god ,i am not oldbey,but OLDBOY!

 

3.5.8  [abc]  筐 表示一个整体 相当于是一个字符  a或b或c

 

[root@oldboyedu-40-nb oldboy]# grep "[abc]" 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 god ,i am not oldbey,but OLDBOY!

[root@oldboyedu-40-nb oldboy]# grep -o "[abc]" oldboy.txt

a

b

a

c

省略

[root@oldboyedu-40-nb oldboy]#

[root@oldboyedu-40-nb oldboy]# grep "[abcdefghijklmnopqrstuvwxyz]" 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!

[root@oldboyedu-40-nb oldboy]# grep "[a-z]" 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!

[root@oldboyedu-40-nb oldboy]# grep "[A-Z]" oldboy.txt

I am oldboy teacher!

I teach linux.

I like badminton ball ,billiard ball and chinese chess!

my god ,i am not oldbey,but OLDBOY!

[root@oldboyedu-40-nb oldboy]# grep "[0-9]" oldboy.txt

my blog is http://oldboy.blog.51cto.com

my qq num is 49000448.

not 4900000448.

 

[root@oldboyedu-40-nb oldboy]# grep "[a-zA-Z]" 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!

 

3.5.9 练习

3.5.9.1  练习1:以大写字母开头的行

[root@oldboyedu-40-nb oldboy]# #练习1:以大写字母开头的行

[root@oldboyedu-40-nb oldboy]# grep "A-Z" oldboy.txt

[root@oldboyedu-40-nb oldboy]# grep "[A-Z]" oldboy.txt

I am oldboy teacher!

I teach linux.

I like badminton ball ,billiard ball and chinese chess!

my god ,i am not oldbey,but OLDBOY!

[root@oldboyedu-40-nb oldboy]# grep "^[A-Z]" oldboy.txt

I am oldboy teacher!

I teach linux.

I like badminton ball ,billiard ball and chinese chess!

 

3.5.9.2  练习2:以小写字母结尾的行

[root@oldboyedu-40-nb oldboy]# #练习2:以小写字母结尾的行

[root@oldboyedu-40-nb oldboy]# grep "[a-z]$" oldboy.txt

my blog is http://oldboy.blog.51cto.com

our site is http://www.etiantian.org

 

 

3.5.9.3  练习3:以 m或n或o开头的 并且以  m或g 结尾的行

[root@oldboyedu-40-nb oldboy]# ##第一个里程碑-取出m n o 开头的行

[root@oldboyedu-40-nb oldboy]# grep "[mno]" 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!

[root@oldboyedu-40-nb oldboy]# grep "^[mno]" oldboy.txt

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!

[root@oldboyedu-40-nb oldboy]#

[root@oldboyedu-40-nb oldboy]# ##第二个里程碑-mg 结尾

[root@oldboyedu-40-nb oldboy]# grep "[mg]$" oldboy.txt

my blog is http://oldboy.blog.51cto.com

our site is http://www.etiantian.org

[root@oldboyedu-40-nb oldboy]#

[root@oldboyedu-40-nb oldboy]# ##第三个里程碑-合并

[root@oldboyedu-40-nb oldboy]# grep "^[mno][mg]$" oldboy.txt

[root@oldboyedu-40-nb oldboy]# grep "^[mno].*[mg]$" oldboy.txt

my blog is http://oldboy.blog.51cto.com

our site is http://www.etiantian.org

 

3.5.10  [^abc]  筐 表示一个整体 排除a或排除b或排除c

 

[abc] 三选一 想要任何一个

 

[root@oldboyedu-40-nb oldboy]# grep "[^abc]" 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!

 

 

######grep -v 排除   [^abc]

grep -v 排除行

[^abc]  字符 文字

第4章 今天小结:

特殊符号-通配符-基础正则表达式

1.

特殊符号小结:

&& >> > /$... ~ | ! #

2.通配符* {} 

3.正则

1)按照一行

2)^ $ ^$  .*  [] \

 

如何排除文件中的空行和包含#的行

第5章 预习:

扩展正则表达式

取出网卡ip地址

ifconfig eth0

posted on 2017-11-16 19:55  李烨然  阅读(261)  评论(0编辑  收藏  举报