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

stimits at comcast.net stimits at comcast.net
Tue Mar 24 15:59:32 MDT 2015


Hi,
 
I have the need to encode directory contents via base64 for a large number of files and directories. One choice is to produce one long string of file names and then later do the base64 encoding, separating each file name out of the string one at a time. This is easy, but very very slow in bash. Two other possibilities are to combine find with xargs -L 1 or with exec...and have the base64 be called on individual files. The base64 command itself handles random strings when provided by a pipe; unfortunately, there is no command line option to use base64 directly on standard input without pipes and echo.
 
For a quick demo, one can do this minimal example of find without encoding to base64:
find / -mindepth 1 -maxdepth 1 -type d -exec echo '{}' \;
 
Or:
find / -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -L 1 
So far though I've been unable to pipe this through base64 one file at a time; piping the whole string through base64 gives one long encoding and I need individual encodings for each file name. Something like this is needed, but fails:
find / -mindepth 1 -maxdepth 1 -type d -print0 | `xargs -0 -L 1 | base64`
 
Anyone here know how to use pipes with find and xargs or exec sending to base64 on a per file basis?
 
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20150324/6a03436d/attachment.html>


More information about the LUG mailing list