<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>shell &#8211; 张三太爷</title>
	<atom:link href="https://www.somedoc.net/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.somedoc.net</link>
	<description>看前面，黑洞洞</description>
	<lastBuildDate>Fri, 29 May 2020 10:52:10 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>

<image>
	<url>https://www.somedoc.net/wp-content/uploads/2016/12/cropped-dandycheung-1-32x32.jpg</url>
	<title>shell &#8211; 张三太爷</title>
	<link>https://www.somedoc.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>改进 dmesg 的输出时间</title>
		<link>https://www.somedoc.net/2020/05/29/%e6%94%b9%e8%bf%9b-dmesg-%e7%9a%84%e8%be%93%e5%87%ba%e6%97%b6%e9%97%b4/</link>
					<comments>https://www.somedoc.net/2020/05/29/%e6%94%b9%e8%bf%9b-dmesg-%e7%9a%84%e8%be%93%e5%87%ba%e6%97%b6%e9%97%b4/#respond</comments>
		
		<dc:creator><![CDATA[张三太爷]]></dc:creator>
		<pubDate>Fri, 29 May 2020 10:40:59 +0000</pubDate>
				<category><![CDATA[[未分类]]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell]]></category>
		<guid isPermaLink="false">https://www.somedoc.net/?p=4509</guid>

					<description><![CDATA[dmesg 的输出里，每行开头是时间信息，通常是这样的： [ <a href="https://www.somedoc.net/2020/05/29/%e6%94%b9%e8%bf%9b-dmesg-%e7%9a%84%e8%be%93%e5%87%ba%e6%97%b6%e9%97%b4/" class="more-link">[&#8230;]</a>]]></description>
										<content:encoded><![CDATA[<p>dmesg 的输出里，每行开头是时间信息，通常是这样的：</p><pre class="crayon-plain-tag">[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct</pre><p>中括号里的值就是时间，只不过是以本次引导为基准的流逝。</p>
<p>有无办法将其显示为一目了然的时间呢？首先尝试了一下 Linux 下的人性化参数 <code>-h</code> 不对，顺便看了下帮助竟然是需要 <code>-H</code> 。加上以后输出变成了这样：</p><pre class="crayon-plain-tag">[Nov16 11:45] Initializing cgroup subsys cpuset
[  +0.000000] Initializing cgroup subsys cpu
[  +0.000000] Initializing cgroup subsys cpuacct</pre><p>隔一阵只能显示一个基准时间，之后显示为流逝偏移。要不手动加工下？按行就地编辑，<code>sed</code> 是第一联想物，先得把中括号里的内容匹配出来吧？嗯，假设要替换成一个固定字符串的话，应该是这样：<code>dmesg | sed "s/^\[[0-9.]*\]/dandy/g"</code>。然而我们的期望并非如此简单，要处理的点至少有：1. 获取到系统本次引导的基准时间；2. 把匹配到的内容与之运算；3. 将运算结果回填/输出。搜索发现，<code>awk</code> 是可行的，且有前人成果：</p><pre class="crayon-plain-tag">#!/bin/sh

uptime_ts=`cat /proc/uptime | awk '{ print $1}'`
# echo $uptime_ts
dmesg | awk -v uptime_ts=$uptime_ts 'BEGIN {
    now_ts = systime();
    start_ts = now_ts - uptime_ts;
    # print "system start time seconds: ", start_ts;
    # print "system start time: ", strftime("[%Y/%m/%d %H:%M:%S]", start_ts);
}
{
    print strftime("[%Y/%m/%d %H:%M:%S]", start_ts + substr($1, 2, length($1) - 2)), $0
}'</pre><p>最后。其实呢，<code>dmesg</code> 命令有个 <code>-T</code> 参数，可以直接输出可读的日期和时间。</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.somedoc.net/2020/05/29/%e6%94%b9%e8%bf%9b-dmesg-%e7%9a%84%e8%be%93%e5%87%ba%e6%97%b6%e9%97%b4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
