Check Linux File Type and File Format using file Command and ls Command


Using ls command to show file type.


   The Linux operating system using the file type to identify and check its file format.  The simple way to check the file type of any files on Linux system is using the ls command and file command.  The example below demonstrate the use of the ls command and the file command to identify Linux file type.


Note:  On the file permission section, the first character indicates the file type:

    -     <=    Linux regular file

    d    <=    Linux directory

    b    <=    Linux block special file

    c    <=    Linux character special file

    l    <=    Linux symbolic link

    p    <=    Linux named pipe

    s    <=    Linux domain socket


The ls command with -l option as show the file in long list format including the file type, file permission and other Linux file properties as show on Linux command example below:

show Linux regular file using ls command

[root@fedora ~]# pwd


[root@fedora ~]# ls -l install.log

-rw-r--r-- 1 root root 72032 2008-05-20 08:25 install.log

[root@fedora ~]#


ls command output:

dash indicate Linux regular file format


Example on using ls command to display the block special file:

Display Linux block special file format using ls command

[root@fedora ~]# ls -l /dev/sda

brw-r----- 1 root disk 8, 0 2008-10-30 02:28 /dev/sda

[root@fedora ~]#


ls command output:

b indicate Linux block special file format


Using the file command to find Linux file type.


The Linux file command usually use to find out the Linux file type.  The file command example below demonstrate the use of Linux file command to show the type of Linux file on Linux Fedora 9 machine.


Show the file type for install.log file ( regular file ) using file command:

using file command to display regular file type

[root@fedora ~]# pwd


[root@fedora ~]# file install.log

install.log: ASCII Pascal program text

[root@fedora ~]#


Show the file type for /dev/sda device file ( block special file ) using file command:

Display Linux block special file format

[root@fedora ~]# file /dev/sda

/dev/sda: block special (8/0)

[root@fedora ~]#


Keywords: find file type, show file type, show Linux file type, check Linux file type, Linux file format, find Linux file type, ls command, file command