Operating System - HP-UX
1834299 Members
2263 Online
110066 Solutions
New Discussion

Extracting file details name and creation yyyy/mm/dd hh:mm

 
SOLVED
Go to solution
Russell Gould
Advisor

Extracting file details name and creation yyyy/mm/dd hh:mm

Hello,

Can anyone suggest how I can extract the following details from a standard text file details :

filename and yyyymmdd, and hh:mm of creation

I understand that I could use ll | grep awk for columns 6,7,8 and 9 - however, on an ll output, newer files do not output the year, and older files do not output the time.

Is there any exe which will show all the details :
Filename
yyyy created
mm created
dd created
hh created
mm (minutes) created

Many thanks

Russell


It's not a problem, it's an opportunity !
9 REPLIES 9
Tom Geudens
Honored Contributor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

Hi,
Tough ... I don't think that is possible (with a "standard" command). See the following post http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xbbb5854994d9d4118fef0090279cd0f9,00.html

Hope this helps,
Tom
A life ? Cool ! Where can I download one of those from ?
Tore_1
Regular Advisor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

Hi, you can install the enhanced gnu version of ls :
http://hpux.connect.org.uk/hppd/hpux/Gnu/findutils-4.1.5/

and issue the command ls --full-time

Trond Haugen
Honored Contributor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

I did write a cprogram a long time ago so I don't quite remember what I did. But if you are a little info C-programming you may be able to modify it to suit your needs.
Example:
$ ./lt lt
8628 -rwxr-xr-x 1 trond crc 20480 lt
Access time | Modification time | Mode change time:
25/04-102 15:07:19 | 27/01-95 13:04:51 | 21/04-102 0:21:52

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
H.Merijn Brand (procura
Honored Contributor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

l1:/tmp 114 > perl -MFile::Find -e 'find(sub{@f=(localtime((stat$_)[9]))[1..5];$f[4]+=1900;$f[3]++;printf"%04d/%02d/%02d %02d:%02d %s\n",reverse(@f),$File::Find::name},@ARGV?@ARGV:".")' l*
2001/10/15 09:17 ./linda.errorlog
2002/04/08 08:16 ./llbdbase.dat
2001/10/10 14:10 lost+found
2001/12/03 09:55 ./lp.err
l1:/tmp 115 > ll -d l*
38 -rw-r--r-- 1 linda softwr 107 Oct 15 2001 linda.errorlog
702 -r--r--r-- 1 root root 0 Apr 8 08:16 llbdbase.dat
3 drwxr-xr-x 2 root root 96 Oct 10 2001 lost+found
746 -rw-rw-rw- 1 lp lp 400 Dec 3 09:55 lp.err
l1:/tmp 116 >
Enjoy, Have FUN! H.Merijn
George A Bodnar
Trusted Contributor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

Here is an extracted C code snippet that provides what you are after. You can build by saving the file as .c and then doing the following:

cc prog.c -o prog

Where prog is the executable you would run and supply a parameter name.
David Burgess
Esteemed Contributor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

This gets the last modified time. You can't get the creation time.

Save the attached as a.out
cc a.out

or

gcc a.out

Run it

./a.out

HTH,

Dave.
Frank Slootweg
Honored Contributor
Solution

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

Better methods have already been given, but if you do not want to install extra commands or/and use C/perl, and do not mind 'hacks' and slow performance for large files (How's *that* for a disclaimer!? :-)), then you can use:

$ echo /stand/system | cpio -o 2>/dev/null | cpio -ivt 2>/dev/null
100444 root 531 Feb 16 08:45:08 2000 /stand/system
$

In a script you can assign the result to a variable:

result=`echo $file | cpio -o 2>/dev/null | cpio -ivt 2>/dev/null`

The cutting and re-arranging of the order is left as an exercise. With "set --" it becomes easy, i.e.

set -- `echo $file | cpio -o 2>/dev/null | cpio -ivt 2>/dev/null
time=$6
year=$7
[etc.]
Rodney Hills
Honored Contributor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

Search for "fstat" on the HP porting site-

http://hpux.cs.utah.edu/

It dumps all kinds of file info and allows you to format the way you prefer.

-- Rod Hills
There be dragons...
Wodisch
Honored Contributor

Re: Extracting file details name and creation yyyy/mm/dd hh:mm

Hello Russel,

you can get only three time stamps:
- atime = access time = reading
- mtime = modification time = writing
- ctime = CHANGE time = chrgp/chown/chmod

but there is NO *creation* time!
The date (=mtime) of the parent directory is changed when a file is created, but then, other files may have caused that, or your file has been created in another directory and then moved to the new one...

Just my $0.02,
Wodisch