--- title: stat โ€” Check file metadata date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: Command that accurately checks file size, permissions, owner, creation/modification/access times, and inode. tags: program, File and disk management, stat --- **๐Ÿ’ฌ "stat command"** ls -l is a summary, while stat shows **all of a file's metadata precisely**. Use it when investigating permission, timestamp, and inode issues. In particular, distinguishing access/modification/change times (Atime/Mtime/Ctime) is important for troubleshooting. - **Concept**: Prints the file's size, inode number, link count, owner, permissions, and timestamp information. - **Access**: Last time the file was read. Because of the relatime option, it is not always updated. - **Modify**: Last time the contents changed. Most useful for judging log or deployment time. - **Change**: Time when metadata (permissions/owner) changed. - **Size / Blocks**: Logical size and actually allocated blocks. Used to check sparse files. ## Commonly used options | Option | Description | | --- | --- | | -c | Print only the fields you want in the specified format | | -f | Print filesystem information instead of file information | | --printf | Output with direct control over newlines | ## 3 essential command combinations - `stat -c '%n %s %U:%G %a' /var/www/html/index.php` โ€” Extract name, size, owner, and permissions on one line - `stat -c '%n %y' /var/log/nginx/*.log` โ€” Compare last modified time by log - `stat -f -c '%T %a %b' /` โ€” Check filesystem type and block statistics **๐Ÿ’ฌ "Show me an example of building evidence for an issue ticket"** Here are common situations on production servers, organized in order. ### Step 1 ยท Check file-level information Check the target file's permissions, owner, and timestamps. ``` stat /var/www/html/index.php ``` ### Step 2 ยท Extract only the needed fields Use formatted output when comparing multiple files. ``` stat -c '%n %U:%G %a %y' /var/www/html/*.php ``` ### Step 3 ยท Compare before and after deployment Verify that the deployment time and file modification time match. ``` stat -c '%n %y' /opt/app/current/public/index.php ``` ## How this is used in practice ### 1. Tracking down permission issues **Situation** โ€” The web server cannot read a specific file, causing a 403 error. ``` stat -c '%n %U:%G %a' /var/www/html/uploads ``` **Result** โ€” If the owner is root:root and permissions are 700, you can immediately see that www-data cannot access it. **Point** โ€” Half of 403/500 issues are permissions. Use stat to check the owner and permissions first. ### 2. Verifying deployment time **Situation** โ€” After a rollback, you need to confirm that the previous file is actually in place. ``` stat -c '%n %y' /opt/app/current/public/index.php ``` **Result** โ€” Check that the Modify time matches the rolled-back release time. **Point** โ€” If cache remains, checking time alone is not enough. Also check the link target. ## Things to watch out for - Access time is not always updated because of the relatime setting, so it is less reliable. - Symbolic links show the target file's information by default. To view the link itself, check the default behavior instead of -L. - Ctime is change time, not creation time. Some Linux filesystems do not provide creation time by default. ## Actual output This is the result of checking file owner, permissions, and timestamps, as well as log file sizes and timestamps. ![stat command output: file metadata and timestamp information](https://games.aidebatehub.com/assets/stat-demo.png) A production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/stat.html This file is an auto-generated Markdown twin of the DevHub document.