Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with C in UNIX environment

Status
Not open for further replies.

zskater

Programmer
Apr 14, 2001
22
GB
I am having trouble with my uni homework , I have been reading through my books but cannot find the information i need.
I dont know the code for obtaining file information
We have to write the program in C running on UNIX machines

Im hoping someone can point me to a relevent web site where i can find information I need OR if anyone else has had to write this program or like it can you please help

The following is the homework description:

Implement a utility called recent that will scan a specified directory tree and list all files that match specified criteria.The program is to be invoked as follows:
recent [ path ] [option... ]

The first argument, path should specify the name of the directory at the root of the tree to be searched.If this argument is omitted, recent should search the tree rooted in the current directory "."
There may be several option arguments,in the following formats
-d List the file if its age in days is less than the
given integer
-s List the file only if its size in bytes is greater than the given integer

-u List the file only if it is owned by a user whose username is "string"

when several option expressions are present only those files that satisfy all specified critera should be listed.Note that the user may specify more than one option of the same kind on the command line;

Files should be listed with pathnames relative to the root directory specified in the command line

If recent is invoked with niether a path nor any options, it should list all of the files in the tree rooted in the current directory, "."

In addition to writting out the file name, if a -d option is given on the command line then the age of the file in days should also be written out; if an -s option - size of file in bytes should be printed and if -u option is given the user name of the owner of the file should also be written out.
 
Unix has a tool implemented "find".

This tool can do everything you need.

It is not neccessary to write C-Code. About 10 Lines shellscript will do it.
hnd
hasso55@yahoo.com

 
I have almost finished writting this now , my problem is I cant find how to access the users name who created each file in a directory
I know using ls -l can tell you this but Im not accessing it from the command line

For finding the size of the files and the times they were last modified I have been using stbuf.st_size and stbuf.st_mtime
both from stat.h

In stat.h there is information for getting UID and GID but I cant find anything for the actual name (string format)

Can anyone help

Cheers Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top