如何在Ubuntu上查看和寫入系統日志文件

image

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中打開“日志文件查看器”應用程序。

image

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來搜索日志消息,或使用“過濾器”菜單過濾日志。

image

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.

如果您要查看其他日志文件(例如,特定應用程序的日志文件),則可以單擊“文件”菜單,選擇“打開”,然后打開日志文件。 它會與列表中的其他日志文件一起顯示,并且會像其他日志一樣受到監視和自動更新。

image

寫入系統日志 (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”

image

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”

image

在終端中查看日志 (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內核的消息緩沖區,該消息緩沖區存儲在內存中。 運行此命令,您將獲得大量輸出。

image

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 | 減

image

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

image

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/

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/279206.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279206.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279206.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[轉]table中設置tr行間距

原文地址:https://blog.csdn.net/itmyhome1990/article/details/50475616 CSS border-collapse 屬性設置表格的邊框是否被合并為一個單一的邊框 值描述separate默認值。邊框會被分開。不會忽略 border-spacing 和 empty-cells 屬性。collapse如果可能,邊框會合并為一…

向Ubuntu提供反饋的5種方法

Ubuntu, like many other Linux distributions, is a community-developed operating system. In addition to getting involved and submitting patches, there are a variety of ways you can provide useful feedback and suggest features to Ubuntu. 與許多其他Linux發行版…

Tomcat 發布項目 conf/Catalina/localhost 配置 及數據源配置

本文介紹通過在tomcat的conf/Catalina/localhost目錄下添加配置文件,來發布項目。因為這樣對 tomcat 的入侵性最小,只需要新增一個配置文件,不需要修改原有配置;而且支持動態解析,修改完代碼直接生效(修改配置除外)。在…

Centos7 中文亂碼

1. 安裝中文庫 yum groupinstall "fonts" 2. 檢查是否有中文語言包 locale -a 3. 查看當前系統語言環境 locale 解析如下 LANG:當前系統的語言LC_CTYPE:語言符號及其分類LC_NUMERIC:數字LC_COLLATE:比較和排序習慣LC_TIME&#xff…

pkpm板按彈性計算還是塑性_雙向板按彈性方法還是按塑性方法計算

雙向板按彈性方法還是按塑性方法計算茅老師您好!想請教您個問題,PKPM計算雙向板時一般都是按彈性算吧,可我去年剛進設計院的時候有一個項目是按塑性算的,這樣影響大不大啊,支座與跨中彎矩比值系數取得默認的1.8&#x…

chrome自動退出的原因_Chrome 70將讓用戶選擇退出新的自動登錄功能

chrome自動退出的原因An upcoming Chrome option allows users to log into Google accounts without logging into the browser. The change was prompted by a backlash among users and privacy advocates. 即將推出的Chrome選項允許用戶無需登錄瀏覽器即可登錄Google帳戶。…

學習筆記DL007:Moore-Penrose偽逆,跡運算,行列式,主成分分析PCA

2019獨角獸企業重金招聘Python工程師標準>>> Moore-Penrose偽逆(pseudoinverse)。 非方矩陣,逆矩陣沒有定義。矩陣A的左逆B求解線性方程Axy。兩邊左乘左逆B,xBy。可能無法設計唯一映射將A映射到B。矩陣A行數大于列數,方程無解。矩…

mysql40題_mysql40題

一、表關系請創建如下表,并創建相關約束導入現有數據庫數據:/*Navicat Premium Data TransferSource Server : localhostSource Server Type : MySQLSource Server Version :50624Source Host : localhostSource Database : sqlexamTarget Server Type :…

ubuntu取消主目錄加密_如何在Ubuntu上恢復加密的主目錄

ubuntu取消主目錄加密Access an encrypted home directory when you’re not logged in – say, from a live CD – and all you’ll see is a README file. You’ll need a terminal command to recover your encrypted files. 當您未登錄時(例如,從實時CD)訪問加密…

select 和epoll模型區別

1.select 和epoll模型區別 1.1.網絡IO模型概述 通常來說,網絡IO可以抽象成用戶態和內核態之間的數據交換。一次網絡數據讀取操作(read),可以拆分成兩個步驟:1)網卡驅動等待數據準備好(內核態&…

python數據結構與算法第六講_Python 學習 -- 數據結構與算法 (六)

棧 是一種 “操作受限”的線性表,只允許在一端插入和刪除數據。從功能是上來說,數組和鏈表確實可以替代棧,但是特定的數據結構是對特定場景的抽象,而且,數組或鏈表暴露了太多的操作接口,操作上的確靈活自由…

spring-springmvc code-based

idea設置maven在下載依賴的同時把對應的源碼下載過來。圖0:1主要實現零配置來完成springMVC環境搭建,當然現在有了springBoot也是零配置,但是很多同仁都是從spring3.x中的springMVC直接過渡到springBoot的,spring3.x的MVC大部分都…

powershell 入門_使用PowerShell入門的5個Cmdlet

powershell 入門PowerShell is quickly becoming the preferred scripting language and CLI of Power Users as well as IT Pros. It’s well worth learning a few commands to get you started, so we’ve got 5 useful cmdlets for you to learn today. PowerShellSwift成為…

Part 3: Services

介紹 在第3部分中,我們將擴展應用程序并啟用負載平衡。為此,我們必須在分布式應用程序的層次結構中提升一個級別:服務。 StackServices (你在這里)Container (涵蓋在第2部分中)關于服務 在分布式應用程序中,應用程序的不同部分被稱為“服務”…

mysql ldf文件太大_Linux_數據庫清除日志文件(LDF文件過大),清除日志: 復制代碼 代碼如 - phpStudy...

數據庫清除日志文件(LDF文件過大)清除日志:復制代碼 代碼如下:DECLARE LogicalFileName sysname,MaxMinutes INT,NewSize INTUSE szwzcheck -- 要操作的數據庫名SELECT LogicalFileName szwzcheck_Log, -- 日志文件名MaxMinutes 10, -- Limit on time allowed to …

emwin之錯誤使用控件函數導致死機現象

2018-10-15 導致死機的代碼示例如下 1 /**2 * brief widget ID define3 * {4 */5 6 #define ID_WINDOW_0 (GUI_ID_USER 0x00)7 #define ID_TEXT_0 (GUI_ID_USER 0x01)8 #define ID_TEXT_1 (GUI_ID_USER …

diy感應usb攝像頭拍照_DIY無線感應充電器

diy感應usb攝像頭拍照Courtesy of Instructables user Inducktion shares a very detailed tutorial on how to build a wireless power charger. He explains the impetus behind the project: 由Instructables用戶提供Inducktion分享了有關如何構建無線電源充電器的非常詳細…

ubuntu7.10安裝到3D開啟

累了好幾天,重裝了十幾遍終于把ubuntu7.10搞定到了我自認為完美的狀態了。現在總結一下安裝過程(按操作順序記錄):1.在xp下不管用pqmajac還是其他硬盤分區工具分出10G的空余分區來(實驗階段10G嘗試下)&…

初學者對python的認識_Python初學者列表,python,初識

1.認識列表列表可以放入所有我們目前學習過的數據類型,甚至包括列表2.有關列表的方法、內置函數(設列表的名稱為list)向列表中添加元素:append():list.append(要添加的元素),注意每次只能添加一個元素,被添加的元素自動…

常用模塊之 time,datetime,random,os,sys

time與datetime模塊 先認識幾個python中關于時間的名詞: 時間戳(timestamp):通常來說,時間戳表示的是從1970年1月1日00:00:00開始按秒計算的偏移量。我們運行“type(time.time())”,返回的是float類型。1970年之前的日期無法以此表…