Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We like to search many directories in a Windows environment with cygwin. We tried find . -name *.txt -print

but it complains the -print predicate. What is the correct command then ?

We only want matched files printed to console.

Thanks all

share|improve this question
add comment

1 Answer 1

It is complaining because you have not quoted the *.txt so the shell is expanding the pattern instead of passing it to find. In other words, let's say you are in a directory that contains these files:

 foo.txt bar.txt baz.txt

When you say find . -name *txt -print the wildcard (*) is expanded by the shell (bash probably) so what is passed to ffindis actually:

find . -name foo.txt bar.txt baz.txt -print

That's too many arguments and find complains. To get what you want, you need to quote the pattern you a re searching for (you also don't need the -print for what you are doing):

 find . -name "*txt"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.