Linux logs a large amount of events to the disk, where they’re mostly stored in the /var/log directory in plain text. Most log entries go through the system logging daemon, syslogd, and are written to the system log.

Linux将大量事件记录到磁盘上,这些事件通常以纯文本格式存储在/ var / log目录中。 大多数日志条目都通过系统日志记录守护程序syslogd写入系统日志。

Ubuntu includes a number of ways of viewing these logs, either graphically or from the command-line. You can also write your own log messages to the system log — particularly useful in scripts.

Ubuntu提供了多种以图形方式或从命令行查看这些日志的方式。 您还可以将自己的日志消息写入系统日志-在脚本中特别有用。

以图形方式查看日志 (Viewing Logs Graphically)

To view log files using an easy-to-use, graphical application, open the Log File Viewer application from your Dash.

要使用易于使用的图形应用程序查看日志文件,请从Dash中打开“日志文件查看器”应用程序。

The Log File Viewer displays a number of logs by default, including your system log (syslog), package manager log (dpkg.log), authentication log (auth.log), and graphical server log (Xorg.0.log). You can view all the logs in a single window – when a new log event is added, it will automatically appear in the window and will be bolded. You can also press Ctrl+F to search your log messages or use the Filters menu to filter your logs.

日志文件查看器默认显示许多日志,包括系统日志(syslog),程序包管理器日志(dpkg.log),身份验证日志(auth.log)和图形服务器日志(Xorg.0.log)。 您可以在一个窗口中查看所有日志–添加新的日志事件后,该事件将自动出现在窗口中并以粗体显示。 您也可以按Ctrl + F来搜索日志消息,或使用“过滤器”菜单过滤日志。

If you have other log files you want to view – say, a log file for a specific application – you can click the File menu, select Open, and open the log file. It will appear alongside the other log files in the list and will be monitored and automatically updated, like the other logs.

如果您要查看其他日志文件(例如,特定应用程序的日志文件),则可以单击“文件”菜单,选择“打开”,然后打开日志文件。 它会与列表中的其他日志文件一起显示,并且会像其他日志一样受到监视和自动更新。

写入系统日志 (Writing to the System Log)

The logger utility allows you to quickly write a message to your system log with a single, simple command. For example, to write the message Hello World to your system log, use the following command:

logger实用程序使您可以通过一个简单的命令将消息快速写入系统日志。 例如,要将消息“ Hello World”写到系统日志中,请使用以下命令:

logger “Hello World”

记录器“ Hello World”

You may also wish to specify additional information – for example, if you’re using the logger command within a script, you may want to include the name of the script:

您可能还希望指定其他信息–例如,如果在脚本中使用logger命令,则可能要包括脚本名称:

logger –t ScriptName “Hello World”

记录器–t ScriptName“ Hello World”

在终端中查看日志 (Viewing Logs in the Terminal)

The dmesg command displays the Linux kernel’s message buffer, which is stored in memory. Run this command and you’ll get a lot of output.

dmesg命令显示Linux内核的消息缓冲区,该消息缓冲区存储在内存中。 运行此命令,您将获得大量输出。

To filter this output and search for the messages you’re interested in, you can pipe it to grep:

要过滤此输出并搜索您感兴趣的消息,可以将其通过管道传递给grep

dmesg | grep something

dmesg | grep的东西

You can also pipe the output of the dmesg command to less, which allows you to scroll through the messages at your own pace. To exit less, press Q.

您还可以将dmesg命令的输出传递给less ,这使您可以按自己的步调滚动消息。 要少退出,请按Q。

dmesg | less

dmesg | 减

If a grep search produces a large amount of results, you can pipe its output to less, too:

如果grep搜索产生大量结果,则也可以将其输出传递给以下内容:

dmesg | grep something | less

dmesg | grep的东西| 减

In addition to opening the log files located in /var/log in any text editor, you can use the cat command to print the contents of a log (or any other file) to the terminal:

除了在任何文本编辑器中打开/ var / log中的日志文件之外,您还可以使用cat命令将日志(或任何其他文件)的内容打印到终端:

cat /var/log/syslog

猫/ var / log / syslog

Like the dmesg command above, this will produce a large amount of output. You can use the grep and less commands to work with the output:

像上面的dmesg命令一样,这将产生大量输出。 您可以使用grepless命令来处理输出:

grep something /var/log/syslog

grep的东西/ var / log / syslog

less /var/log/syslog

少/ var / log / syslog

Other useful commands include the head and tail commands. head prints the first n lines in a file, while tail prints the last n lines in the file – if you want to view recent log messages, the tail command is particularly useful.

其他有用的命令包括headtail命令。 head打印文件的前n行,而tail打印文件的后n行–如果要查看最近的日志消息,tail命令特别有用。

head -n 10 /var/log/syslog

头-n 10 / var / log / syslog

tail -n 10 /var/log/syslog

尾-n 10 / var / log / syslog

Some applications may not write to the system log and may produce their own log files, which you can manipulate in the same way – you’ll generally find them in the /var/log directory, too. For example, the Apache web server creates a /var/log/apache2 directory containing its logs.

