span.fullpost {display:inline;}

Friday, July 18, 2008

Embedding Text in Find Output

For exemple We recently did a migration of large files to another server, and needed to create a bunch of redirect commands to point at the new location. This turned out to be quite easy with find. First, we need to find the files over 570K:

find . -size +570k -printf '%k %p\n'

The quotes after printf include both text and variables. %k is the size in K, and %p is the relative path of the file. The output looks like this:

1484 ./files/bigfile.exe
4148 ./files/biggerfile.exe
.
.
.



To copy these files into a single folder:

find . -size +570k -exec cp {} /placetostore/files/ \;

To create redirect statements suitable for httpd.conf:

find * -size +570k -printf 'Redirect permanent /%p http://new.example.com/%f\n'

The output looks something like this:

Redirect permanent /files/bigfile.exe http://new.example.com/bigfile.exe

The cool thing we didn't know was that you could embed text in the output of find. This made our job quite easy in this case, even easier than Perl!

0 comments:

Tutorialsland By - Templates4all | Free Blogger and web Templates
Free Website templatesFree Flash TemplatesFree joomla templatesSEO Web Design AgencyMusic Videos OnlineFree Wordpress Themes Templatesfreethemes4all.comFree Blog TemplatesLast NewsFree CMS TemplatesFree CSS TemplatesSoccer Videos OnlineFree Wordpress ThemesFree Web Templates