long string using find and "-exec ls -ls" to find part-of filename

Matthew Seaman m.seaman at infracaninophile.co.uk
Mon Jun 30 06:23:54 UTC 2014


On 30/06/2014 06:48, Gregory Orange wrote:
>>     yup.  then WHY O WHY O WHY doesnt this work::
>>     find . -name "foo.t*" |xargs ls -lsi
>>     work?  is it only my memory [[delusional] that made me think that
>>     "foo.t*" expanded into your cmd string??  I thought the "*"
>>     expanded into what you have to save the hacker typing/keystrokes.
> 
> Curiously your command line works for me on both an Ubuntu (sh, bash)
> machine and a FreeBSD (sh, bash, csh, tcsh) machine. I would have
> expected the shell to expand * to and cause find to return an error, but
> it appears not. Perhaps it depends on the shell? It works for me on the
> shells listed above.

No -- it's find(1) that does the globbing expansion there.  That's why
you need to put quote marks around the wildcard term; to stop the shell
trying to process it.  The shell is irrelevant.

One reason this sort of command may not work as expected is if you're
outputing filenames with spaces or other characters of syntactic
significance to the shell.  If you have those sorts of filenames, the
solution is:

   find . -name "foo.t*" -print0 | xargs -0 ls -lsi



-- 
Dr Matthew J Seaman MA, D.Phil.

PGP: http://www.infracaninophile.co.uk/pgpkey
JID: matthew at infracaninophile.co.uk

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1036 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20140630/aba04d41/attachment.sig>


More information about the freebsd-questions mailing list