File Types


A file is a means by which information is stored on a UNIX system. The commands you issue, the applications you use, the data you store, and the devices you access, such as printers and keyboard, are all contained in files. One aspect of UNIX that makes it both simple and complex: simple because you know that everything out there is a file, complex because the contents of a file could be anything ranging from ASCII text files to executable programs.

Every file on the system has a filename. The operating system takes care of all file-system - related tasks ; you just need to know the name of the file and how to use it. Many types of files are on UNIX systems. Some file types are peculiar to the UNIX variant you are using. Device files, for instance, contain information about the specific hardware platform on which you are running your UNIX variant. In general, however, most file types are similar going from system to system. The file types we will look at are:

  • Text Files

  • Data Files

  • Source Code Files

  • Executable Files

  • Shell Programs

  • Links

  • Device Files

Many times when dealing with various types of files, there are extensions associated with the files. Many applications, for instance, associate a specific extension with that application. Text files, for instance, sometimes have a .txt extension. Most C source code programs have a .c extension, and most C++ programs have a .cc extension. Although the extension can be useful for determining the type of a file, no written requirements state that a particular type of file must contain an assigned extension or that you must have any extension at all.

The following table shows some commonly used extensions for various types of files:

Extension

File Type

.1 to . n

Online manual source.

.a

An archive or library.

.c

C program source.

.cc

C++ program source.

.csh

C shell script.

.f

FORTRAN program source.

.ksh

Korn shell script.

.o

Object file of compiled source.

.ps

Postscript source.

.shar

Shell archive.

.sh

Bourne shell script.

.tar

tar archive.

.txt

ASCII text file.

.Z

Compressed file.

A useful technique for determining the file type is to use the file command. Most UNIX variants support the file command, although the outputs differ somewhat, so I suggest that you use the file command to determine file type. The best way to learn about file types and the file command is through example, which we'll do later in this chapter after discussing some common file types in more detail.

Text Files

What could be simpler than a file that contains characters, just like the ones you're now reading in this chapter? These ASCII characters are letters and numerals that represent the work you perform. If, for instance, you use a UNIX editor to create an electronic mail message or a letter, you are creating a text file in most cases. Here is an example of part of an ASCII text file from a Linux system:

[View full width]
 
[View full width]
Thu Nov 5 07:29:53 1999 debug: FTS: appending '/dev/hda1' Thu Nov 5 07:29:53 1999 debug: FTS: appending '/tmp/LST/swap.sel' Thu Nov 5 07:29:53 1999 debug: Building partition-list with argument <Linux> Thu Nov 5 07:29:53 1999 debug: Respecting exclude file /tmp/LST/targets.sel: /dev/hdd /dev/hda1 /dev/hda2 Thu Nov 5 07:29:53 1999 debug: No ADDITIONAL partitions available Thu Nov 5 07:29:59 1999 debug: added '8390' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added '8390' to '/root/etc/modules/2.0.29/#1 Tue Feb 11 graphics/ccc.gif 20:36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: added 'scsi_mod' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added 'scsi_mod' to '/root/etc/modules/2.0.29/#1 Tue Feb graphics/ccc.gif 11 20:36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: added 'sd_mod' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added 'sd_mod' to '/root/etc/modules/2.0.29/#1 Tue Feb 11 graphics/ccc.gif 20:36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: added 'sr_mod' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added 'sr_mod' to '/root/etc/modules/2.0.29/#1 Tue Feb 11 graphics/ccc.gif 20:36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: added 'st' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added 'st' to '/root/etc/modules/2.0.29/#1 Tue Feb 11 20: graphics/ccc.gif 36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: added 'sg' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added 'sg' to '/root/etc/modules/2.0.29/#1 Tue Feb 11 20: graphics/ccc.gif 36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: added 'nfs' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added 'nfs' to '/root/etc/modules/2.0.29/#1 Tue Feb 11 20: graphics/ccc.gif 36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: added 'isofs' to '/root/tmp/modules.handled' Thu Nov 5 07:29:59 1999 debug: added 'isofs' to '/root/etc/modules/2.0.29/#1 Tue Feb 11 graphics/ccc.gif 20:36:48 MET 1997.default' Thu Nov 5 07:29:59 1999 debug: 'isofs' is already handled Thu Nov 5 07:29:59 1999 debug: 'nfs' is already handled Thu Nov 5 07:29:59 1999 debug: 'sg' is already handled Thu Nov 5 07:29:59 1999 debug: 'st' is already handled

