-1

Using pdksh

stat() command is unavailable on system.

I need to loop through the amount of files found and store their dates in an array. $COMMAND stores the number of files found in $location as can be seen below.

Can someone help me please?

COMMAND=`find $location -type f | wc -l`
CMD_getDate=$(find $location -type f | xargs ls -lrt | awk '{print $6} {print $7}')
Mark Reed
  • 91,912
  • 16
  • 138
  • 175
  • OK, what do you want the final array to look like? Just an array of dates with no way to figure out which filename goes with which date? And what sort of dates - strings like `Tue Jun 2 08:58:06 EDT 2015`? time_t values like `1433249886`? ISO 8601, like `2015-06-02T12:58:06Z`? I assume you want the mtime (as opposed to the atime or ctime)? – Mark Reed Jun 02 '15 at 12:58
  • If I would have 2 arrays then I would be able to know. This is because they will be sorted beforehand no? I just need to save the date Jun 2 for example .. then I do the same for filename, time etc.. – Sergio M. S. Jun 02 '15 at 13:24

1 Answers1

0

Well, first, you don't need to do the wc. The size of the array will tell you how many there are. Here's a simple way to build an array of dates and names (designed for pdksh; there are better ways to do it in AT&T ksh or bash):

set -A files 
set -A dates
find "$location" -type f -ls |&
while read -p inum blocks symode links owner group size rest; do 
  set -A files "${files[@]}" "${rest##* }"
  set -A dates "${dates[@]}" "${rest% *}"
done

Here's one way to examine the results:

print "Found ${#files[@]} files:"
let i=0
while (( i < ${#files[@]} )); do
  print "The file '${files[i]}' was modified on ${dates[i]}."
  let i+=1
done

This gives you the full date string, not just the month and day. That might be what you want - the date output of ls -l (or find -ls) is variable depending on how long ago the file was modified. Given these files, how does your original format distinguish between the modification times of a and b?

$ ls -l
total 0
-rw-rw-r--+ 1 mjreed  staff  0 Feb  3  2014 a
-rw-rw-r--+ 1 mjreed  staff  0 Feb  3 04:05 b

As written, the code above would yields this for the above directory with location=.:

Found 2 files:
The file './a' was modified on Feb  3  2014.
The file './b' was modified on Feb  3 00:00.

It would help if you indicated what the actual end goal is..

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
  • I don't think my system allows using of typeset -a as it says '0403-010 A specified flag is not valid for this command.' ... Also for the array i can see the dates and filenames but as you said they are gone by the time the loop exited. – Sergio M. S. Jun 02 '15 at 14:17
  • OK, you're using pdksh, not AT&T ksh. check my edit. – Mark Reed Jun 02 '15 at 14:37
  • Thanks for your help but when inputting the block of code of set -A etc .. i get the following - [1] + Done find "$location" -type f -ls |& – Sergio M. S. Jun 02 '15 at 15:08
  • that's to be expected at the end of the loop. The coprocess job terminated. – Mark Reed Jun 02 '15 at 16:57