find

फ़ाइल और डायरेक्टरी

इस्तेमाल

find [path] -name '[pattern]' -type f

डायरेक्टरी पेड़ में घूमकर हर प्रविष्टि जाँचता है; pattern को -name '*.log' की तरह quote करें, वरना shell उसे find से पहले खोल देता है।

आम विकल्प

विकल्पअर्थ
-nameMatch the file name, case sensitive; -iname ignores case
-typeRestrict to f (file), d (directory) or l (symlink)
-sizeFilter by size, as in -size +100M
-mtimeFilter by age in days, as in -mtime +7
-maxdepthLimit how deep to walk; GNU wants it before the tests
-deleteDelete every match, no confirmation
-execRun a command on each hit, ending with \; or +
-print0Separate results with NUL, to pair with xargs -0

उदाहरण

find . -name '*.log' -mtime +7 -delete

Deletes log files older than a week.

find / -type f -size +1G 2>/dev/null

Finds 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