How to find out file types in Linux and Unix

There are a few tools for finding out file types in Linux and Unix. You can use file or stat, or even ls -l to display file types.

Watch Free Movies

File is better than the other tools, because it shows more details.

How to find file types:

File vs stat.
For different types of files:

$ file /etc/passwd
/etc/passwd: ASCII text
$ stat -c %F /etc/passwd
regular file

$ file samplescript.sh
samplescript.sh: Bourne-Again shell script text executable
$ stat -c %F samplescript.sh
regular file

With stat you get general information only, while file gives you more details:

$ file /bin/zsh4
zsh4: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped
$ stat -c %F /bin/zsh4
regular file

$ file /usr/bin/yum
yum: a /usr/bin/python script text executable
$ stat -c %F /usr/bin/yum
regular file

For folders:

$ file /etc/ssh
/etc/ssh: directory
$ stat -c %F /etc/ssh
directory

Scroll to Top