What does the file command do and what is stat?
Answer
file filename determines and displays the type of a file by examining its content (magic bytes), not just its extension. It correctly identifies scripts, executables, images, compressed archives, and text files: file script.sh → Bourne-Again shell script, ASCII text executable. This is valuable when file extensions are missing or misleading. stat filename displays detailed inode information: file size in bytes, number of blocks, permissions in octal, owner/group UID/GID, inode number, number of hard links, and all three timestamps — access time (atime), modification time (mtime, when content changed), and change time (ctime, when metadata changed).
Previous
How do echo and printf work in bash?
Next
How do head and tail work for viewing file portions?