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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged log from sorted by
Terminal - Commands tagged log - 35 results
awk '/^--- Day changed (.*)/ {st=""; for (i=0;i<ar[date];i++) {st=st"*"} print date" "st; date=$7"-"$5"-"$6} /> emergency/ {ar[date]++} END {st=""; for (i=0;i<ar[date];i++) {st=st"*"}; print date" "st}' #engineyard.log
2010-02-24 22:54:34
User: menicosia
Functions: awk
0

This awk command prints a histogram of the number of times 'emergency' is the first word in a line, per day, in an irssi (IRC client) log file.

zcat access_log.*.gz | awk '{print $7}' | sort | uniq -c | sort -n | tail -n 20
argv=("$@"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest`
2009-10-16 17:36:16
User: lassel
Functions: less
Tags: bash less log grep
1

Really useful way to combine less and grep while browsing log files.

I can't figure out how to make it into a true oneliner so paste it into a script file called lgrep:

Usage:

lgrep searchfor file1 [file2 file3]

Advanced example (grep for an Exception in logfiles that starts with qc):

lgrep Exception $(find . -name "qc*.log")

echo $(date +%s) > start-time; URL=http://www.google.com; while true; do echo $(curl -L --w %{speed_download} -o/dev/null -s $URL) >> bps; sleep 10; done &
2009-09-19 21:26:06
User: matthewbauer
Functions: date echo sleep
9

This will log your internet download speed.

You can run

gnuplot -persist <(echo "plot 'bps' with lines")

to get a graph of it.

perl -F' ' -MDate::Format -pale 'substr($_, index($_, $F[1]), length($F[1]), time2str("%C", $F[1]))' file.log
2009-08-13 13:57:33
Functions: perl
Tags: perl log
2

When you have one of those (log)files that only has epoch for time (since no one will ever look at them as a date) this is a way to get the human readable date/time and do further inspection.

Mostly perl-fu :-/

ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
2009-07-22 14:44:41
User: kanaka
Functions: ls sudo tail xargs
Tags: bash tail log watch
5

This command finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files.

Alternately, you can do this to follow a specific list of log files:

sudo tail -n0 -f /var/log/{messages,secure,cron,cups/error_log}

grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
2009-06-17 19:41:04
User: miketheman
Functions: grep
6

Using the grep command, retrieve all lines from any log files in /var/log/ that have one of the problem states

svn log -v -r{2009-05-21}:HEAD | awk '/^r[0-9]+ / {user=$3} /yms_web/ {if (user=="george") {print $2}}' | sort | uniq
2009-06-05 14:07:28
User: jemptymethod
Functions: awk sort
Tags: svn awk log
3

just change the date following the -r flag, and/or the user name in the user== conditional statement, and substitute yms_web with the name of your module

tail -f logfile.log | cut -b 1-80
2009-03-26 18:41:57
User: plasticboy
Functions: cut tail
Tags: tail log
3

This truncates any lines longer than 80 characters. Also useful for looking at different parts of the line, e.g. cut -b 50-100 shows columns 50 through 100.

tail -f *[!.1][!.gz]
2009-03-06 16:24:44
User: piscue
Functions: tail
5

with discard wilcards in bash you can "tail" newer logs files to see what happen, any error, info, warn...