DistributedNetworks DistributedNetworks

Special File Types   «Prev  Next»
Lesson 5 Determining file types
Objective Use the ls -F and the File Commands to identify File Types.

Use ls -F and the File Commands to identify File Types

UNIX systems have two commands for conveniently identifying the types of files you may encounter.

ls -F

The first useful command is the -F option to the ls command. This option lists the files in a directory, with a different flag for each type of file. For example:
$ ls -F $HOME
nmap@  readme*  subdir/  temp/

Notice that ls -F flags the different types of files:
  1. Directory (/)
  2. Executable (*)
  3. Symbolic link (@)
Many people find this option to the ls command so convenient that they use it automatically, in conjunction with other options. For example:
$ ls -lF
total 3
drwx-wx-wx  3 user1  user1  810 Jun 7 19:46 nmap
-rwx-wx--x  1 user1  user1    0 Jun 7 19:32 readme*
dr-xr-xr-x  2 user1  user1 1024 Jun 7 19:40 subdir/
drwx------  3 user1  user1 1024 Jun 7 19:49 temp/

The file command

The second useful command is the file command, which provides even more information about file types. The syntax for the file command is
file file1 [file2 ....]
Here is an example of using the file command on the same directory we used the ls –F command:
$ file $HOME/*
/home/user1/nmap:   symbolic link to /dev/nmap
/home/user1/readme: empty
/home/user1/subdir: directory
/home/user1/temp:   directory

The file command applies a series of rules to determine the file type. Some of the more common types of files detected by the file command are text files, source code files, executable files, and directories. Here is another example, showing information about several other file types:

$ file /dev/*
/dev/MAKEDEV:    Bourne shell script text
/dev/audio:      character special (14/4)
/dev/bpcd:       block special (41/0)
/dev/cdrom:      symbolic link to hdb
/dev/console:    character special (4/0)
/dev/log:        socket
/dev/addftinfo:  ELF 32-bit LSB executable,
Intel 80386, version 1, dynamically
linked, stripped
/dev/apache_1.3.3.tar.gz: gzip compressed data,
deflated, original filename, last modified:
Wed Oct  7 02:50:59 1998, max compression,
os: Unix