Data Files

A file that contains data used by one of your applications is a data file. If you use a sophisticated desktop publishing tool such as FrameMaker to write a book, you create data files that FrameMaker uses. These data files contain data, which you can usually read, and formatting information, which you can sometimes read but is usually hidden from you. If your UNIX installation uses a database program, then you may have data files that you can partially read.

Source Code Files

A source code file is a text file that contains information related to a programming language such as C, C++, Pascal, FORTRAN, and so on. These files are readable - at least to the programmer who wrote them. When a programmer develops a source code file, they create a file that conforms to the naming convention of the program language being used, such as adding a ".c" to the end of the file if creating a C program.

The following is an example of a C source code file:

 /* this is K & R sort program */ # include <stdio.h> # include <stdlib.h>        int N;        int v[1000000];        /* v is array to be sorted */        int left = 0;          /* left pointer */        int right;        int swapcount, comparecount = 0;                               /* count swaps and compares*/         int i, j, t;        char print;        char pr_incr_sorts; main() {    printf("Enter number of numbers to sort : ");    scanf("%10d", &N);                    /* 10d used for a BIG input */    printf ("\n");                            /* select type of input to sort */    printf("Enter rand(1), in-order(2), or reverse order (3)    sort : ");    scanf("%2d", &type);    printf ("\n");                        /* select type of input to sort */    if (type == 3)                 for (i=0; i<N; ++i)      /* random        */                       v[i] = (N - i);    else if (type == 2)                 for (i=0; i<N; ++i)                       v[i]= (i + 1);        /* in order      */    else if (type == 1)                 for (i=0; i<N; ++i)                       v[i]=rand();          /* reverse order */    fflush(stdin);    printf("Do you want to see the numbers before sorting (y or n)? : ");    scanf("%c", &print);    printf ("\n");                        /* View unsorted numbers?  */    if (print == 'y')       {             printf ("\n");          for (i=0; i<N; ++i)             printf("a[%2d]= %2d\n", i, v[i]);             printf ("\n");       }       fflush(stdin);      printf("Do you want to see the array at each step as it sorts? (y or n)? : ");       scanf("%c", &pr_incr_sorts);       printf ("\n");                      /* View incremental sorts?   */          right = N-1;                     /* right pointer            */                     qsort(v, left, right);       {          fflush(stdin);          printf ("Here is the sorted list of %2d items\n", N);              printf ("\n");          for (i=0; i<N; ++i)              printf ("%2d\n ", v[i]);              printf ("\n");              printf ("\n");                /* print sorted list        */                    }                         printf ("number of swaps = %2d\n ", swapcount);                         printf ("number of compares = %2d\n ", comparecount);        }    /* qsort function */              void qsort( v, left, right)                           int v[], left, right;        {                    int i, last;                    if (left > right)                     return;                    swap(v, left, (left + right)/2);                    last = left;                    for (i=left+1; i <= right; i++)                    {                       comparecount = ++comparecount;                         if (v[i] < v[left])                    swap(v, ++last, i);                    }                    swap(v, left, last);                    qsort(v, left, last-1);                    qsort(v, last+1, right);                   }                   /* swap function  */                    swap(v, i, j)                       int v[], i, j;                       {int temp;                          swapcount = swapcount++;                          temp = v[i];                          v[i] = v[j];                          v[j] = temp;   if (pr_incr_sorts == 'y')      {                    printf("Incremental sort of array = ");         printf ("\n");         for (i=0; i<N; ++i)            printf("a[%2d]= %2d\n", i, v[i]);            printf ("\n");      } } 

