Scrip to delete files older than 6 months

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











up vote
8
down vote

favorite
1












Setting up a cron job for once a month to start a script.



the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.



Looking to run this script once a month. Is that possible to get the old one deleted?



Please let me know if that isn't clear enough.










share|improve this question

















  • 11




    Why not just use logrotate?
    – Michael Hampton
    May 29 '13 at 20:33










  • @scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
    – Bratchley
    May 29 '13 at 20:45










  • Yeah I've just had a good look at logrotate makes sense cheers all
    – scott marriott
    May 29 '13 at 20:54










  • @MichaelHampton you should make that an answer.
    – evilsoup
    May 30 '13 at 18:53














up vote
8
down vote

favorite
1












Setting up a cron job for once a month to start a script.



the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.



Looking to run this script once a month. Is that possible to get the old one deleted?



Please let me know if that isn't clear enough.










share|improve this question

















  • 11




    Why not just use logrotate?
    – Michael Hampton
    May 29 '13 at 20:33










  • @scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
    – Bratchley
    May 29 '13 at 20:45










  • Yeah I've just had a good look at logrotate makes sense cheers all
    – scott marriott
    May 29 '13 at 20:54










  • @MichaelHampton you should make that an answer.
    – evilsoup
    May 30 '13 at 18:53












up vote
8
down vote

favorite
1









up vote
8
down vote

favorite
1






1





Setting up a cron job for once a month to start a script.



the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.



Looking to run this script once a month. Is that possible to get the old one deleted?



Please let me know if that isn't clear enough.










share|improve this question













Setting up a cron job for once a month to start a script.



the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.



Looking to run this script once a month. Is that possible to get the old one deleted?



Please let me know if that isn't clear enough.







scripting ksh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 29 '13 at 20:29









scott marriott

54114




54114







  • 11




    Why not just use logrotate?
    – Michael Hampton
    May 29 '13 at 20:33










  • @scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
    – Bratchley
    May 29 '13 at 20:45










  • Yeah I've just had a good look at logrotate makes sense cheers all
    – scott marriott
    May 29 '13 at 20:54










  • @MichaelHampton you should make that an answer.
    – evilsoup
    May 30 '13 at 18:53












  • 11




    Why not just use logrotate?
    – Michael Hampton
    May 29 '13 at 20:33










  • @scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
    – Bratchley
    May 29 '13 at 20:45










  • Yeah I've just had a good look at logrotate makes sense cheers all
    – scott marriott
    May 29 '13 at 20:54










  • @MichaelHampton you should make that an answer.
    – evilsoup
    May 30 '13 at 18:53







11




11




Why not just use logrotate?
– Michael Hampton
May 29 '13 at 20:33




Why not just use logrotate?
– Michael Hampton
May 29 '13 at 20:33












@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45




@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45












Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54




Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54












@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53




@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53










2 Answers
2






active

oldest

votes

















up vote
13
down vote













You could start with this:



find /your/file -mtime +182 -exec rm +


Where +182 are the days quantity.






share|improve this answer






















  • Thanks for that, might have a play with it, but I maybe logrotate might be the best option
    – scott marriott
    May 29 '13 at 20:55










  • @jordanm any ideas why this might not of worked?
    – scott marriott
    May 30 '13 at 9:51










  • ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
    – scott marriott
    May 30 '13 at 9:53










  • I changed number of days to 1
    – scott marriott
    May 30 '13 at 10:09










  • @scottmarriott Not all versions of find support +/- for -mtime. What OS and version of find do you have?
    – jordanm
    May 30 '13 at 13:04

















up vote
2
down vote













