1. 查询文件中的关键字并高亮显示【查询当前目录关键字为elasticsearch的日志文件】

find ./ -name "my-elasticsearch.log" | xargs grep --color=auto "elasticsearch"

2. 查看日志文件后100行

tail -100f log_file.log

3. 另外一种查询关键字log的方法

grep -rn "二狗子" /logs/web.log --color

4. 查询并打印;匹配行之前和之后各2行

grep -rn '' web.log --color -C 

5. 搜索压缩包里面的日志文件

zcat /logs/log.--.log.gz | grep '' --color

或者

zgrep --color '' /logs/log.--.log.gz

满足多个条件查询

# 同时满足多条件
zcat /logs/log.--.log.gz | grep 'A' | grep 'B' --color
zgrep 'A' /logs/log.--.log.gz | grep 'B' --color

满足任一条件

# 满足任一条件
zcat /logs/log.--.log.gz | grep -E 'A|B|C' --color
zgrep --color -E 'A|B|C' /logs/log.--.log.gz

6. 对接外部路由,用telnet查看地址通不通

# 目标地址是ip
$ telnet -b [本机地址] [目标地址] # 目标地址是url,不要带http://
$ telnet -b [本机地址] xxx.api.com
Trying xxx.xx.xx.xxx...
Connected to xxx.api.com.
Escape character is '^]'.

7. 统计特定字符出现次数

grep 'key' app.log | wc -l

8. grep和zgrep定义

================grep================
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c Regexp selection and interpretation:
-E, --extended-regexp PATTERN is an extended regular expression (ERE)
-F, --fixed-strings PATTERN is a set of newline-separated fixed strings
-G, --basic-regexp PATTERN is a basic regular expression (BRE)
-P, --perl-regexp PATTERN is a Perl regular expression
-e, --regexp=PATTERN use PATTERN for matching
-f, --file=FILE obtain PATTERN from FILE
-i, --ignore-case ignore case distinctions
-w, --word-regexp force PATTERN to match only whole words
-x, --line-regexp force PATTERN to match only whole lines
-z, --null-data a data line ends in byte, not newline Miscellaneous:
-s, --no-messages suppress error messages
-v, --invert-match select non-matching lines
-V, --version print version information and exit
--help display this help and exit
--mmap ignored for backwards compatibility Output control:
-m, --max-count=NUM stop after NUM matches
-b, --byte-offset print the byte offset with output lines
-n, --line-number print line number with output lines
--line-buffered flush output on every line
-H, --with-filename print the filename for each match
-h, --no-filename suppress the prefixing filename on output
--label=LABEL print LABEL as filename for standard input
-o, --only-matching show only the part of a line matching PATTERN
-q, --quiet, --silent suppress all normal output
--binary-files=TYPE assume that binary files are TYPE;
TYPE is `binary', `text', or `without-match'
-a, --text equivalent to --binary-files=text
-I equivalent to --binary-files=without-match
-d, --directories=ACTION how to handle directories;
ACTION is `read', `recurse', or `skip'
-D, --devices=ACTION how to handle devices, FIFOs and sockets;
ACTION is `read' or `skip'
-R, -r, --recursive equivalent to --directories=recurse
--include=FILE_PATTERN search only files that match FILE_PATTERN
--exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN
--exclude-from=FILE skip files matching any file pattern from FILE
--exclude-dir=PATTERN directories that match PATTERN will be skipped.
-L, --files-without-match print only names of FILEs containing no match
-l, --files-with-matches print only names of FILEs containing matches
-c, --count print only a count of matching lines per FILE
-T, --initial-tab make tabs line up (if needed)
-Z, --null print byte after FILE name Context control:
-B, --before-context=NUM print NUM lines of leading context
-A, --after-context=NUM print NUM lines of trailing context
-C, --context=NUM print NUM lines of output context
-NUM same as --context=NUM
--color[=WHEN],
--colour[=WHEN] use markers to highlight the matching strings;
WHEN is `always', `never', or `auto'
-U, --binary do not strip CR characters at EOL (MSDOS)
-u, --unix-byte-offsets report offsets as if CRs were not there (MSDOS) `egrep' means `grep -E'. `fgrep' means `grep -F'.
Direct invocation as either `egrep' or `fgrep' is deprecated.
With no FILE, or when FILE is -, read standard input. If less than two FILEs
are given, assume -h. Exit status is if any line was selected, otherwise;
if any error occurs and -q was not given, the exit status is .
================zgrep================
Usage: /usr/bin/zgrep [OPTION]... [-e] PATTERN [FILE]...
Look for instances of PATTERN in the input FILEs, using their
uncompressed contents if they are compressed. OPTIONs are the same as for 'grep'.