某些应用程序可能不会写入系统日志,并且可能会生成它们自己的日志文件,您可以用相同的方式对其进行操作-通常您也可以在/ var / log目录中找到它们。 例如,Apache Web服务器创建一个包含其日志的/ var / log / apache2目录。

翻译自: https://www.howtogeek.com/117878/how-to-view-write-to-system-log-files-on-ubuntu/

如何在Ubuntu上查看和写入系统日志文件相关推荐

  1. linux ./ 执行run文件,如何在Ubuntu中执行.bin和.run文件

    在解释如何在Ubuntu上执行.bin和.run文件之前,让我们首先定义这些文件扩展名到底是什么: Bin档:Ubuntu中的Binary或BIN文件指的是安装软件包,其中大多数是self-extra ...

  2. Ubuntu查看和写入系统日志

    一.背景 Linux将大量事件记录到磁盘上,它们大部分以纯文本形式存储在/var/log目录中.大多数日志条目通过系统日志守护进程syslogd,并被写入系统日志. Ubuntu包括以图形方式或从命令 ...

  3. 如何在Mac上查看系统日志

    如何在Mac上查看系统日志 Mac会保留系统日志,这有助于诊断和解决macOS和已安装应用程序的问题. 这些日志作为纯文本日志文件存储在Mac的系统驱动器上,macOS还包括一个用于查看它们的应用程序 ...

  4. linux+usb刻录,如何在Ubuntu上安装Etcher-开源USB刻录机工具

    如何在Ubuntu上安装Etcher-开源USB刻录机工具 Mark Do 2017年5月20日 暂无评论 阅读 4,988 次 Etcher是一款跨平台的USB镜像文件写入工具,在Windows.m ...

  5. 如何在Ubuntu上安装MariaDB

    We can install MariaDB on Ubuntu from the Ubuntu repositories or the official MariaDB repositories. ...

  6. 如何在Ubuntu上安装OnlyOffice Docs 7.1?

    如何在Ubuntu上安装OnlyOffice Docs 7.1? 什么是OnlyOffice Docs? OnlyOffice Docs是一套在线办公软件,可以打开阅读并编辑文档.表格和幻灯片文件,完 ...

  7. linux卸载kodi,如何在Ubuntu上安装Kodi 18 Beta

    Kodi的Beta版周期很长.很棒,因为它有助于将错误排除在生产版本之外,而且还可以保留数月的新功能.值得庆幸的是,Kodi开发人员提供了可供测试和使用的"unstable"软件包 ...

  8. 如何在Ubuntu上使用MultiSystem创建多启动USB盘

    如何在Ubuntu上使用MultiSystem创建多启动USB盘 介绍 也许还有不少人不知道MultiSystem,它是一个用来在Linux系统中创建多启动usb盘的小型的开源软件.使用这个工具,我们 ...

  9. pip安装deb_技术|如何在 Ubuntu 上安装 pip

    pip 是一个命令行工具,允许你安装 Python 编写的软件包. 学习如何在 Ubuntu 上安装 pip 以及如何使用它来安装 Python 应用程序. 有许多方法可以在 Ubuntu 上安装软件 ...

最新文章

  1. selenium 操作 html 5,[Selenium] WebDriver 操作 HTML5 中的 video
  2. 的app抓包 ssl_抓包旧版App
  3. xs_run加密还原
  4. iOS-AFNetworking参数和多文件同时上传【多文件上传】
  5. java golang速度_golang思考之运行速度
  6. vim之添加多行和删除多行
  7. 华为云Volcano:让企业AI算力像火山一样爆发
  8. ubuntu18机器学习环境安装基于anaconda
  9. Android雁翎刀之ImageView之定制头像
  10. php手机网页_使用PHPCMS搭建wap手机网站
  11. Flash CS4 Professional 10.0.2简体中文版下载地址
  12. 在取证过程中,常见的一些注册表键值整理
  13. 计算机网络素质拓展心得体会范文,计算机网络培训心得体会范文(通用4篇)...
  14. Xubuntu22.04装有道词典:报错has unexpected type “float“(一百四十一)
  15. 【和UI斗智斗勇的日子】如何实现一个类似哈罗单车APP主页打车模块的卡片式切的View
  16. 鼓励与信任让人变得更强大
  17. Mysql 条件查询(like、between、and、in······)
  18. 1789: 高精度A+B
  19. 吕泉高维智慧创始人:17年心灵修行与素食·造就冻龄女神
  20. C语言数据的输入输出

热门文章

  1. 注入双括号报错注入_SQL手动注入:sqlilabs(less110)
  2. ttl继承逻辑门的逻辑功能与参数测试 实验总结_LMS电声测试仪,LMS-V测试系统,精声电声...
  3. 微信接口请求次数_接口签名验证常用方案
  4. 突然讨厌做前端,讨厌代码_为什么用户讨厌重新设计
  5. 前端 Offer 提速:如何写出有亮点的简历
  6. 找出无序数组中最小的k个数(top k问题)
  7. 用maven profile实现环境配置切换
  8. 【转】知道这20个正则表达式,能让你少写1,000行代码
  9. code point,code unit
  10. 多功能复合机基于用户认证功能的实现过程详解