学习啦 > 学习电脑 > 操作系统 > Linux教程 > liunx grep命令常见用法

liunx grep命令常见用法

时间: 志艺942 分享

学习啦在线学习网liunx grep命令常见用法

  对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命令类似。接下来是小编为大家收集的liunx grep 命令常见用法,欢迎大家阅读:

  liunx grep 命令常见用法

  1.redis在make时报错

  下载解压redis-3.0.2后,执行make进行编译,结果出现下面的错误:

学习啦在线学习网   make: cc: Command not found make: *** [adlist.o] Error 127

  2.

学习啦在线学习网   这是由于新安装的Linux系统没有安装gcc环境,需要安装gcc,为了方便,这里我选择用yum进行安装。

学习啦在线学习网   # yum install gcc

  3.

  验证gcc是否安装成功

  # rpm -qa |grep gcc

  4.

  重新对redis进行编译安装

学习啦在线学习网   # make && make install

  结果又报错:

  zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory

  5.

  原因分析

学习啦在线学习网   在README 有这个一段话。

  Allocator

学习啦在线学习网   ---------

  Selecting a non-default memory allocator when building Redis is done by setting

  the `MALLOC` environment variable. Redis is compiled and linked against

学习啦在线学习网   grep 命令常见用法。首先,说明管道命令 ‘|’

学习啦在线学习网   cmd1 | cmd2

  管道命令仅会处理standard output,对于standard error output忽略;

学习啦在线学习网   管道命令必须要能够接收来自前一个命令的数据成为standard input继续处理。

学习啦在线学习网   grep就是cmd2,接受前一个命令的数据,进行选取处理。

  grep对行的选取处理功能:

学习啦在线学习网   grep [-acinv] ‘查找字符串’ filename

学习啦在线学习网   -a: 将binary文件以text文件的方式查找数据;

  -c: 计算找到 ‘查找字符串’ 的次数;

  -i: 忽略大小写的不同

  -v: 反向选择,即显示没有 ‘查找字符串’ 内容的那一行;

  –color=auto: 关键字部分加上颜色显示;

  Ex:

学习啦在线学习网   grep ‘lc’: 查找有字符串‘lc’的行

学习啦在线学习网   last | grep ‘lc’

学习啦在线学习网   last | grep -v ‘lc’

学习啦在线学习网   grep [-A] [-B] ‘搜索字符串’ filename

学习啦在线学习网   -A:后面可加数字,为after的意思。除了该行外也列出后续的n行

  -B:before的意思,除了列出该行外,前面的n行也列出来

  Ex:

学习啦在线学习网   dmesg命令可列出内核信息,-n列出行号,前面的绿色部分;最终显示所有带 ‘eth’的行.

  dmesg | grep -n -A3 -B2 ‘eth’

学习啦在线学习网   745的前2行和后3行都列出来了。

  libc

学习啦在线学习网   malloc by default, with the exception of jemalloc being the default on Linux

  systems. This default was picked because jemalloc has proven to have fewer

  fragmentation problems than libc malloc.

学习啦在线学习网   To force compiling against libc malloc, use:

学习啦在线学习网   % make MALLOC=libc

学习啦在线学习网   To compile against jemalloc on Mac OS X systems, use:

  % make MALLOC=jemalloc

  说关于分配器allocator, 如果有MALLOC 这个 环境变量, 会有用这个环境变量的 去建立Redis。

学习啦在线学习网   而且libc 并不是默认的 分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。

学习啦在线学习网   但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数。

  解决办法

学习啦在线学习网   make MALLOC=libc

  
看了“liunx grep 命令常见用法”还想看:

1.Linux下如何使用grep命令搜索多个单词

2.linux grep搜索命令的使用方法

3.讲解Linux下grep命令的使用技巧

4.15个Linux Grep命令使用实例

2991617