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.shBourne-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).