生产环境Linux常用命令【随时更新】的更多相关文章

  1. Linux常用命令--不断更新

    Linux命令: !. 1.[root@loc8lhost/root]# 表示登陆进去系统,其中#是超级⽤用户也即root⽤用 户的系统提示符 #. 2.reboot命令可以重启系统 $. 3.关闭系 ...

  2. Linux常用命令——持续更新(2018-05-09)

    此命令默认是在centos环境下执行,除非特殊标明. 1.查看ip: ifconfig 2.创建指定用户并分配到某个组:创建用户user并分配到root组 useradd -g root user 3 ...

  3. 【Linux常用命令(更新)】

    1.ifconfig:查看当前ip,网卡信息 2.df -h:查看文件系统的使用情况,挂载点信息 3.du -sh  /var:查看/var文件夹大小 4.netstat -a:查看网络联机状态 5. ...

  4. Linux常用命令(持续更新中)

    cd 目录名 :进入某个目录 ls :列出当前目录的内容 locate 文件名/目录名:寻找文件.目录 find 目录名1 -name 文件名/目录名2 :在目录1中寻找目录2 whereis  文件 ...

  5. Git常用命令 - 随时更新

    1. 配置用户信息 git config --global user.name <name> git config --global user.email <email_addres ...

  6. linux常用命令[持续更新]

    top 察看系统状态,退出按q ps -A 察看所有进程 ps -A|grep gcalc|awk '{print $1}'|xargs kill 杀掉所有gcalc进程

  7. Linux常用命令(更新)

  8. [转帖]linux常用命令大全(linux基础命令入门到精通+实例讲解+持续更新+命令备忘录+面试复习)

    linux常用命令大全(linux基础命令入门到精通+实例讲解+持续更新+命令备忘录+面试复习) https://www.cnblogs.com/caozy/p/9261224.html 总结的挺好的 ...

  9. 0、驱动及应用小技巧、uboot指令及环境变量配置、linux常用命令

    (内核make menuconfig之后,通过insmod安装的驱动都应该重新make,可能会出现一些莫名的问题) (nor flash/SDRAM/DM9000都受内存控制器控制,需要配置内存控制器 ...

随机推荐

  1. spring boot 获取bean

    在写测试用例的时候,如果是springboot的应该加上 springboot的标签: @SpringBootTest(classes = ApplicationLoader.class) @Acti ...

  2. 为什么int型最大的数是2147483647

    32位的电脑中,用二进制表示,最大的就是32个1,用十进制表示为2^32-1,大概40多亿(4294967295) 对于有符号的,第一位用作表示正负(0,1),最大的就是31个1,用十进制表示为2^3 ...

  3. DotNetty 实现 Modbus TCP 系列 (一) 报文类

    本文已收录至:开源 DotNetty 实现的 Modbus TCP/IP 协议 Modbus TCP/IP 报文 报文最大长度为 260 byte (ADU = 7 byte MBAP Header ...

  4. codeforces 1065F Up and Down the Tree

    题目链接:codeforces 1065F Up and Down the Tree 题意:给出一棵树的节点数\(n\)以及一次移动的最大距离\(k\),现在有一个标记在根节点1处,每一次可以进行一下 ...

  5. day2 网络基础

    网路基础 网络OSI模型七层: 物理层: 定义特性:机械,电器,功能,过程: 定义接口标准:双绞线,光纤,同轴电缆: 相关协议:无: 数据链路层: 定义帧的开始结束,封装成帧,差错校验,透明传输(防止 ...

  6. MT【276】正切的半角公式

    若$\Delta ABC$满足:$\tan\dfrac{A}{2}\cdot\tan\dfrac{C}{2}=\dfrac{1}{3},b=\dfrac{4}{3}a$,则$\sin B=$_____ ...

  7. LGP2801 教主的魔法

    题目链接 : P2801 教主的魔法 这是第一次A分块的题 就是模板题了 每个块内排序 每个整块仅需维护整块的修改量 询问操作: 对于边缘块 直接暴力找在[l, r]内 且比给定值大的有几个 对于整块 ...

  8. Atcoder 乱做

    最近感觉自己思维僵化,啥都不会做了-- ARC103 F Distance Sums 题意 给定第 \(i\) 个点到所有点的距离和 \(D_i\) ,要求构造一棵合法的树.满足第 \(i\) 个点到 ...

  9. emwin 存在多个窗口时,如何获取当前所在窗口

    @2019-02-20 [小记] emwin存在多个窗口时,如何获取当前所在窗口 > emwin 之获取当前窗口的一种方法 [需求] 用于在代码中获知当前呈现的是哪个窗口 [方法] 进入新窗口将 ...

  10. 「SCOI2014」方伯伯的商场之旅 解题报告

    「SCOI2014」方伯伯的商场之旅 我一开始的想法会被两个相同的集合位置去重给搞死,不过应该还是可以写的,讨论起来老麻烦. 可以先钦定在\(1\)号点集合,然后往后调整一部分. 具体一点,通过前缀和 ...