Compare file dates
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Sometimes when I boot, my system goes into emergency mode.
I then use Clonezilla to restore an image.
Usually the image is older than the current date.
This is part of a backup script that runs as a startup program.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
This then overwrites my zip file with one that is in fact older.
I thought that if I could compare the file dates, before the zip operation, I could prevent the overwriting.
I tried this.
file1time=`stat -c %Y /home/andy/bin/Ubuntu_Scripts.zip`
file2time=`stat -c %Y /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Ubuntu_Scripts.zip`
if [ "$file1time" -ot "$file2time" ]
then
echo "File is older. "
fi
18.04 files mate copy
add a comment |Â
up vote
1
down vote
favorite
Sometimes when I boot, my system goes into emergency mode.
I then use Clonezilla to restore an image.
Usually the image is older than the current date.
This is part of a backup script that runs as a startup program.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
This then overwrites my zip file with one that is in fact older.
I thought that if I could compare the file dates, before the zip operation, I could prevent the overwriting.
I tried this.
file1time=`stat -c %Y /home/andy/bin/Ubuntu_Scripts.zip`
file2time=`stat -c %Y /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Ubuntu_Scripts.zip`
if [ "$file1time" -ot "$file2time" ]
then
echo "File is older. "
fi
18.04 files mate copy
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Sometimes when I boot, my system goes into emergency mode.
I then use Clonezilla to restore an image.
Usually the image is older than the current date.
This is part of a backup script that runs as a startup program.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
This then overwrites my zip file with one that is in fact older.
I thought that if I could compare the file dates, before the zip operation, I could prevent the overwriting.
I tried this.
file1time=`stat -c %Y /home/andy/bin/Ubuntu_Scripts.zip`
file2time=`stat -c %Y /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Ubuntu_Scripts.zip`
if [ "$file1time" -ot "$file2time" ]
then
echo "File is older. "
fi
18.04 files mate copy
Sometimes when I boot, my system goes into emergency mode.
I then use Clonezilla to restore an image.
Usually the image is older than the current date.
This is part of a backup script that runs as a startup program.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
cp -u Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
This then overwrites my zip file with one that is in fact older.
I thought that if I could compare the file dates, before the zip operation, I could prevent the overwriting.
I tried this.
file1time=`stat -c %Y /home/andy/bin/Ubuntu_Scripts.zip`
file2time=`stat -c %Y /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Ubuntu_Scripts.zip`
if [ "$file1time" -ot "$file2time" ]
then
echo "File is older. "
fi
18.04 files mate copy
asked Aug 9 at 13:04
fixit7
491317
491317
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
Use rsync
instead of cp
and you can use the --update
flag that will only update when you are copying a newer file.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
add a comment |Â
up vote
2
down vote
Your code uses -ot
where it should use -lt
. See the example below.
#!/bin/bash
file1time=`stat -c %Y /home/niclas/dbat/INSTALL.txt`
file2time=`stat -c %Y /home/niclas/dbat/README.txt`
if [ "$file1time" -lt "$file2time" ]
then
echo "INSTALL.txt is older."
else
echo "README.txt is older."
fi
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Use rsync
instead of cp
and you can use the --update
flag that will only update when you are copying a newer file.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
add a comment |Â
up vote
3
down vote
accepted
Use rsync
instead of cp
and you can use the --update
flag that will only update when you are copying a newer file.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Use rsync
instead of cp
and you can use the --update
flag that will only update when you are copying a newer file.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
Use rsync
instead of cp
and you can use the --update
flag that will only update when you are copying a newer file.
cd /home/andy/bin/
zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py *.txt
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/
rsync -av --update Ubuntu_Scripts.zip /media/andy/MAXTOR_SDB5/Emergency_Backup/
answered Aug 9 at 13:18
Katu
2,2051326
2,2051326
add a comment |Â
add a comment |Â
up vote
2
down vote
Your code uses -ot
where it should use -lt
. See the example below.
#!/bin/bash
file1time=`stat -c %Y /home/niclas/dbat/INSTALL.txt`
file2time=`stat -c %Y /home/niclas/dbat/README.txt`
if [ "$file1time" -lt "$file2time" ]
then
echo "INSTALL.txt is older."
else
echo "README.txt is older."
fi
add a comment |Â
up vote
2
down vote
Your code uses -ot
where it should use -lt
. See the example below.
#!/bin/bash
file1time=`stat -c %Y /home/niclas/dbat/INSTALL.txt`
file2time=`stat -c %Y /home/niclas/dbat/README.txt`
if [ "$file1time" -lt "$file2time" ]
then
echo "INSTALL.txt is older."
else
echo "README.txt is older."
fi
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Your code uses -ot
where it should use -lt
. See the example below.
#!/bin/bash
file1time=`stat -c %Y /home/niclas/dbat/INSTALL.txt`
file2time=`stat -c %Y /home/niclas/dbat/README.txt`
if [ "$file1time" -lt "$file2time" ]
then
echo "INSTALL.txt is older."
else
echo "README.txt is older."
fi
Your code uses -ot
where it should use -lt
. See the example below.
#!/bin/bash
file1time=`stat -c %Y /home/niclas/dbat/INSTALL.txt`
file2time=`stat -c %Y /home/niclas/dbat/README.txt`
if [ "$file1time" -lt "$file2time" ]
then
echo "INSTALL.txt is older."
else
echo "README.txt is older."
fi
answered Aug 9 at 13:26
Niclas Börlin
7961515
7961515
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1063832%2fcompare-file-dates%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password