Finding a file with the same modification time as another

The name of the pictureThe name of the pictureThe name of the pictureClash 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)?









share|improve this question





















  • "Long list"????
    – xenoid
    Aug 19 at 10:56














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)?









share|improve this question





















  • "Long list"????
    – xenoid
    Aug 19 at 10:56












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)?









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 19 at 10:25









xenoid

1,7051620




1,7051620











  • "Long list"????
    – xenoid
    Aug 19 at 10:56
















  • "Long list"????
    – xenoid
    Aug 19 at 10:56















"Long list"????
– xenoid
Aug 19 at 10:56




"Long list"????
– xenoid
Aug 19 at 10:56










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.






share|improve this answer






















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer






















  • 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














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.






share|improve this answer






















  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)