Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.
Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

dmesg with colored human-readable dates

Terminal - dmesg with colored human-readable dates
dmesg -T|sed -e 's|\(^.*'`date +%Y`']\)\(.*\)|\x1b[0;34m\1\x1b[0m - \2|g'
2012-07-31 22:21:07
User: jlaunay
Functions: dmesg sed
19
dmesg with colored human-readable dates

Use sed to color the output of a human-readable dmesg output

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

With sed it's easy to choose the bash color to use ;34 here for blue.

You can also use grep to highlight the date instead of sed.

dmesg -T| grep --color "^\[.*`date +%Y`\]"

And export the GREP_COLORS variable to change the color.

ex : export GREP_COLORS="fn=34:mc=01;30:ms=33:sl=21:cx=31"

Comment by jlaunay 212 weeks and 2 days ago

dmesg -T works on my archlinux but on my debian server option -T does not exist.

You can use perl if your dmesg does not support -T :

dmesg|perl -ne "BEGIN{\$a= time()- qx!cat /proc/uptime!};s/\[\s*(\d+)\.\d+\]/localtime(\$1 + \$a)/e; print \$_;" | sed -e 's|\(^.*'`date +%Y`' \)\(.*\)|\x1b[0;34m\1\x1b[0m - \2|g'

Comment by jlaunay 212 weeks and 1 day ago

Not working on CentOS:

dmesg: invalid option -- T

Comment by dynaguy 212 weeks and 1 day ago

-T option to dmesg is available on Fedora but not RHEL5/6.

Comment by foobrew 212 weeks and 1 day ago

@dynaguy so as said on my previous comment on CentOS you should try :

dmesg|perl -ne "BEGIN{\$a= time()- qx!cat /proc/uptime!};s/\[\s*(\d+)\.\d+\]/localtime(\$1 + \$a)/e; print \$_;" | sed -e 's|\(^.*'`date +%Y`' \)\(.*\)|\x1b[0;34m\1\x1b[0m - \2|g'

If you get the error :

bash: !}: event not found

You need to turn off bash history substitution with : set +H

Comment by jlaunay 212 weeks and 1 day ago

@jlaunay I just tried on CentOS 6.3 64bit. After "set +H" there is no more error message. But your command still doesn't give time stamp.

Comment by dynaguy 212 weeks ago

Recent CentOS use rsyslog. What I did is edit /etc/rsyslog.conf, add:

kern.* /var/log/kern.log

then "service rsyslog restart"

Now you can view dmesg in file /var/log/kern.log with time/data

Comment by dynaguy 212 weeks ago

@dynaguy Good to know if I have to use CentOS one day.Thks

Comment by jlaunay 212 weeks ago

"dmesg -T" gives:

"dmesg: invalid option -- 'T'

Usage: dmesg [-c] [-n level] [-r] [-s bufsize]"

Comment by mpb 211 weeks and 6 days ago

@mpb you should have a look at the previous comments. I gave an alternative usefull on OS using a dmesg which doesn't support the -T option.

Comment by jlaunay 211 weeks and 6 days ago

@dynaguy -- no need to turn off bash history substitution. Change the bangs to ':'. The bangs are simply used as delimiters to the qx function, and were simply chosen as a character which wouldn't conflict with all of the other possible delimiters being used in the expression being quoted. Using ':' instead doesn't cause the history substitution problems...

Comment by bartonski 211 weeks and 6 days ago

@dynaguy -- no need to turn off bash history substitution. Change the bangs to ':'. The bangs are simply used as delimiters to the qx function, and were simply chosen as a character which wouldn't conflict with all of the other possible delimiters being used in the expression being quoted. Using ':' instead doesn't cause the history substitution problems...

Comment by bartonski 211 weeks and 6 days ago

dmesg |ccze -A

Comment by kxdemon 182 weeks and 3 days ago

Your point of view

You must be signed in to comment.