How to fix “touch: out of range or illegal time specification” with touch t- function












-2















I have lost the creation date of 500 photos and clips when I transmitted them from my camera to my mac. Fortunately the creation dates are still in the files' name (like P_20180615_131048_vHDR_Auto_HP.jpg ; V_20180616_071110_vHDR_Auto_OC0.mp4)
So I read through some guidances from the internet to make the below scripts to help me batch changing the dates from the name. As I am a newbie of shell scripting, I don't know what I've done wrong.



for f in *; do
t=“${f:2:4}${f:6:2}${f:8:2}${f:11:2}${f:13:2}.${f:15:2}”
touch -t $t "$f"
done



I put the date in the format that touch needs(201806151310.48), but still get the same error "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS] [[CC]YY]MMDDhhmm[.SS]"
I've been tried to put a date in the script directly
touch like -t 201806151610.48 $f and it worked. It seems that I cannot apply $t and $f both variables at the same time under touch function.
I would be very grateful if anyone can help me.










share|improve this question























  • change it to echo touch -t $t "$f" so you can see what it produces.

    – Ben
    Dec 29 '18 at 13:26











  • More generally, generate the sequence of commands to a file using echo whatever > commandlist.sh, then you can check the file with vi commandlist.sh and execute it using sh < commandlist.sh

    – Ben
    Dec 29 '18 at 13:27











  • What kind of shell you use? I tried to run your script, and it worked well. BTW, I use bash.

    – Lester_wu
    Dec 30 '18 at 2:47


















-2















I have lost the creation date of 500 photos and clips when I transmitted them from my camera to my mac. Fortunately the creation dates are still in the files' name (like P_20180615_131048_vHDR_Auto_HP.jpg ; V_20180616_071110_vHDR_Auto_OC0.mp4)
So I read through some guidances from the internet to make the below scripts to help me batch changing the dates from the name. As I am a newbie of shell scripting, I don't know what I've done wrong.



for f in *; do
t=“${f:2:4}${f:6:2}${f:8:2}${f:11:2}${f:13:2}.${f:15:2}”
touch -t $t "$f"
done



I put the date in the format that touch needs(201806151310.48), but still get the same error "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS] [[CC]YY]MMDDhhmm[.SS]"
I've been tried to put a date in the script directly
touch like -t 201806151610.48 $f and it worked. It seems that I cannot apply $t and $f both variables at the same time under touch function.
I would be very grateful if anyone can help me.










share|improve this question























  • change it to echo touch -t $t "$f" so you can see what it produces.

    – Ben
    Dec 29 '18 at 13:26











  • More generally, generate the sequence of commands to a file using echo whatever > commandlist.sh, then you can check the file with vi commandlist.sh and execute it using sh < commandlist.sh

    – Ben
    Dec 29 '18 at 13:27











  • What kind of shell you use? I tried to run your script, and it worked well. BTW, I use bash.

    – Lester_wu
    Dec 30 '18 at 2:47
















-2












-2








-2








I have lost the creation date of 500 photos and clips when I transmitted them from my camera to my mac. Fortunately the creation dates are still in the files' name (like P_20180615_131048_vHDR_Auto_HP.jpg ; V_20180616_071110_vHDR_Auto_OC0.mp4)
So I read through some guidances from the internet to make the below scripts to help me batch changing the dates from the name. As I am a newbie of shell scripting, I don't know what I've done wrong.



for f in *; do
t=“${f:2:4}${f:6:2}${f:8:2}${f:11:2}${f:13:2}.${f:15:2}”
touch -t $t "$f"
done



I put the date in the format that touch needs(201806151310.48), but still get the same error "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS] [[CC]YY]MMDDhhmm[.SS]"
I've been tried to put a date in the script directly
touch like -t 201806151610.48 $f and it worked. It seems that I cannot apply $t and $f both variables at the same time under touch function.
I would be very grateful if anyone can help me.










share|improve this question














I have lost the creation date of 500 photos and clips when I transmitted them from my camera to my mac. Fortunately the creation dates are still in the files' name (like P_20180615_131048_vHDR_Auto_HP.jpg ; V_20180616_071110_vHDR_Auto_OC0.mp4)
So I read through some guidances from the internet to make the below scripts to help me batch changing the dates from the name. As I am a newbie of shell scripting, I don't know what I've done wrong.