Executable Files

Executable files are compiled or interpreted programs that can be run. You can't read executable files, and you'll typically get a bunch of errors, unreadable characters, and beeps from your UNIX system when you try to look at one of these. You may also lose your screen settings and cause other problems.

You don't have to go far in UNIX to find executable files, they are everywhere. Many of the UNIX commands you issue are executable files that you can't read. In addition, if you are developing programs on your system, you are creating your own executables.

Here is an example of what you see if you attempt to send an executable to the screen:

 unknown/etc/ttytyperunknown<@=><@=>:unknown<@=> callocLINESCOLUMNSunknownPackaged for argbad aftger%3 parmnumber missing <@=><@=>: @ @ 3### @@@A:2TTO>@#<2X00R EraseKillOOPS<@=><@=>: <@=><@=>: <@=><@=>:<@=>ATOO<@=>:<@=><@=>:<@=><@=>:<@=><@=>: 

Shell Programs

A shell program is both a file that you can run to perform a task and a file that you can read. So yes, even though you can run this file because it is executable, you can also read it. I'm going to describe shell programming in more detail in Chapter 28.

I consider shell programming to be an important skill for every user to have. I'll spend some time going over the basics of shell programming. Some of the background I'm about to cover relating to file types and permissions is important when it comes to shell programming, so this is important information for you to understand.

Here is an example of part of a shell program that performs an audit of a system:

 #!/bin/sh { echo "PROG>>>>> determining if Ignite-UX loaded on system." igtest='swlist   grep Ignite' echo $igtest if [ -n "$igtest" ]; then echo "Ignite-UX installed" else echo "Ignite-UX is not installed" fi echo "PROG>>>>> determining if make_recovery has been run by              checking for /var/opt/ignite/arch.include." if [ -f /var/opt/ignite/recovery/arch.include ]; then echo "make_recovery has been run." else echo "make_recovery has not been run." fi echo "PROG>>>>> determining if make_recovery was run with the              -C (for check_recovery) option." if [ -f /var/opt/ignite/recovery/makrec.last ]; then echo "make_recovery with -C has been run. We'll now              run check_recovery." /opt/ignite/bin/check_recovery 2>&1 else echo "make_recovery with -C has not been run. We can't              run check_recovery." fi }   tee -a /tmp/IMPORTANT/igtest.out 

The shell program is text you can read and modify if indeed you have permission to do so. In addition to programming information, shell programs contain comments indicated by lines beginning with a # .

Links

A link is a pointer to a file stored elsewhere on the system. Instead of having two or more copies of a file on your system, you can link to a file that already exists on your system.

One particularly useful way that links have been used in UNIX is related to new releases of the operating system. The locations of files sometimes change going from one release to another, and rather than learn all the new locations, links are produced from the old location to the new one. When you run a command using the old location, the link points to the new location.

Links are also useful for centralizing files. If a set of identical files has to be updated often, it is easier to link to a central file and update it, rather than having to update several copies of the file in several different locations.

Device Files

Device files, sometimes called device special files , contain information about the hardware connected to your system. Because device special files are associated with system administration functions, they are usually not covered much in user, as opposed to system administration, material. I think the situation should be otherwise . It is very frustrating for a user to want to write a file to a floppy disk or a tape and not have any idea how to access a device file. I'll cover some use of device files so you are not completely in the dark in this area.

Devices on your system can often be accessed with different device files. A disk, for instance, can be accessed with either a block device file or a character device file. Most of this access is the responsibility of your system administrator; however, when you attempt to determine the file type, you may encounter special files of different types such as character and block.

Other types of files are on your system as well, but for the purposes of getting started with UNIX, the file types I will describe supply sufficient background to get you started.



HP-UX 11i Systems Administration Handbook and Toolkit
HP-UX 11i Systems Administration Handbook and Toolkit (2nd Edition)
ISBN: 0131018833
EAN: 2147483647
Year: 2003
Pages: 301

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net