I have two directories with files with the same name.
Basically I want to replace dir1/file.txt with dir2/file.txt if the creation date of dir1/file.txt is more recent. But i think I'm missing something in the if condition.
#!/bin/bash
for i in /dir1/*; do
nameFIRR=$(basename "$i")
dateINPUT="$(date -r $i)"
dateOUTPUT="$(date -r /dir2/$nameFIRR)"
if [ $dateINPUT -ge $dateOUTPUT ];
then
cp -u $i /dir2/$nameFIRR
fi
done
Asked by LucaP
(143 rep)
Jan 27, 2017, 05:31 PM
Last activity: Nov 30, 2023, 04:50 AM
Last activity: Nov 30, 2023, 04:50 AM