Sample Header Ad - 728x90

Compare file dates from two directories

1 vote
1 answer
599 views
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