PrintLogo

Embedding Text in Find Output




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!



This article comes from NetAdminTools:
http://www.netadmintools.com/

The URL for this story is:
http://www.netadmintools.com/art500.html

Copyright 1997-2008 NetAdminTools.com. Read our Terms of Use.