How to delete older files in a folder in unix?











up vote
1
down vote

favorite












I need to find the meaning of the below statement:



find /sourcedirectory -mtime +2 -exec mv "{}" /destination/directory/ ;









share|improve this question















migrated from serverfault.com Aug 14 '14 at 11:14


This question came from our site for system and network administrators.











  • 1




    Next time, please specify which Unix you're talking about. (Or as in this case, which find.) AIX is not FreeBSD is not OS X, for example.
    – a CVn
    Aug 12 '14 at 13:09






  • 1




    Also, the title and the question do not match.
    – a CVn
    Aug 12 '14 at 13:10















up vote
1
down vote

favorite












I need to find the meaning of the below statement:



find /sourcedirectory -mtime +2 -exec mv "{}" /destination/directory/ ;









share|improve this question















migrated from serverfault.com Aug 14 '14 at 11:14


This question came from our site for system and network administrators.











  • 1




    Next time, please specify which Unix you're talking about. (Or as in this case, which find.) AIX is not FreeBSD is not OS X, for example.
    – a CVn
    Aug 12 '14 at 13:09






  • 1




    Also, the title and the question do not match.
    – a CVn
    Aug 12 '14 at 13:10













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I need to find the meaning of the below statement:



find /sourcedirectory -mtime +2 -exec mv "{}" /destination/directory/ ;









share|improve this question















I need to find the meaning of the below statement:



find /sourcedirectory -mtime +2 -exec mv "{}" /destination/directory/ ;






shell find






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 at 14:29









Rui F Ribeiro

38.3k1475126




38.3k1475126










asked Aug 12 '14 at 9:16







Anna Vincent











migrated from serverfault.com Aug 14 '14 at 11:14


This question came from our site for system and network administrators.






migrated from serverfault.com Aug 14 '14 at 11:14


This question came from our site for system and network administrators.










  • 1




    Next time, please specify which Unix you're talking about. (Or as in this case, which find.) AIX is not FreeBSD is not OS X, for example.
    – a CVn
    Aug 12 '14 at 13:09






  • 1




    Also, the title and the question do not match.
    – a CVn
    Aug 12 '14 at 13:10














  • 1




    Next time, please specify which Unix you're talking about. (Or as in this case, which find.) AIX is not FreeBSD is not OS X, for example.
    – a CVn
    Aug 12 '14 at 13:09






  • 1




    Also, the title and the question do not match.
    – a CVn
    Aug 12 '14 at 13:10








1




1




Next time, please specify which Unix you're talking about. (Or as in this case, which find.) AIX is not FreeBSD is not OS X, for example.
– a CVn
Aug 12 '14 at 13:09




Next time, please specify which Unix you're talking about. (Or as in this case, which find.) AIX is not FreeBSD is not OS X, for example.
– a CVn
Aug 12 '14 at 13:09




1




1




Also, the title and the question do not match.
– a CVn
Aug 12 '14 at 13:10




Also, the title and the question do not match.
– a CVn
Aug 12 '14 at 13:10










1 Answer
1






active

oldest

votes

















up vote
7
down vote













It means that every file or folder under /sourcedirectory older than two days should be moved to /destination/directory/.



find /sourcedirectory           # finds every file/folder
-mtime +2 # sort out files/folders older than 2 days
mv "{}" /destination/directory/ # move each result to destination folder





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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f150225%2fhow-to-delete-older-files-in-a-folder-in-unix%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








    up vote
    7
    down vote













    It means that every file or folder under /sourcedirectory older than two days should be moved to /destination/directory/.



    find /sourcedirectory           # finds every file/folder
    -mtime +2 # sort out files/folders older than 2 days
    mv "{}" /destination/directory/ # move each result to destination folder





    share|improve this answer

























      up vote
      7
      down vote













      It means that every file or folder under /sourcedirectory older than two days should be moved to /destination/directory/.



      find /sourcedirectory           # finds every file/folder
      -mtime +2 # sort out files/folders older than 2 days
      mv "{}" /destination/directory/ # move each result to destination folder





      share|improve this answer























        up vote
        7
        down vote










        up vote
        7
        down vote









        It means that every file or folder under /sourcedirectory older than two days should be moved to /destination/directory/.



        find /sourcedirectory           # finds every file/folder
        -mtime +2 # sort out files/folders older than 2 days
        mv "{}" /destination/directory/ # move each result to destination folder





        share|improve this answer












        It means that every file or folder under /sourcedirectory older than two days should be moved to /destination/directory/.



        find /sourcedirectory           # finds every file/folder
        -mtime +2 # sort out files/folders older than 2 days
        mv "{}" /destination/directory/ # move each result to destination folder






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 12 '14 at 9:20









        SteffenNielsen

        1713




        1713






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f150225%2fhow-to-delete-older-files-in-a-folder-in-unix%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

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux