The file command is used to determine the file type. This command is useful because the name of a file does not always indicate its file type. The following examples perform a long listing of a file to provide some background information on the file, and then the file command is run to show the file type. I don't cover the command used to list files until the next chapter, but I include it in these examples. The ls command provides a listing of files. ls is covered in detail in the next chapter. We need to use it in this chapter in only its basic form.. Combined with the "-l" option, you can produce a long listing that provides a lot of information about files. Using ls -l in the following examples, you will see the name of each file, file type, permissions, number of hard links, owner name, group name, size in bytes, and time stamp. You may not know what much of this information is for now; however, some of this information may be useful when viewing the output of the file command. Examples in this chapter for the file command show that different UNIX variants may produce somewhat different outputs of the file command. The following examples show an HP-UX output for the "UNIX example" and then a Linux output where available. Text File (UNIX example)(Described by the file command as ascii text .) # ls -l .mosaic-global-history -rw-r--r-- 1 201 users 587 Dec 22 1999 .mosaic-global-history # file .mosaic-global-history .mosaic-global-history: ascii text # Text File (Linux example)(Described by the file command as ASCII text .) # ls -l * -rw-r--r-- 1 root root 251367 Nov 5 07:11 debug -rw-r--r-- 1 root root 2020 Nov 5 07:11 history # file * debug: ASCII text history: ASCII text Data File (UNIX example)(Described by the file command as data .) # ls -l Static.dat -rw-r--r-- 1 201 users 235874 Aug 26 1999 Static.dat # file Static.dat Static.dat: data # Source Code File (UNIX example)(Described by the file command as c program text .) # ls -l krsort.c -rwxrwxrwx 1 201 users 3234 Nov 16 1999 krsort.c # file krsort.c krsort.c: c program text # Source Code File (Linux example)(Described by the file command as C program text .) # ls -l *.c -rw-r--r-- 1 root root 4521 Jul 12 1999 intl-bindtextdom.c -rw-r--r-- 1 root root 6234 Jul 12 1999 intl-cat-compat.c -rw-r--r-- 1 root root 14128 Jul 12 1999 intl-dcgettext.c -rw-r--r-- 1 root root 1750 Jul 12 1999 intl-dgettext.c -rw-r--r-- 1 root root 12759 Jul 12 1999 intl-finddomain.c -rw-r--r-- 1 root root 1907 Jul 12 1999 intl-gettext.c -rw-r--r-- 1 root root 1646 Jul 12 1999 intl-intl-compat.c -rw-r--r-- 1 root root 5361 Jul 12 1999 intl-loadmsgcat.c -rw-r--r-- 1 root root 7271 Jul 12 1999 intl-localealias.c -rw-r--r-- 1 root root 2914 Jul 12 1999 intl-textdomain.c # file *.c intl-bindtextdom.c: C program text intl-cat-compat.c: C program text intl-dcgettext.c: C program text intl-dgettext.c: C program text intl-finddomain.c: C program text intl-gettext.c: C program text intl-intl-compat.c: C program text intl-loadmsgcat.c: C program text intl-localealias.c: C program text intl-textdomain.c: C program text # Executable File (UNIX example)(Described by the file command as shared executable. ) # ls -l krsort -rwxr-xr-x 1 201 users 34592 Nov 16 1999 krsort # file krsort krsort: PA-RISC1.1 shared executable dynamically linked -not stripped # Executable File (LInux example)(Described by the file command as executable. ) # ls -l a* -rwxr-xr-x 1 root root 3888 Jul 24 1999 activate -rwxr-xr-x 1 root root 4452 Feb 25 1999 adjtimex # file a* activate: ELF 32-bit LSB executable, Intel 80386, version 1, stripped adjtimex: ELF 32-bit LSB executable, Intel 80386, version 1, stripped # Shell Program (UNIX example)(Described by the file command as commands text .) # ls -l llsum -rwxrwxrwx 1 root sys 1267 Feb 23 1999 llsum # file llsum llsum: commands text # Shell Program (Linux example)(Described by the file command as Bourne shell script text .) # ls -l request-route -rwx------ 1 root root 1046 Sep 19 1999 request-route # file request-route request-route: Bourne shell script text # Link (UNIX example)(The link is not referenced by the file command; this is shown as a shared executable dynamically linked . The reference to dynamically linked does not mean that this is a link.) # ls -l /usr/bin/ar lr-xr-xr-t 1 root sys 15 Mar 23 1999 ar -> /usr/ccs/bin/ar # file /usr/bin/ar /usr/bin/ar: s800 shared executable dynamically linked # Link (Linux example)(The link shown is a symbolic link .) # ls -l reboot lrwxrwxrwx 1 root root 4 Nov 5 01:31 reboot -> halt # file * grep link depmod: symbolic link to modprobe ksyms: symbolic link to insmod pidof: symbolic link to killall5 reboot: symbolic link to halt rmmod: symbolic link to insmod swapoff: symbolic link to swapon telinit: symbolic link to init udosctl: symbolic link to /sbin/umssync umssetup: symbolic link to /sbin/umssync # Block Device File (UNIX example)(Described by the file command as block special .) # ls -l /dev/dsk/c0t1d0 brw-r--r-- 1 bin sys 31 0x001000 Apr 17 1999 /dev/dsk/c0t1d0 # file /dev/dsk/c0t1d0 /dev/dsk/c0t1d0: block special (31/4096) # Block Device File (Linux example)(Described by the file command as block special .) # ls -l loop* brw-rw---- 1 root disk 7, 0 Sep 23 1999 loop0 brw-rw---- 1 root disk 7, 1 Sep 23 1999 loop1 brw-rw---- 1 root disk 7, 2 Sep 23 1999 loop2 brw-rw---- 1 root disk 7, 3 Sep 23 1999 loop3 brw-rw---- 1 root disk 7, 4 Sep 23 1999 loop4 brw-rw---- 1 root disk 7, 5 Sep 23 1999 loop5 brw-rw---- 1 root disk 7, 6 Sep 23 1999 loop6 brw-rw---- 1 root disk 7, 7 Sep 23 1999 loop7 # file loop* loop0: block special (7/0) loop1: block special (7/1) loop2: block special (7/2) loop3: block special (7/3) loop4: block special (7/4) loop5: block special (7/5) loop6: block special (7/6) loop7: block special (7/7) # Character Device File (UNIX example)(Described by the file command as character special .) # ls -l /dev/rdsk/c0t1d0 crw-r----- 1 root sys 188 0x001000 Mar 23 1999 /dev/rdsk/c0t1d0 # file /dev/rdsk/c0t1d0 /dev/rdsk/c0t1d0: character special (188/4096) # Character Device File (Linux example)(Described by the file command as character special .) # ls -l mi* crw-rw-rw- 1 root sys 14, 2 Sep 23 1999 midi00 crw-rw-rw- 1 root sys 14, 18 Sep 23 1999 midi01 crw-rw-rw- 1 root sys 14, 34 Sep 23 1999 midi02 crw-rw-rw- 1 root sys 14, 50 Sep 23 1999 midi03 crw-rw-rw- 1 root sys 14, 0 Sep 23 1999 mixer crw-rw-rw- 1 root sys 14, 16 Sep 23 1999 mixer1 # file mi* midi00: character special (14/2) midi01: character special (14/18) midi02: character special (14/34) midi03: character special (14/50) mixer: character special (14/0) mixer1: character special (14/16) # |