[lfs-support] Using 'find' to Help Make Package Users Simpler

Pierre Labastie pierre.labastie at neuf.fr
Wed Oct 16 13:15:12 PDT 2013


Le 16/10/2013 20:43, Dan McGhee a écrit :
> [...]
> 
> Here's the find statement:
> <find / -xdev -type d -gid $(id -g <packageuser name>) \! -path /usr/src 
> \! -path /tools -print>
> 
> This statement achieves all the parameters stated above with the 
> addition that it ignores /tools also.  Now I would like to change group 
> ownership and permissions and redirect the output to installdirs.lst.  I 
> know I could do that using an intermediate file:
> 
> find > tmpfile
> chown $(cat tmpfile)
> chmod $(cat tmpfile)
> tmpfile >> installdirs.lst
> rm tmpfile
> 
> But, and here's the real question of this post, can I do this with one 
> statement?  Here's my first idea:
> 
> 'find' | 'chown' | 'chmod' >> installdirs.lst
I do not know if chown can read standard input. If it would, the first pipe would work. But
the second will never work, since it takes the output off the chown command, not that of find...
> 
> Or, can I use more than one -exec option in 'find'? The statement would 
> look something like this
> 
> find (stuff) -exec chown :install {} \; -exec chmod ug=rwx, o=rxt {} \; 
>  >> installdirs.lst
> 
> The reason I'm asking this question is that one of my references says 
> "[-exec] will execute the program once per file while xargs can handle 
> several files with each process."  I've never been successful with xargs 
> and I don't know if 'find' will, then ignore the second -exec.  I 
> haven't been able to glean anymore from wandering around on the internet 
> and wading through man pages.
> 
> I have "piped" the output of find only once many times, but I don't know 
> if the output would survive two pipes.
> 
> I guess that it's just one question after all.  Can I use "chained" 
> pipes or -execs before I redirect?
> 
I've never tried two -exec directives in find, sorry. What I know is that xargs is more flexible,
and I recommand that you insist on having it work.
It could be something similar to:
find... -print| xargs -I xxx sh -c 'chmod xxx; chown xxx; echo xxx >> installdirs.lst'
more robust:
find... -print0 | xargs -0 -I xxx sh -c 'chmod xxx; chown xxx; echo xxx >> installdirs.lst'

Good luck
Pierre



More information about the lfs-support mailing list