Computer Science 202
Systems Programming Concepts Using C
Lab 6 - Modified ls Command
Winter 1998

Overview

Write a C program using the GNU C Compiler (gcc) that will print to the screen the same information that is printed using the ls command with the -la option. (WITH SOME MODIFICATIONS) In this version, some of the information may be in a different format.

Specifics

Your program will receive from the command line an optional number of arguments. If no arguments are specified then your program is to print a listing of the current directory containing the following information: The above information is to be printed such that each file is listed in alphabetical order. A suitable example output would be the following:
total 68
drwx------  4  sdorney  faculty      512 Tue Aug 12 14:53:43 1997 ./
drwx------  8  sdorney  faculty      512 Mon Aug  4 12:34:30 1997 ../
-rwx------  1  sdorney  faculty     8688 Tue Aug 12 11:16:17 1997 a.out
-rw-------  1  sdorney  faculty     4729 Tue Aug 12 11:16:14 1997 dirList.c
-rw-------  1  sdorney  faculty       50 Mon Aug  4 09:22:18 1997 file.hole
-rw-------  1  sdorney  faculty      849 Mon Jul 28 10:27:46 1997 fork.c
-rw-------  1  sdorney  faculty     1126 Wed Jul 30 10:51:32 1997 forkexec.c
-rw-------  1  sdorney  faculty     1260 Mon Jul 28 10:29:36 1997 forkwait.c
lrwxrwxrwx  1  sdorney  faculty       22 Sun Aug 10 11:36:02 1997 java
-rw-------  1  sdorney  faculty     4389 Tue Aug 12 14:54:13 1997 output
-rw-------  1  sdorney  faculty      834 Tue Aug 12 14:52:03 1997 output2
drwx------  2  sdorney  faculty      512 Sun Aug 10 11:36:40 1997 sample/
-rw-------  1  sdorney  faculty     2206 Mon Aug  4 10:50:44 1997 seeker.c
drwx------  2  sdorney  faculty      512 Tue Aug 12 14:51:20 1997 stuff/
The optional argument is a pathname that indicates another directory that is to be used.

Extra Credit

The following is a list of possible additions to the above program that can be done. Any combination of these options is allowed.
  1. (3 points)Add an additional command line argument -size that indicates that the files are to be listed according to the size of the file instead of alphabetically by the file name.
  2. (3 points)If the file is a symbolic link include the pathname to the actual file. (like the following: java -> /opt/jdk1.1.2/bin/java )
  3. (3 points)If the file has executable permission, print an * after the file name.
  4. (3 points)Print the modified time value in the same format as used by the actual ls command.

Deliverables

The following must be delivered to your instructor via text-only email no later than midnight of Monday, February 23, 1998, (8th Monday).
  1. Source code for your program.
In addition, you must deliver to the instructor at the start of class (Lab) on Tuesday, February 24, 1998, (8th Tuesday) the following:
  1. A printed copy of your source code.

Notes

  1. This lab may be done in groups of two. All groups must be identified in writing no later than 7th Monday at 9am.