*.cรูปแบบที่ได้รับการประเมินจากเปลือกของคุณ ls *.cซึ่งจะใช้กับไดเรกทอรีปัจจุบันเช่นเดียวกับที่คุณจะใช้
ฉันคิดว่าสิ่งที่คุณต้องการคือการค้นหาไฟล์ทั้งหมดที่ตรงกับ*.cรูปแบบ (ซ้ำ) และgrepค้นหาคุณในนั้น นี่คือวิธีในการทำเช่นนั้น:
find . -name "*.c" -print0 | xargs --null grep -l search-pattern
จะใช้เพื่อผนวกผลการค้นหาโดยxargsfind
หรือใช้-execตัวเลือกในการค้นหาเช่น:
find . -name "*.c" -exec grep -l search-pattern "{}" \;
นอกจากนี้ผมไม่แน่ใจว่าถ้าคุณต้องการจริงๆตัวเลือกในการ-l grepมันจะหยุดในนัดแรก:
-l, --files-with-matches
Suppress normal output; instead print the name of each
input file from which output would normally have been
printed. The scanning will stop on the first match.
(-l is specified by POSIX.)
--include=GLOBตัวเลือก ร่วมกับตัวเลือก recursivefindนี้จะมีประสิทธิภาพมากและไม่จำเป็นต้อง ดี!