On 03/09/2016 12:43, meino.cra...@gmx.de wrote:
> Joerg Schilling <joerg.schill...@fokus.fraunhofer.de> [16-09-03 12:28]:
>> <meino.cra...@gmx.de> wrote:
>>
>>> Hi,
>>>
>>> I want to 'locate' a bunch of files and feed the output into 
>>> '| xargs md5sum'.
>>> Unfortunately some of them are infected with the "file name"-virus
>>> (space in the filename).
>>> With find there is the -print0 option which corresponds to '-0' of
>>> the xargs options. As of my knowledge, locate does not have such 
>>> a thing.
>>
>> This is one of the reasons, why POSIX did not include -print0, as it would 
>> need 
>> to add new related options to an unknown amount of other programs.
>>
>> Another reason of curse is that "find . -exec cmd {} +" exists longer than 
>> GNU 
>> find and it's -print0. Execplus was added on 1989 by David Korn.
>>
>> Jörg
>>
>> -- 
>>  EMail:jo...@schily.net                    (home) Jörg Schilling D-13353 
>> Berlin
>>        joerg.schill...@fokus.fraunhofer.de (work) Blog: 
>> http://schily.blogspot.com/
>>  URL:  http://cdrecord.org/private/ 
>> http://sourceforge.net/projects/schilytools/files/'
>>
> 
> 
> ...and how does it solve my problem?

In several ways.

locate may or may not be up to date as it runs on a cron.
find OTOH tells you what files you really have right now.

Your objection to find IMHO is not really valid. It doesn't read all the
files, it simply reads all the *directories* and grabs the dentries for
the files from there. As you intend using locate, all you need is the
names and so find has no need to touch any file inodes it finds at all.
[ -mtime can really slow things down, but you won't be doing that ]

Do it once and even if you repeat the find many times in succession, all
the data find needs is now in RAM so it's not much more expensive than
locate.

So with that in mind there's no reason to not use find, then you get all
the -print0 goodness that you *really* need.

The alternative is to struggle endlessly with bash quoting rules to get
quotes around your filenames and quote the arguments to md5sum. Or some
magic with awk (all of which is many many times more cpu work than your
objection to find)

So use find :-)


-- 
Alan McKinnon
alan.mckin...@gmail.com


Reply via email to