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/
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.
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:
Per country GET report, based on access log. Easy to transform to unique IP
Provides a much cleaner, easier to read output than the closest alternative, ls -1R. This alternative makes it easier to differentiate directories from files: find . -printf '%y %p\n' | perl -ne 'if( m/(\w) (.*)\/(.*)/ ) { $t = $1; $p = $2; $f = $3; $t =~ s/[^d]/ /; $p =~ s/[^\/]/ /g; $p =~ s/\//|/g; print "$t $p/$f\n"; } elsif( m/(\w) (.*)/ ) { print "$1 $2\n"; } else { print "error interpreting: \"$_\"\n"; }'
Dump 389ds schema, putting "\n " on one line with perl.
You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!
Dump 389ds schema, putting "\n " on one line with perl.
You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!
extract data in multiline blocks of data with perl pattern matching loop
Dump 389ds schema, putting "\n " on one line with perl.
You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!
Dump 389ds schema, putting "\n " on one line with perl.
You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!
Dump 389ds schema, putting "\n " on one line with perl.
You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!
Dump 389ds schema, putting "\n " on one line with perl.
You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!
Dump 389ds schema, putting "\n " on one line with perl.
You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!
This prints file access rights in octal - useful when "stat" is unavailable.
loop through files in .php extension
make a .bak of each of them
find the base64_decode function and remove it
People are *going* to post the wrong ways to do this. It's one of the most common form-validation tasks, and also one of the most commonly messed up. Using a third party tool or library like exim means that you are future-proofing yourself against changes to the email standard, and protecting yourself against the fact that actually checking whether an email address is valid is *not possible*.
Still, perhaps your boss is insisting you really do need to check them internally. OK.
Read the RFCs. The bet before the @ is specified by RFC2821 and RFC2822. The domain name part is specified by RFC1035, RFC1101, RFC1123 and RFC2181.
Generally, when people say "email address", they mean that part of the address that the RFC terms the "addr-spec": the "blah@domain.tld" address, with no display names, comments, quotes, etc. Also "root@localhost" and "root" should be invalid, as should arbitrary addressing schemes specified by a protocol indicator, like "jimbo@myprotocol:foo^bar^baz".
So... With the smallest poetic license for readability (allowing underscores in domain names so we can use "\w" instead of "[a-z0-9]"), the RFCs give us:
^(?:"(?:[^"\\]|\\.)+"|[-^!#\$%&'*+\/=?`{|}~.\w]+)@(?=.{3,255}$)(?:[\w][\w-]{0,62}\.){1,128}[\w][\w-]{0,62}$
Not perfect, but the best I can come up with, and most compliant I've found. I'd be interested to see other people's ideas, though. It's still not going to verify you an address fersure, properly, 100% guaranteed legit, though. What else can you do? Well, you could also:
* verify that the address is either a correct dotted-decimal IP, or contains letters.
* remove reserved domains (.localhost, .example, .test, .invalid), reserved IP ranges, and so forth from the address.
* check for banned domains (whitehouse.gov, example.com...)
* check for known TLDs including alt tlds.
* see if the domain has an MX record set up: if so, connect to that host, else connect to the domain.
* see if the given address is accepted by the server as a recipient or sender (this fails for yahoo.*, which blocks after a few attempts, assuming you are a spammer, and for other domains like rediffmail.com, home.com).
But these are moving well out of the realm of generic regex checks and into the realm of application-specific stuff that should be done in code instead - especially the latter two. Hopefully, this is all you needed to point out to your boss "hey, email validation this is a dark pit with no bottom, we really just want to do a basic check, then send them an email with a link in it: it's the industry standard solution."
Of course, if you want to go nuts, here's an idea that you could do. Wouldn't like to do it myself, though: I'd rather just trust them until their mail bounces too many times. But if you want it, this (untested) code checks to see if the mail domain works. It's based on a script by John Coggeshall and Jesse Houwing that also asked the server if the specific email address existed, but I disliked that idea for several reasons. I suspect: it will get you blocked as a spambot address harvester pretty quick; a lot of servers would lie to you; it would take too much time; this way you can cache domains marked as "OK"; and I suspect it would add little to the reliability test.
// Based on work by: John Coggeshall and Jesse Houwing.
// http://www.zend.com/zend/spotlight/ev12apr.php
mailRegex = '^(?:"(?:[^"\\\\]|\\\\.)+"|[-^!#\$%&\'*+\/=?`{|}~.\w]+)';
mailRegex .= '@(?=.{3,255}$)(?:[\w][\w-]{0,62}\.){1,128}[\w][\w-]{0,62}$';
function ValidateMail($address) {
global $mailRegex; // Yes, globals are evil. Put it inline if you want.
if (!preg_match($mailRegex)) {
return false;
}
list ( $localPart, $Domain ) = split ("@",$Email);
// connect to the first available MX record, or to domain if no MX record.
$ConnectAddress = new Array();
if (getmxrr($Domain, $MXHost)) {
$ConnectAddress = $MXHost;
} else {
$ConnectAddress[0] = $Domain;
}
// check all MX records in case main server is down - may take time!
for ($i=0; $i < count($ConnectAddress); $i++ ) {
$Connect = fsockopen ( $ConnectAddress[$i], 25 );
if ($Connect){
break;
}
}
if ($Connect) {
socket_set_blocking($Connect,0);
// Only works if socket_blocking is off.
if (ereg("^220", $Out = fgets($Connect, 1024))) {
fclose($Connect); // Unneeded, but let's help the gc.
return true;
}
fclose($Connect); // Help the gc.
}
return false;
}
handels @, ?, whitespaces in names.
replace "?" and "add" by "!" and "rm" for svn mass remove.
---> I m looking for a nicer way to write it, perhaps with something using " perl -ne '`blahblah` if /\?(.*)/' "
Commandline perl filter for, using a production.log from a rails app, display on realtime the count of requests grouped by "seconds to complete" (gross round, but fair enough for an oneliner) :)
Just want to post a Perl alternative.
Does not count hidden files ('.' ones).
- excel date compatible with a separate hour field
- added a fixed 1 for easier request counter aggregation
- split URL in directory, filename, fileext, query
- used with tomcat valve with response bytes replaced by elapsed time
This one line Perl script will display the smallest to the largest files sizes in all directories on a server.
The crypt function takes a password, key, as a string, and a salt character array which is described below, and returns a printable ASCII string which starts with another salt. It is believed that, given the output of the function, the best way to find a key that will produce that output is to guess values of key until the original value of key is found.