You can just use logrotate. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.






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%2f77558%2fscrip-to-delete-files-older-than-6-months%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    13
    down vote













    You could start with this:



    find /your/file -mtime +182 -exec rm +


    Where +182 are the days quantity.






    share|improve this answer






















    • Thanks for that, might have a play with it, but I maybe logrotate might be the best option
      – scott marriott
      May 29 '13 at 20:55










    • @jordanm any ideas why this might not of worked?
      – scott marriott
      May 30 '13 at 9:51










    • ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
      – scott marriott
      May 30 '13 at 9:53










    • I changed number of days to 1
      – scott marriott
      May 30 '13 at 10:09










    • @scottmarriott Not all versions of find support +/- for -mtime. What OS and version of find do you have?
      – jordanm
      May 30 '13 at 13:04














    up vote
    13
    down vote













    You could start with this:



    find /your/file -mtime +182 -exec rm +


    Where +182 are the days quantity.






    share|improve this answer






















    • Thanks for that, might have a play with it, but I maybe logrotate might be the best option
      – scott marriott
      May 29 '13 at 20:55










    • @jordanm any ideas why this might not of worked?
      – scott marriott
      May 30 '13 at 9:51










    • ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
      – scott marriott
      May 30 '13 at 9:53










    • I changed number of days to 1
      – scott marriott
      May 30 '13 at 10:09










    • @scottmarriott Not all versions of find support +/- for -mtime. What OS and version of find do you have?
      – jordanm
      May 30 '13 at 13:04












    up vote
    13
    down vote










    up vote
    13
    down vote









    You could start with this:



    find /your/file -mtime +182 -exec rm +


    Where +182 are the days quantity.






    share|improve this answer














    You could start with this:



    find /your/file -mtime +182 -exec rm +


    Where +182 are the days quantity.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 29 '13 at 20:46









    jordanm

    29.9k28192




    29.9k28192










    answered May 29 '13 at 20:41









    ramonovski

    32217




    32217











    • Thanks for that, might have a play with it, but I maybe logrotate might be the best option
      – scott marriott
      May 29 '13 at 20:55










    • @jordanm any ideas why this might not of worked?
      – scott marriott
      May 30 '13 at 9:51










    • ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
      – scott marriott
      May 30 '13 at 9:53










    • I changed number of days to 1
      – scott marriott
      May 30 '13 at 10:09










    • @scottmarriott Not all versions of find support +/- for -mtime. What OS and version of find do you have?
      – jordanm
      May 30 '13 at 13:04
















    • Thanks for that, might have a play with it, but I maybe logrotate might be the best option
      – scott marriott
      May 29 '13 at 20:55










    • @jordanm any ideas why this might not of worked?
      – scott marriott
      May 30 '13 at 9:51










    • ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
      – scott marriott
      May 30 '13 at 9:53










    • I changed number of days to 1
      – scott marriott
      May 30 '13 at 10:09










    • @scottmarriott Not all versions of find support +/- for -mtime. What OS and version of find do you have?
      – jordanm
      May 30 '13 at 13:04















    Thanks for that, might have a play with it, but I maybe logrotate might be the best option
    – scott marriott
    May 29 '13 at 20:55




    Thanks for that, might have a play with it, but I maybe logrotate might be the best option
    – scott marriott
    May 29 '13 at 20:55












    @jordanm any ideas why this might not of worked?
    – scott marriott
    May 30 '13 at 9:51




    @jordanm any ideas why this might not of worked?
    – scott marriott
    May 30 '13 at 9:51












    ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
    – scott marriott
    May 30 '13 at 9:53




    ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
    – scott marriott
    May 30 '13 at 9:53












    I changed number of days to 1
    – scott marriott
    May 30 '13 at 10:09




    I changed number of days to 1
    – scott marriott
    May 30 '13 at 10:09












    @scottmarriott Not all versions of find support +/- for -mtime. What OS and version of find do you have?
    – jordanm
    May 30 '13 at 13:04




    @scottmarriott Not all versions of find support +/- for -mtime. What OS and version of find do you have?
    – jordanm
    May 30 '13 at 13:04












    up vote
    2
    down vote













    You can just use logrotate. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.






    share|improve this answer
























      up vote
      2
      down vote













      You can just use logrotate. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        You can just use logrotate. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.






        share|improve this answer












        You can just use logrotate. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 30 '13 at 18:56









        Michael Hampton

        5,52911740




        5,52911740



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2funix.stackexchange.com%2fquestions%2f77558%2fscrip-to-delete-files-older-than-6-months%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

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

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?