How to move a file and change its creation time at the same time?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












If I move a file in Linux with the mv command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch command. So, is there a command that does both atomically?



I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.







share|improve this question


















  • 1




    Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
    – thrig
    Oct 27 '17 at 20:13










  • Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
    – pythonic
    Oct 27 '17 at 20:15











  • What if you touch and then move?
    – Jesse_b
    Oct 27 '17 at 20:19










  • That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
    – pythonic
    Oct 27 '17 at 20:22










  • rsync --remove-source-files SOURCEFILE DESTINATION/ will move your file and update mtime (though rsync does use a hidden temporary file to do this...)
    – don_crissti
    Oct 27 '17 at 20:47














up vote
2
down vote

favorite












If I move a file in Linux with the mv command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch command. So, is there a command that does both atomically?



I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.







share|improve this question


















  • 1




    Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
    – thrig
    Oct 27 '17 at 20:13










  • Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
    – pythonic
    Oct 27 '17 at 20:15











  • What if you touch and then move?
    – Jesse_b
    Oct 27 '17 at 20:19










  • That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
    – pythonic
    Oct 27 '17 at 20:22










  • rsync --remove-source-files SOURCEFILE DESTINATION/ will move your file and update mtime (though rsync does use a hidden temporary file to do this...)
    – don_crissti
    Oct 27 '17 at 20:47












up vote
2
down vote

favorite









up vote
2
down vote

favorite











If I move a file in Linux with the mv command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch command. So, is there a command that does both atomically?



I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.







share|improve this question














If I move a file in Linux with the mv command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch command. So, is there a command that does both atomically?



I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.









share|improve this question













share|improve this question




share|improve this question








edited Oct 27 '17 at 21:01









guntbert

1,0011917




1,0011917










asked Oct 27 '17 at 20:07









pythonic

1112




1112







  • 1




    Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
    – thrig
    Oct 27 '17 at 20:13










  • Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
    – pythonic
    Oct 27 '17 at 20:15











  • What if you touch and then move?
    – Jesse_b
    Oct 27 '17 at 20:19










  • That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
    – pythonic
    Oct 27 '17 at 20:22










  • rsync --remove-source-files SOURCEFILE DESTINATION/ will move your file and update mtime (though rsync does use a hidden temporary file to do this...)
    – don_crissti
    Oct 27 '17 at 20:47












  • 1




    Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
    – thrig
    Oct 27 '17 at 20:13










  • Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
    – pythonic
    Oct 27 '17 at 20:15











  • What if you touch and then move?
    – Jesse_b
    Oct 27 '17 at 20:19










  • That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
    – pythonic
    Oct 27 '17 at 20:22










  • rsync --remove-source-files SOURCEFILE DESTINATION/ will move your file and update mtime (though rsync does use a hidden temporary file to do this...)
    – don_crissti
    Oct 27 '17 at 20:47







1




1




Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
– thrig
Oct 27 '17 at 20:13




Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
– thrig
Oct 27 '17 at 20:13












Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
– pythonic
Oct 27 '17 at 20:15





Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
– pythonic
Oct 27 '17 at 20:15













What if you touch and then move?
– Jesse_b
Oct 27 '17 at 20:19




What if you touch and then move?
– Jesse_b
Oct 27 '17 at 20:19












That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
– pythonic
Oct 27 '17 at 20:22




That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
– pythonic
Oct 27 '17 at 20:22












rsync --remove-source-files SOURCEFILE DESTINATION/ will move your file and update mtime (though rsync does use a hidden temporary file to do this...)
– don_crissti
Oct 27 '17 at 20:47




rsync --remove-source-files SOURCEFILE DESTINATION/ will move your file and update mtime (though rsync does use a hidden temporary file to do this...)
– don_crissti
Oct 27 '17 at 20:47










1 Answer
1






active

oldest

votes

















up vote
4
down vote













mv, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch, or to simply cp the file (which will create a new file with new modification and access times), and rm the old one. If it's a particularly large file, this is inefficient, which is why tools like touch exist in the first place.



Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch it, and then move it to its final resting place.






share|improve this answer




















    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%2f400957%2fhow-to-move-a-file-and-change-its-creation-time-at-the-same-time%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
    4
    down vote













    mv, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch, or to simply cp the file (which will create a new file with new modification and access times), and rm the old one. If it's a particularly large file, this is inefficient, which is why tools like touch exist in the first place.



    Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch it, and then move it to its final resting place.






    share|improve this answer
























      up vote
      4
      down vote













      mv, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch, or to simply cp the file (which will create a new file with new modification and access times), and rm the old one. If it's a particularly large file, this is inefficient, which is why tools like touch exist in the first place.



      Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch it, and then move it to its final resting place.






      share|improve this answer






















        up vote
        4
        down vote










        up vote
        4
        down vote









        mv, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch, or to simply cp the file (which will create a new file with new modification and access times), and rm the old one. If it's a particularly large file, this is inefficient, which is why tools like touch exist in the first place.



        Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch it, and then move it to its final resting place.






        share|improve this answer












        mv, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch, or to simply cp the file (which will create a new file with new modification and access times), and rm the old one. If it's a particularly large file, this is inefficient, which is why tools like touch exist in the first place.



        Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch it, and then move it to its final resting place.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 27 '17 at 20:31









        DopeGhoti

        40.7k54979




        40.7k54979



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f400957%2fhow-to-move-a-file-and-change-its-creation-time-at-the-same-time%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay