Finding a file with the same modification time as another

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
For each photo my camera produces both a IMG_NNNN.JPG and a IMG_NNNN.CR2 file, that have exactly the same modification time (which, coming from a FAT-formatted SD card, is always an even number of seconds).
I keep JPG and CR2 separately, but I sometimes need to find the CR2 that corresponds to a given JPG. My current scripts use something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2
But unfortunately due to numbering rollover using the name alone is no longer sufficient. Using the name and the modification time would be perfect, but something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2 -newermt "$(stat -c '%y' $jpgfile)"
doesn't work because newermt seems to perform a strict inequality comparison (same with newer). In addition newer... options are not really bullet-proof since searching the CR2 of an old JPG could find the CR2 of a newer homonym.
So:
- Am i overlooking an option in
find(GNU findutils 4.7.0-git)? - Or is there an elegant way to do this (taking in account that files with the same name are normally years apart)?
files find
add a comment |Â
up vote
1
down vote
favorite
For each photo my camera produces both a IMG_NNNN.JPG and a IMG_NNNN.CR2 file, that have exactly the same modification time (which, coming from a FAT-formatted SD card, is always an even number of seconds).
I keep JPG and CR2 separately, but I sometimes need to find the CR2 that corresponds to a given JPG. My current scripts use something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2
But unfortunately due to numbering rollover using the name alone is no longer sufficient. Using the name and the modification time would be perfect, but something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2 -newermt "$(stat -c '%y' $jpgfile)"
doesn't work because newermt seems to perform a strict inequality comparison (same with newer). In addition newer... options are not really bullet-proof since searching the CR2 of an old JPG could find the CR2 of a newer homonym.
So:
- Am i overlooking an option in
find(GNU findutils 4.7.0-git)? - Or is there an elegant way to do this (taking in account that files with the same name are normally years apart)?
files find
"Long list"????
â xenoid
Aug 19 at 10:56
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
For each photo my camera produces both a IMG_NNNN.JPG and a IMG_NNNN.CR2 file, that have exactly the same modification time (which, coming from a FAT-formatted SD card, is always an even number of seconds).
I keep JPG and CR2 separately, but I sometimes need to find the CR2 that corresponds to a given JPG. My current scripts use something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2
But unfortunately due to numbering rollover using the name alone is no longer sufficient. Using the name and the modification time would be perfect, but something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2 -newermt "$(stat -c '%y' $jpgfile)"
doesn't work because newermt seems to perform a strict inequality comparison (same with newer). In addition newer... options are not really bullet-proof since searching the CR2 of an old JPG could find the CR2 of a newer homonym.
So:
- Am i overlooking an option in
find(GNU findutils 4.7.0-git)? - Or is there an elegant way to do this (taking in account that files with the same name are normally years apart)?
files find
For each photo my camera produces both a IMG_NNNN.JPG and a IMG_NNNN.CR2 file, that have exactly the same modification time (which, coming from a FAT-formatted SD card, is always an even number of seconds).
I keep JPG and CR2 separately, but I sometimes need to find the CR2 that corresponds to a given JPG. My current scripts use something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2
But unfortunately due to numbering rollover using the name alone is no longer sufficient. Using the name and the modification time would be perfect, but something like:
find /path/to/CR2s -name $(basename $jpgfile .JPG).CR2 -newermt "$(stat -c '%y' $jpgfile)"
doesn't work because newermt seems to perform a strict inequality comparison (same with newer). In addition newer... options are not really bullet-proof since searching the CR2 of an old JPG could find the CR2 of a newer homonym.
So:
- Am i overlooking an option in
find(GNU findutils 4.7.0-git)? - Or is there an elegant way to do this (taking in account that files with the same name are normally years apart)?
files find
files find
asked Aug 19 at 10:25
xenoid
1,7051620
1,7051620
"Long list"????
â xenoid
Aug 19 at 10:56
add a comment |Â
"Long list"????
â xenoid
Aug 19 at 10:56
"Long list"????
â xenoid
Aug 19 at 10:56
"Long list"????
â xenoid
Aug 19 at 10:56
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
With zsh, you can do
autoload age
file=/path/to/something.JPG
ls -ld -- **/$file:t:e.CR2 (De'(age :$file :$file)')
To find the something.CR2 files that are exactly the same age as $file.
Thanks for the tip, even if I shall remain with bash for the time being. I found that my starting hypothesis was wrong anyway, timestamps look the same because they are rounded/truncated to the nearest even second, but there are a few cases where the time stamps are off by two seconds.
â xenoid
Aug 24 at 17:40
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
With zsh, you can do
autoload age
file=/path/to/something.JPG
ls -ld -- **/$file:t:e.CR2 (De'(age :$file :$file)')
To find the something.CR2 files that are exactly the same age as $file.
Thanks for the tip, even if I shall remain with bash for the time being. I found that my starting hypothesis was wrong anyway, timestamps look the same because they are rounded/truncated to the nearest even second, but there are a few cases where the time stamps are off by two seconds.
â xenoid
Aug 24 at 17:40
add a comment |Â
up vote
1
down vote
With zsh, you can do
autoload age
file=/path/to/something.JPG
ls -ld -- **/$file:t:e.CR2 (De'(age :$file :$file)')
To find the something.CR2 files that are exactly the same age as $file.
Thanks for the tip, even if I shall remain with bash for the time being. I found that my starting hypothesis was wrong anyway, timestamps look the same because they are rounded/truncated to the nearest even second, but there are a few cases where the time stamps are off by two seconds.
â xenoid
Aug 24 at 17:40
add a comment |Â
up vote
1
down vote
up vote
1
down vote
With zsh, you can do
autoload age
file=/path/to/something.JPG
ls -ld -- **/$file:t:e.CR2 (De'(age :$file :$file)')
To find the something.CR2 files that are exactly the same age as $file.
With zsh, you can do
autoload age
file=/path/to/something.JPG
ls -ld -- **/$file:t:e.CR2 (De'(age :$file :$file)')
To find the something.CR2 files that are exactly the same age as $file.
edited Aug 19 at 11:29
answered Aug 19 at 11:06
Stéphane Chazelas
285k53525864
285k53525864
Thanks for the tip, even if I shall remain with bash for the time being. I found that my starting hypothesis was wrong anyway, timestamps look the same because they are rounded/truncated to the nearest even second, but there are a few cases where the time stamps are off by two seconds.
â xenoid
Aug 24 at 17:40
add a comment |Â
Thanks for the tip, even if I shall remain with bash for the time being. I found that my starting hypothesis was wrong anyway, timestamps look the same because they are rounded/truncated to the nearest even second, but there are a few cases where the time stamps are off by two seconds.
â xenoid
Aug 24 at 17:40
Thanks for the tip, even if I shall remain with bash for the time being. I found that my starting hypothesis was wrong anyway, timestamps look the same because they are rounded/truncated to the nearest even second, but there are a few cases where the time stamps are off by two seconds.
â xenoid
Aug 24 at 17:40
Thanks for the tip, even if I shall remain with bash for the time being. I found that my starting hypothesis was wrong anyway, timestamps look the same because they are rounded/truncated to the nearest even second, but there are a few cases where the time stamps are off by two seconds.
â xenoid
Aug 24 at 17:40
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%2funix.stackexchange.com%2fquestions%2f463470%2ffinding-a-file-with-the-same-modification-time-as-another%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
"Long list"????
â xenoid
Aug 19 at 10:56