grep the command-line-fu archive

clgrep keyword
Sample Output
view this page source to copy perl command.

====================
== make alias

$ cat alias.txt # this line is too long to post Command-line-fu
perl -MHTML::Form -MLWP::UserAgent -e'$a=LWP::UserAgent->new;push@{$a->{requests_redirectable}},"POST";$u="http://www.commandlinefu.com/commands/browse";$f=HTML::Form->parse($a->get($u)->content,$u);$f->value(q=>join" ",@ARGV);for($a->request($f->click)->content=~m!<div class="one-liner">(.+?)(?=<div class="one-liner">|</html>)!sg){($s)=m!<div class="summary".+?>(.+?)<!s;($_)=m!<div class="command">\s*(.*?)<!s;s/</</g;s/>/>/g;s/"/"/g;s/&/&/g;print"### $s\n$_\n\n";++$n>7&&last}'

$ alias clgrep=`cat alias.txt`

====================
== grep the archive about "backup"

$ clgrep backup
### quickly backup or copy a file with bash
cp filename{,.bak}

### infile search and replace on N files (including backup of the files)
perl -pi.bk -e's/foo/bar/g' file1 file2 fileN

### backup directory. (for bash)
cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bash

$ 

====================
== grep the archive about "wget"

$ clgrep wget
### Download all images from a site
wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" http://example.com/images

### Extract tarball from internet without local saving
wget -qO - "http://www.tarball.com/tarball.gz" | tar zxvf -

### Echo the latest commands from commandlinefu on the console
wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/code>/, d);print d[1]"\n"} '

### Get My Public IP Address
wget -qO - http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'

$


====================
== grep recently posted

$ clgrep 
### Launch an Explorer window with a file selected
explorer /select,[file]

### Search specified $TEXT1 and Replace that by specified arg ($TEXT2)
find "$DIR" -regex "$FILENAME" -type f -print0 | xargs -0 sed -i _`date "+%y%m%d%H%M%S"` -E "s/$TEXT1/$TEXT2/g"

### count IPv4 connections per IP
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | sed s/::ffff:// | cut -d: -f1 | sort | uniq -c | sort -n

$

-1
By: wbx
2009-02-15 11:45:28

These Might Interest You

What Others Think

How do I install clgrep ?
Antoine · 483 weeks and 5 days ago
1st) view html source. 2nd) copy alias.txt. 3rd) alias clgrep=`cat /path/to/alias.txt`
wbx · 483 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

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.

Share Your Commands



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: