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

stat कमांड

stat एक file पर library card के details पढ़ने जैसा है: यह कितनी बड़ी है, कौन इसे उपयोग कर सकता है और इसे last कब touch किया गया था। यह ls से मिलने वाले quick look से ज़्यादा दिखाता है।

In this page:

  1. stat
Syntax
bash
stat file_name

stat

stat एक file के बारे में detailed metadata report करता है, size, permissions, और timestamps शामिल, ls -l से ज़्यादा comprehensively।

इसका exact output format Linux और macOS के बीच थोड़ा अलग है, लेकिन core information जो यह expose करता है वही है। यह अक्सर उन scripts में उपयोग होता है जिन्हें file size या modification time जैसी चीज़ें programmatically check करनी हों।

Note: Linux पर stat -c %s file उपयोग करें सिर्फ file size bytes में पाने के लिए, जो एक variable में capture करने के लिए suitable है।

उदाहरण: stat

bash
#!/bin/bash
echo "some sample content" > info.txt

stat info.txt

size=$(stat -c %s info.txt 2>/dev/null || stat -f %z info.txt)
echo "File size in bytes: $size"
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. यह मानना कि stat के Linux और macOS पर same options हैं, क्योंकि format flags अलग हैं।
  2. Spaces वाले file names के आस-पास quotes भूल जाना।
  3. Modification time (content बदला) को change time (metadata जैसे permissions बदले) के साथ confuse करना।
चैप्टर सारांश
  • -f, -d, और -e जैसे File tests जांचते हैं कि files और directories मौजूद हैं या नहीं और वे क्या हैं।
  • Reading, writing, appending, और line-by-line processing file contents handle करते हैं, और globbing file names match करता है।
  • find, cp, mv, rm, directory operations, permissions, और stat filesystem manage करते हैं।

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.