search
HomeOperation and MaintenanceLinux Operation and MaintenanceDetailed explanation of what commands are used to view logs in Linux?


This article mainly introduces the commands for viewing logs in Linux. I hope it will be helpful to friends in need!

Detailed explanation of what commands are used to view logs in Linux?

First method: View the log of real-time changes (more memory-consuming)

Most commonly used:

##

tail -f filename  (默认最后10行,相当于增加参数 -n 10)
Ctrl+c 是退出tail命令

Other situations:

##

tail -n 20 filename  (显示filename最后20行)
tail -n +5 filename  (从第5行开始显示文件)

Second type: Search logs near keywords

Most commonly used:

cat -n filename |grep "关键字"

Other situations:  

cat filename | grep -C 5 '关键字'   (显示日志里匹配字串那行以及前后5行)
cat filename | grep -B 5 '关键字'   (显示匹配字串及前5行)
cat filename | grep -A 5 '关键字'   (显示匹配字串及后5行)

Third method: Enter the editor to search: vi(vim)

1. Enter vim editing mode: vim filename

2. Enter "/keyword" and press enter to find

##3 , search for the next one, press "n" to exit: After pressing the ESC key, and then entering the : sign, vi will wait for us to enter the command at the bottom of the screen

wq! Save and exit;

q! Exit without saving;

Other situations :

/关键字
    注:正向查找,按n键把光标移动到下一个符合条件的地方
?关键字
    注:反向查找,按shift+n 键,把光标移动到下一个符合条件的

The above is the detailed content of Detailed explanation of what commands are used to view logs in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
分享Fedora工作站的屏幕截图技巧分享Fedora工作站的屏幕截图技巧Dec 31, 2023 am 08:26 AM

导读Fedora工作站附带了一个虽然简单,然而做截图却足够的工具。允许用户快速地对桌面、特定的窗口、或屏幕的任意部分进行截图。屏幕截图工具(gnome-screenshot)这个应用程序专门设计用于在桌面系统中快速捕获并保存截图。启动Screenshot在Fedora工作站中,通过在activitiesoverview中搜索screenshot来启动Screenshot。也可以在applications视图中找到(在Utilities文件夹)。Screenshot模式Screenshot有三种主

AWS 云服务清单大揭秘:71种你不知道的选择AWS 云服务清单大揭秘:71种你不知道的选择Dec 30, 2023 pm 10:59 PM

导读AWS,即亚马逊Web服务,是一个提供了一系列按使用计费的web服务的云平台。它是迄今为止最为著名的云平台之一。由于其灵活性、有效性、弹性、可测量性和无须维护,所以有一些企业正逐步把他们的业务迁移到云端。由于许多公司目前在使用这些服务,所以对于系统管理员和运维人员来说应该了解一下AWS。认识71个AWS云服务的术语!通过了解AWS世界中使用的术语开始你的AWS云服务使用生涯!计算型服务这是一个提供了虚拟服务器配置功能的服务,即所谓的云计算。它提供了包括以下这一系列的服务。EC2:EC2代表弹

利用树莓派构建一个网络存储设备的方法利用树莓派构建一个网络存储设备的方法Dec 31, 2023 am 11:53 AM

导读你有闲置的移动硬盘和树莓派吗?你可以用这些来打造一个廉价而且低能耗的NAS。最后的效果肯定比不上售价500美刀的NAS,比如SynologyDiskStation出品的那些。但可以搭建出一个低能耗的网络存储平台——而且特别适用于已经厌倦了国家安全局的数据监控的那些人,你可以把数据藏在这个“小阁楼”里。你需要一个树莓派,和一两个闲置着的移动硬盘。体积较小的2.5硬盘可以由USB接口直接供电,但是我们需要一个带有供电功能的USB分线器,因为树莓派的USB接口提供的电是不足以给移动硬盘供电的。除此

19个有趣的Linux 命令,最后一个?... 打死我都不敢尝试!19个有趣的Linux 命令,最后一个?... 打死我都不敢尝试!Aug 04, 2023 pm 04:45 PM

这些好玩的命令可以通过查 man 手册,然后在加上自己想出来的创意,改编成更多有趣的东西,哈哈,给别人捣乱也是挺好玩的

优化curl的内存分配操作优化curl的内存分配操作Dec 27, 2023 pm 02:23 PM

今天我在libcurl内部又做了一个小改动[1],使其做更少的malloc。这一次,泛型链表函数被转换成更少的malloc(这才是链表函数应有的方式,真的)。研究malloc几周前我开始研究内存分配。这很容易,因为多年前我们curl中就已经有内存调试和日志记录系统了。使用curl的调试版本,并在我的构建目录中运行此脚本:#!/bin/shexportCURL_MEMDEBUG=$HOME/tmp/curlmem.log./src/curlhttp://localhost./tests/meman

6 个“吓人”的 Linux 命令6 个“吓人”的 Linux 命令Aug 03, 2023 pm 04:33 PM

还有kill命令——当然这并不是指谋杀,而是指我们用来终止进程的命令,终止的方式有多强硬取决于需要什么来适当地终止它们。当然,Linux并不就此止步。相反,它有各种各样的kill命令来用于你的命令行。

清除 Linux/Unix/Mac 上的 DNS 查询缓存清除 Linux/Unix/Mac 上的 DNS 查询缓存Dec 30, 2023 pm 10:59 PM

导读在MS-Windows下,你可以使用ipconfig命令来清除dns缓存。然而,Linux和Unix提供了不同的方法来清除缓存。Linux可以运行nscd或者BIND或者dnsmasq作为名称服务缓存守护进程。大型或者工作组服务器可能使用BIND或者dnsmasq作为专用缓存服务器来加速查询。如何:清除nscddns缓存Nscd会缓存libc发起的名称服务的请求。如果把检索NSS数据看做很慢,那么nscd能够显著加快连续访问同一数据的速度,并能提高整个系统的性能。只需重启nscd即可刷新缓存

如何在PHP开发中使用Linux命令进行服务器管理如何在PHP开发中使用Linux命令进行服务器管理Jun 25, 2023 am 11:42 AM

随着互联网的发展,服务器管理已经成为一个日益重要的领域。在PHP开发中,使用Linux命令可以方便快捷地管理服务器,调试代码和优化性能。在本文中,我将介绍一些使用Linux命令进行服务器管理的技巧,帮助开发者更好地完成工作。一、SSH连接服务器在使用Linux命令之前,需要通过SSH连接到服务器。SSH(SecureShell)是一种安全的网络协议,用来远

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft