No such file or directory With find -exec rm -f ;

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











up vote
0
down vote

favorite












I have a purge job that runs daily to clean up logs older than 30 days.



find /dir/app/logs -mtime +30 -exec rm -f ;


I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.



The job runs by executing the command:



ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"


against the remote server.



I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.



Currently I'm testing changing ; to + as suggested here:



find - exec rm vs -delete



Thanks in advance for any insight into what's going on.







share|improve this question




















  • Ssh introduces another level of quoting; there’s another question on it here somewhere.
    – Jeff Schaller
    Jan 5 at 18:19










  • Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
    – lightwing
    Jan 5 at 18:33















up vote
0
down vote

favorite












I have a purge job that runs daily to clean up logs older than 30 days.



find /dir/app/logs -mtime +30 -exec rm -f ;


I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.



The job runs by executing the command:



ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"


against the remote server.



I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.



Currently I'm testing changing ; to + as suggested here:



find - exec rm vs -delete



Thanks in advance for any insight into what's going on.







share|improve this question




















  • Ssh introduces another level of quoting; there’s another question on it here somewhere.
    – Jeff Schaller
    Jan 5 at 18:19










  • Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
    – lightwing
    Jan 5 at 18:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a purge job that runs daily to clean up logs older than 30 days.



find /dir/app/logs -mtime +30 -exec rm -f ;


I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.



The job runs by executing the command:



ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"


against the remote server.



I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.



Currently I'm testing changing ; to + as suggested here:



find - exec rm vs -delete



Thanks in advance for any insight into what's going on.







share|improve this question












I have a purge job that runs daily to clean up logs older than 30 days.



find /dir/app/logs -mtime +30 -exec rm -f ;


I am moving our jobs out of cron and into a 3rd party scheduling product, Automic. Since moving this job, I keep getting the error "No such file or directory" randomly. Running the find command at the prompt after receiving the error, without the -exec rm -f ;, always returns no results and runs successfully. Long story short, I'm unable to reproduce the error.



The job runs by executing the command:



ssh user@server "find /dir/app/logs -mtime +30 -exec rm -f ;"


against the remote server.



I have tested various solutions without any luck. Originally, the command ran without -f. Adding -f, I understand, is supposed to suppress errors, but I'm not seeing that happen. I tried replacing -exec rm ; with -delete, but that didn't help either.



Currently I'm testing changing ; to + as suggested here:



find - exec rm vs -delete



Thanks in advance for any insight into what's going on.









share|improve this question











share|improve this question




share|improve this question










asked Jan 5 at 18:17









lightwing

96




96











  • Ssh introduces another level of quoting; there’s another question on it here somewhere.
    – Jeff Schaller
    Jan 5 at 18:19










  • Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
    – lightwing
    Jan 5 at 18:33

















  • Ssh introduces another level of quoting; there’s another question on it here somewhere.
    – Jeff Schaller
    Jan 5 at 18:19










  • Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
    – lightwing
    Jan 5 at 18:33
















Ssh introduces another level of quoting; there’s another question on it here somewhere.
– Jeff Schaller
Jan 5 at 18:19




Ssh introduces another level of quoting; there’s another question on it here somewhere.
– Jeff Schaller
Jan 5 at 18:19












Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
– lightwing
Jan 5 at 18:33





Maybe this? unix.stackexchange.com/questions/212215/ssh-command-with-quotes ssh user@server 'find /dir/app/logs -mtime +30 -exec "rm -f " ;'?
– lightwing
Jan 5 at 18:33











1 Answer
1






active

oldest

votes

















up vote
0
down vote













After some time off and more googling around, this solution may fix the issue:



find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete


It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.



To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:



find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete





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%2f415044%2fno-such-file-or-directory-with-find-exec-rm-f%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
    0
    down vote













    After some time off and more googling around, this solution may fix the issue:



    find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete


    It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.



    To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
    Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:



    find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete





    share|improve this answer


























      up vote
      0
      down vote













      After some time off and more googling around, this solution may fix the issue:



      find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete


      It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.



      To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
      Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:



      find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete





      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        After some time off and more googling around, this solution may fix the issue:



        find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete


        It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.



        To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
        Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:



        find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete





        share|improve this answer














        After some time off and more googling around, this solution may fix the issue:



        find /usr/dir/logs/ -mindepth 1 -mtime +45 -delete


        It appears find and rm were including the parent directory and trying to remove it first, which explains why it sometimes worked, then would throw missing file/directory errors. Using -delete worked fine, and adding -mindepth 1 caused it to skip the parent.



        To retain subdirectories where they shouldn't be deleted, adding -type f to only look at files left those be.
        Additionally, there was one instance where a specific file needed ignored. This appears to work for that situation:



        find /usr/dir/logs/ -mindepth 1 -type f ( ! -name "ignoreme*" ) -mtime +30 -delete






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 6 at 18:58

























        answered Jan 16 at 13:57









        lightwing

        96




        96






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f415044%2fno-such-file-or-directory-with-find-exec-rm-f%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)