stat
In this page:
stat
stat reports detailed metadata about a file, including size, permissions, and timestamps, more comprehensively than ls -l. Its exact output format differs slightly between Linux and macOS, but the core information it exposes is the same. It's often used in scripts that need to check things like file size or modification time programmatically.
Note: Use stat -c %s file on Linux to get just the file size in bytes, suitable for capturing in a variable.
Example: stat
#!/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"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: