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.

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 Bourne-Again shell script text executable
$ stat -c %F
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

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *


Support LinuxG via Patreon
Support on Patreon!


Subscribe to get the latest Linux news and how to guides directly on your e-mail!