This is really fast :)
time find . -name \*.c | xargs wc -l | tail -1 | awk '{print $1}'
204753
real 0m0.191s
user 0m0.068s
sys 0m0.116s
Show Sample Output
draw `vmstat ` data using gnuplot
Calculating series with awk only, no need for seq: add numbers from 1 to 100
Variations:
1+3+...+(2n-1) = n^2
awk 'BEGIN {for(i=1;i<=19;i+=2)sum+=i}; END {print sum}' /dev/null # displays 100
1/2 + 1/4 + ... = 1
awk 'BEGIN {for(i=1;i<=10;i++)sum+=1/(2**i)}; END {print sum}' /dev/null # displays 0.999023
Show Sample Output
Simple MAC adrress, thanks to ifconfig.
I wasn't sure how to display the image, so I thought I'd try xml for a different twist. Show Sample Output
Only need to install Image Magick package.
Display a xkcd comic with its title and save it in /tmp directory
If you prefer to view the newest xkcd, use this command:
wget -q http://xkcd.com/ -O-| sed -n '/<img src="http:\/\/imgs.xkcd.com\/comics/{s/.*\(http:.*\)" t.*/\1/;p}' | awk '{system ("wget -q " $1 " -O- | display -title $(basename " $1") -write /tmp/$(basename " $1")");}'
Computes a columns average in a file. Input parameters = column number and optional pattern. Show Sample Output
If you use HISTTIMEFORMAT environment e.g. timestamping typed commands, $(echo "1 2 $HISTTIMEFORMAT" | wc -w) gives the number of columns that containing non-command parts per lines. It should universify this command. Show Sample Output
Splitting on tags in awk is a handy way to parse html.
If you want a sequence that can be plotted, do: seq 8 | awk '{print "e(" $0 ")" }' | bc -l | awk '{print NR " " $0}' Other bc functions include s (sine), c (cosine), l (log) and j (bessel). See the man page for details. Show Sample Output
The result of this command is a tar with all files that have been modified/added since revision 1792 until HEAD. This command is super useful for incremental releases.
seq 20 | awk '{line=line sep $0; sep=" "} !(NR%5){print line; line=sep=""}' Show Sample Output
Why use grep and awk?
to be executed from root. this works well on most commercial unix systems, have not tried on linux systems.
count connections, group by IP and port
Replace .py with .rb or .java to get the LOC of that particular filetype. An alternative is http://www.commandlinefu.com/commands/view/2812/make-a-statistic-about-the-lines-of-code Show Sample Output
If your version of curl does not support the --compressed option, use
curl -s http://funnyjunk.com | gunzip
instead of
curl -s --compressed http://funnyjunk.com
commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.
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
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: