Hi All,
I thank you for the very quick answer to:
James Sainsbury and
J.A. Gutierrez
o James sugested to make c program using the stat() function. or using the
gnu ls which is part of fileutils which has this command:
% ls -l --full-time passwd
-rw-r--r-- 1 root root 858 Tue Jan 30 14:55:36 2001 passwd
o Mr. Gutierrez even give me the C source code to do it:
.c------------------------------------------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <errno.h>
main( int argc, char **argv)
{
struct stat sbp;
int f;
int isdevice=0;
struct passwd *pw;
struct group *gr;
char *name;
int error=0;
if ( argc == 1 )
{
fprintf(stderr,"Use: %s filename(s)\n",argv[0]);
exit(1);
}
for( f=1; f<argc; f ++)
{
printf("\n\tName:\t%s\n",argv[f]);
if ( stat(argv[f],&sbp)==-1)
{
perror("stat");
error++;
}
else
{
switch (sbp.st_mode & S_IFMT)
{
case S_IFIFO:
fprintf(stdout,"\t\tnamed pipe
(fifo)\n");
break;
case S_IFCHR:
fprintf(stdout,"\t\tcharacter
special\n");
isdevice=1;
break;
case S_IFDIR:
fprintf(stdout,"\t\tdirectory\n");
break;
case S_IFBLK:
fprintf(stdout,"\t\tblock
special\n");
isdevice=1;
break;
case S_IFREG:
fprintf(stdout,"\t\tregular\n");
break;
case S_IFLNK:
fprintf(stdout,"\t\tsymbolic
link\n");
break;
case S_IFSOCK:
fprintf(stdout,"\t\tsocket\n");
break;
default:
fprintf(stdout,"\t\tunknown\n");
break;
}
if (isdevice)
fprintf(stdout, "Device number:%d,%d\n",
(sbp.st_rdev>>8) & 0xff,
sbp.st_rdev & 0xff );
fprintf(stdout, "Resides on device:%d,%d\n",
(sbp.st_dev>>8) & 0xff,
sbp.st_dev & 0xff);
fprintf(stdout, "I-node: %d; Links: %d;
Size: %ld\n",
sbp.st_ino, sbp.st_nlink,
sbp.st_size);
if (( pw=getpwuid(sbp.st_uid))==NULL)
name="???";
else
name=pw->pw_name;
fprintf(stdout, "Owner ID: %d; Name: %s\n",
sbp.st_uid, name);
if (( gr=getgrgid(sbp.st_gid))==NULL)
name="???";
else
name=gr->gr_name;
fprintf(stdout, "Group ID: %d; Name: %s\n",
sbp.st_gid, name);
if ((sbp.st_mode & S_ISUID )== S_ISUID )
fprintf(stdout, "Set-user-ID\n");
if ((sbp.st_mode & S_ISGID )== S_ISGID )
fprintf(stdout, "Set-group-ID\n");
if ((sbp.st_mode & S_ISVTX )== S_ISVTX )
fprintf(stdout, "Save swapped text
after use\n");
fprintf(stdout, "Permissions:
%o\n",sbp.st_mode & 0xfff);
fprintf(stdout, "Last access: %s",
asctime(localtime(&sbp.st_atime )));
fprintf(stdout, "Last modification: %s",
asctime(localtime(&sbp.st_mtime )));
fprintf(stdout, "Last status change: %s",
asctime(localtime(&sbp.st_ctime )));
}
}
exit(error);
}
---------------------------------------------------------------------------
Thank you all for the very quick response and the informations.
Best Regards,
Iwan
Received on Thu Feb 22 2001 - 09:52:20 NZDT