file and stat command in Linux are used for viewing file related information. file command displays the type of a file. stat command is a useful for viewing file or file system status.

File Command

The syntax for the Linux file command is as follows:

file [OPTION] FILE

It can take one or more file names as its arguments. This command reports the file type in human readable format. To view the mime type of a file pass the -i option. It also accepts wildcard characters in the file name.

Below example demonstrate the usage of this command.

file command example

Last command in the above example uses wild card to find details of all the files having .txt extension.

Stat Command

The syntax for the Linux stat command is as follows:

stat [OPTION] FILE

Below example shows default output from the stat command. Basic information such as size, file type, Inode information, Number of links, Access, Modification and Change date and time stamps are displayed.

stat command example

To view information that relates to a file system, pass the -f parameter followed by a filesystem.

stat -f /

Certain files may have one or more symbolic links, to enable stat to follow links, use the -L parameter.