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!
Categories
- GNU/Linux (20)
- Linux Security (12)
- Ubuntu Tutorials (20)
- Web Browsers (1)
- Windows 2000 (20)
- Windows 2003 (13)
- Windows 7 (8)
- Windows Vista (43)
- Windows XP (54)
Bookmark us
Friday, July 18, 2008
Embedding Text in Find Output
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment