Mittu Thomas
Mittu Thomas

Reputation: 13

How to make find . -name "*.txt" | xargs grep "text" to work with filename with spaces

find . -name "*.txt" | xargs grep "text"

fail when file name has spaces

How to make this to work with filename with spaces

Upvotes: 1

Views: 2012

Answers (2)

John1024
John1024

Reputation: 113834

This will work for all file names and it will also be slightly more efficient because it avoids the need for a pipeline:

find . -name "*.txt" -exec grep "text" {} +

Upvotes: 2

UtLox
UtLox

Reputation: 4154

try this:

find . -name "*.txt" -print0 | xargs -0 grep "text"

Upvotes: 2

Related Questions