for f in *; do
t=“${f:2:4}${f:6:2}${f:8:2}${f:11:2}${f:13:2}.${f:15:2}”
touch -t $t "$f"
done



I put the date in the format that touch needs(201806151310.48), but still get the same error "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS] [[CC]YY]MMDDhhmm[.SS]"
I've been tried to put a date in the script directly
touch like -t 201806151610.48 $f and it worked. It seems that I cannot apply $t and $f both variables at the same time under touch function.
I would be very grateful if anyone can help me.







shell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 29 '18 at 13:24









Billy LamBilly Lam

1




1













  • change it to echo touch -t $t "$f" so you can see what it produces.

    – Ben
    Dec 29 '18 at 13:26











  • More generally, generate the sequence of commands to a file using echo whatever > commandlist.sh, then you can check the file with vi commandlist.sh and execute it using sh < commandlist.sh

    – Ben
    Dec 29 '18 at 13:27











  • What kind of shell you use? I tried to run your script, and it worked well. BTW, I use bash.

    – Lester_wu
    Dec 30 '18 at 2:47





















  • change it to echo touch -t $t "$f" so you can see what it produces.

    – Ben
    Dec 29 '18 at 13:26











  • More generally, generate the sequence of commands to a file using echo whatever > commandlist.sh, then you can check the file with vi commandlist.sh and execute it using sh < commandlist.sh

    – Ben
    Dec 29 '18 at 13:27











  • What kind of shell you use? I tried to run your script, and it worked well. BTW, I use bash.

    – Lester_wu
    Dec 30 '18 at 2:47



















change it to echo touch -t $t "$f" so you can see what it produces.

– Ben
Dec 29 '18 at 13:26





change it to echo touch -t $t "$f" so you can see what it produces.

– Ben
Dec 29 '18 at 13:26













More generally, generate the sequence of commands to a file using echo whatever > commandlist.sh, then you can check the file with vi commandlist.sh and execute it using sh < commandlist.sh

– Ben
Dec 29 '18 at 13:27





More generally, generate the sequence of commands to a file using echo whatever > commandlist.sh, then you can check the file with vi commandlist.sh and execute it using sh < commandlist.sh

– Ben
Dec 29 '18 at 13:27













What kind of shell you use? I tried to run your script, and it worked well. BTW, I use bash.

– Lester_wu
Dec 30 '18 at 2:47







What kind of shell you use? I tried to run your script, and it worked well. BTW, I use bash.

– Lester_wu
Dec 30 '18 at 2:47














1 Answer
1






active

oldest

votes


















0














Thank you all of you. I solve the problem by just eliminate the " " in the second line. As I echo $t, it show "201806151310.48". How silly am i!!
I use bash shell in Mac os, I wonder why Lester can run it smoothly.
BTW, happy new yearXD






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53969970%2fhow-to-fix-touch-out-of-range-or-illegal-time-specification-with-touch-t-fun%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Thank you all of you. I solve the problem by just eliminate the " " in the second line. As I echo $t, it show "201806151310.48". How silly am i!!
    I use bash shell in Mac os, I wonder why Lester can run it smoothly.
    BTW, happy new yearXD






    share|improve this answer




























      0














      Thank you all of you. I solve the problem by just eliminate the " " in the second line. As I echo $t, it show "201806151310.48". How silly am i!!
      I use bash shell in Mac os, I wonder why Lester can run it smoothly.
      BTW, happy new yearXD






      share|improve this answer


























        0












        0








        0







        Thank you all of you. I solve the problem by just eliminate the " " in the second line. As I echo $t, it show "201806151310.48". How silly am i!!
        I use bash shell in Mac os, I wonder why Lester can run it smoothly.
        BTW, happy new yearXD






        share|improve this answer













        Thank you all of you. I solve the problem by just eliminate the " " in the second line. As I echo $t, it show "201806151310.48". How silly am i!!
        I use bash shell in Mac os, I wonder why Lester can run it smoothly.
        BTW, happy new yearXD







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 3:04









        Billy LamBilly Lam

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53969970%2fhow-to-fix-touch-out-of-range-or-illegal-time-specification-with-touch-t-fun%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            compose and upload a new article using a custom form

            How to correct the classpath of spring boot application so that it contains a single, compatible version of...