← Back to Bash Course | Chapter 9: File Testing & Filesystem | Lesson 7 of 13

find कमांड

find घर के हर room में एक scavenger hunt जैसा है। आप describe करते हैं कि आप क्या ढूंढ रहे हैं, जैसे इसका name या type, और यह आपके लिए सभी folders search करता है।

In this page:

  1. find Command
Syntax
bash
find directory -name "pattern" -type f|d

find Command

find name, type, या modification time जैसे criteria से match करने वाली files और directories के लिए एक directory tree search करता है। find . -name "*.txt" current directory को recursively .txt से खत्म होने वाली files के लिए search करता है।

यह nested directory structures search करने के लिए simple globbing से कहीं ज़्यादा powerful है।

Note: find . -name "*.log" -mtime -1 पिछले एक दिन में modify की गई .log files ढूंढता है — log cleanup scripts के लिए great।

उदाहरण: The find Command

bash
#!/bin/bash
mkdir -p search_demo
touch search_demo/a.txt search_demo/b.log search_demo/c.txt

find search_demo -name "*.txt"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Patterns को quote करना भूल जाना, जैसे find . -name *.txt, जिसे shell पहले expand करती है।
  2. Options को गलत order में रखना, जैसे tests के बाद -maxdepth, जो एक warning देता है।
  3. -exec को \; या + से end किए बिना उपयोग करना।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.