I have a set of files in a structure like so;
regions ├── ap-northeast-1 │ └── sg-66497903 │ ├── sg-66497903-2017-10-03-Tue-12.39.json │ ├── sg-66497903-2017-10-03-Tue-12.42.json │ ├── sg-66497903-2017-10-03-Tue-12.49.json │ ├── sg-66497903-2017-10-03-Tue-12.53.json │ └── sg-66497903-2017-10-03-Tue-13.12.json ├── ap-northeast-2 │ └── sg-824282eb │ ├── sg-824282eb-2017-10-03-Tue-12.39.json │ ├── sg-824282eb-2017-10-03-Tue-12.42.json │ ├── sg-824282eb-2017-10-03-Tue-12.49.json │ ├── sg-824282eb-2017-10-03-Tue-12.53.json │ └── sg-824282eb-2017-10-03-Tue-13.12.json ├── ap-south-1 │ └── sg-4fec0526 │ ├── sg-4fec0526-2017-10-03-Tue-12.39.json │ ├── sg-4fec0526-2017-10-03-Tue-12.42.json │ ├── sg-4fec0526-2017-10-03-Tue-12.49.json │ ├── sg-4fec0526-2017-10-03-Tue-12.53.json │ └── sg-4fec0526-2017-10-03-Tue-13.12.json
The list is longer but you get the idea. I am trying to find the oldest json file in each directory to use as at the standard to set in an array and diff
the other files in the individual directories.
I have this so far, but it's not right.
#!/bin/bash mapfile -t awsReg < <(ls ~/regions) for awsrg in "${awsReg[@]}" do mapfile -t awsSG < <(ls regions/"$awsrg") for sg in "${awsSG[@]}" do find "$sg" -mindepth 2 -type f -printf '%T+ %p\n' | sort | head -n 1 diff -q ##oldest file## ##all other files### done done
For example I would like in regions -> ap-northeast-1 -> sg-66497903
to find the file sg-66497903-2017-10-03-Tue-12.39.json
, set it as the file to diff
the other files in the directory with a diff -q
. Move on to next directory, find the oldest in that directory....etc