find
फ़ाइल और डायरेक्टरी
इस्तेमाल
find [path] -name '[pattern]' -type fडायरेक्टरी पेड़ में घूमकर हर प्रविष्टि जाँचता है; pattern को -name '*.log' की तरह quote करें, वरना shell उसे find से पहले खोल देता है।
आम विकल्प
| विकल्प | अर्थ |
|---|---|
| -name | Match the file name, case sensitive; -iname ignores case |
| -type | Restrict to f (file), d (directory) or l (symlink) |
| -size | Filter by size, as in -size +100M |
| -mtime | Filter by age in days, as in -mtime +7 |
| -maxdepth | Limit how deep to walk; GNU wants it before the tests |
| -delete | Delete every match, no confirmation |
| -exec | Run a command on each hit, ending with \; or + |
| -print0 | Separate results with NUL, to pair with xargs -0 |
उदाहरण
find . -name '*.log' -mtime +7 -deleteDeletes log files older than a week.
find / -type f -size +1G 2>/dev/nullFinds files over a gigabyte, hiding permission errors.
find . -name '*.jpg' -exec mv {} photos/ +Moves every JPEG it finds.
हटाना, मिटाना और ढूँढना। कुछ कमांड दोबारा नहीं पूछते, इसीलिए -i लगाने की आदत हाथ बचाती है।
कैसे पढ़ें
- बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
- तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
- विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।
आम सवाल
Q. find क्या करता है?
डायरेक्टरी पेड़ में घूमकर हर प्रविष्टि जाँचता है; pattern को -name '*.log' की तरह quote करें, वरना shell उसे find से पहले खोल देता है।
Q. इसे कैसे लिखें?
find [path] -name '[pattern]' -type f — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।
Q. कितने विकल्प जानने लायक़ हैं?
यहाँ 8 दिए हैं; पूरी सूची man find में है। यह कमांड फ़ाइल और डायरेक्टरी में आती है।
मिलती-जुलती कमांड
man पेज: man find