[lug] Using Pipes w/ find exec Or find xargs

stimits at comcast.net stimits at comcast.net
Tue Mar 24 16:48:42 MDT 2015


...

> Just to make sure we're all trying to solve the same problem, could you post the easy bash solution?
 
The concept is easy, the actual code under bash is a bit of a nightmare since file names and symbolic links and their targets can contain any kind of whitespace or control characters. The "easy" version comes down to using find with printf to insert a record separator character (hex 0x1E) between each unquoted file/directory/link name; this results in a huge string which can be iterated over 1 character at a time, building file names until the 0x1d is encountered. At this point the name is echoed through a pipe to base64 -wrap=0, and stored as an associative array key...the value is taken from slicing and dicing of ls -ld. In the case of symbolic links the slicing and dicing results in an extra parameter which is the base64 encoding of the link target. End result: One array base64 key which bash works well with, and an attribute for the value (permissions, ownership, major/minor numbers, link dereferences, hard file checksums).
 
Profiling shows that producing the initial find string is fairly quick, but looping through it one character at a time to build file names from it costs exponentially more as the string grows. Bash does not have pointers or iterators, so referencing a character at index 1000 isn't bad...referencing one at index 100,000 is terrible; each character extracted this way is in a loop from 0 to n. Cutting large strings into smaller strings helps, but trimming the low order indices of large strings also goes up exponentially as string size grows. Ahh, my kingdom for a pointer or iterator!

FYI, bash is necessary for portability reasons across architectures and to possibly have "snippets" placed in related bash software.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20150324/084e331c/attachment.html>


More information about the LUG mailing list