1. CentOS8设置中文字符集#

在使用Cent8的过程中,不能像设置Cent7的字符集那样进行下载。8的设置方式如下(亲自实践过):

1
2
3
dnf install glibc-langpack-zh.x86_64  #安装中文支持
echo LANG=zh_CN.UTF-8 > /etc/locale.conf #修改系统的字符集
source /etc/locale.conf #使立即生效

参考博客CentOS8中文支持

2. 查看Linux版本#

对于RedHat版本的linux,可以使用如下命令:

1
# cat /etc/redhat-release

结果:

1
2
[root@c071060a0213 /]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)

参考博客

3. grep的基本使用#

3.1 获取匹配模式的上下指定行数#

在平时工作中,有时候只想获取匹配模式的上面5行或下面5行,那么如何实现呢?首先看一下man手册。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# man grep
得到如下部分:
Context Line Control
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing a group separator (described under --group-separator)
between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.

-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing a group separator (described under --group-separator)
between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.

-C NUM, -NUM, --context=NUM
Print NUM lines of output context. Places a line containing a group separator (described under --group-separator) between contiguous
groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.

举例:

有一个名为testb的文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
aaaaaaaa
dddddddd
ffffffff
gggggggg
hhhhhhhh
first=before
hello
first=after
jjjjjjjj
kkkkkkkk
llllllll
qqqqqqqq
wwwwwwww
eeeeeeee
rrrrrrrr
tttttttt
yyyyyyyy
uuuuuuuu
iiiiiiii
oooooooo
pppppppp
second=before
hello
second=after
zzzzzzzz
xxxxxxxx
cccccccc
vvvvvvvv
bbbbbbbb
nnnnnnnn
mmmmmmmm

我们想要获取hello前后各一行的数据

1
2
3
4
5
6
7
8
[geneplus@bogon software]$ less testb | grep -1 'hello'
first=before
hello
first=after
--
second=before
hello
second=after

其他试用方式如下:

  • grep -5 ‘parttern’ inputfile =打印匹配行的前后5行

  • grep -C 5 ‘parttern’ inputfile =打印匹配行的前后5行

  • grep -A 5 ‘parttern’ inputfile =打印匹配行的后5行

  • grep -B 5 ‘parttern’ inputfile =打印匹配行的前5行

参考博客