विशिष्ट टेक्स्ट वाली फ़ाइलों को खोजना Linux उपयोगकर्ताओं और सिस्टम administrators के लिए एक सामान्य कार्य है। चाहे आप code debug कर रहे हों, logs में खोज रहे हों, या configuration फ़ाइलों को प्रबंधित कर रहे हों, जानना
विशिष्ट टेक्स्ट वाली फ़ाइलों को खोजना Linux उपयोगकर्ताओं और सिस्टम administrators के लिए एक सामान्य कार्य है। चाहे आप code debug कर रहे हों, logs में खोज रहे हों, या configuration फ़ाइलों को प्रबंधित कर रहे हों, …
grep का उपयोग (सबसे आम तरीका)
grepcommand फाइलों में टेक्स्ट खोजने के लिए सबसे शक्तिशाली टूल है। किसी डायरेक्टरी में सभी फाइलों को recursively खोजने के लिए:
grep r search_text /path/to/directory
केस-इनसेंसिटिव खोज के लिए, यह जोड़ेंiflag:
grep ri search_text /path/to/directory
केवल फ़ाइल नाम प्रदर्शित करने के लिए बिना मैचिंग लाइनों के, उपयोग करेंl:
grep rl search_text /path/to/directory
find और grep को मिलाना

🎨 AI Generated: find और grep को मिलाना
किन files को search करना है इस पर अधिक नियंत्रण के लिए, combine करेंखोजेंके साथgrep:
find /path/to/directory type f name *.log exec grep l search_text {} ; को execute करें
यह उदाहरण केवल .log एक्सटेंशन वाली फाइलों में खोज करता है।
File Patterns के साथ grep का उपयोग
find का उपयोग किए बिना विशिष्ट फाइल प्रकारों में खोज करने के लिए:
grep r include= *.php search_text /path/to/directory
कुछ file types को exclude करने के लिए:
grep r exclude= *.min.js search_text /path/to/directory
Line Numbers और Context प्रदर्शित करना

🎨 AI Generated: Line Numbers और Context प्रदर्शित करना
उन पंक्ति संख्याओं को दिखाएं जहाँ text दिखाई देता हैn:
grep rn search_text /path/to/directory
आसपास की context lines को प्रदर्शित करेंC:
grep -rn -C 3 search_text /path/to/directory
ack या ag (The Silver Searcher) का उपयोग करना
तेज़ searches के लिए, विशेष रूप से code repositories में, विचार करेंag:
ag search_text /path/to/directory
ये tools स्वचालित रूप से version control directories और binary files को अनदेखा करते हैं।
Compressed Files में खोज करना

🎨 AI Generated: Compressed Files खोजना
उपयोग करेंzgrepgzip से compress की गई files के लिए:
zgrep search_text /path/to/files/*.gz
इन commands में महारत हासिल करने से Linux systems के साथ काम करते समय आपकी productivity में उल्लेखनीय सुधार होगा।
🚀 Tech के मामले में आगे रहें
रोज़ाना tech insights, ईमानदार reviews और व्यावहारिक guides पाएं।
✍️ Leave a Comment