NetAdminTools.com
 
SignalQ Sites:
L1G3R Information Systems - Coprolite - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - FixRambler
Solar Energy - Energy Efficiency - Solar Panels
Home Energy Savings
Categories:
GNU/Linux | Homebrew designs | Perl | Ruby | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | ERP | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Ruby
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·ERP
·REALbasic
·All Categories


Embedding Text in Find Output
Topic:GNU/Linux   Date: 2006-01-16
Printer Friendly: Print   

spacerspacer
<<  <   >  >>

Subject

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!


People:
Places:
Things:
Times:





Please read our Terms of Use and our Privacy Policy
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2011 NetAdminTools.com