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

Orion Poplawski orion at cora.nwra.com
Tue Mar 24 16:28:26 MDT 2015


On 03/24/2015 03:59 PM, stimits at comcast.net wrote:
> 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?

What do you have against pipes and echo?

find / -mindepth 1 -maxdepth 1 -type d -print | while read x; do echo $x |
base64; done


-- 
Orion Poplawski
Technical Manager                     303-415-9701 x222
NWRA, Boulder/CoRA Office             FAX: 303-415-9702
3380 Mitchell Lane                       orion at nwra.com
Boulder, CO 80301                   http://www.nwra.com


More information about the LUG mailing list