NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

GJSchaller's avatar
Jun 15, 2018
Solved

Need help crafting a script to delete files older than 60 days

I have a ReadyNAS that acts as a backup FTP site for some of my websites - every night / week, the websites back themselves up and download via FTP to the ReadyNAS.  So far, so good.   I'd like t...
  • bengsig's avatar
    bengsig
    Jun 17, 2018

    Hmm, I don't understand the \ in your script execution.  The script file (which does not need to have a .sh suffix) should have a first line containinig:

    #!/bin/sh

    and is should have the execute bit set e.g.

    chmod 755 yourscript.sh

    If your script is in any directory in PATH, you can then just call it

    yourscript.sh

    otherwise you need

    ./yourscript.sh

    with no spaces assuming the script is in your current directory.  The following works for me and it will happily do an ls of all files older than 600 days.  I don't want to remove them ;-)

     

     

    bjorn@nas:~$ cat oldfiles  
    #!/bin/sh  
    find . -mtime +600 -exec ls -ld {} \; 
    bjorn@nas:~$ ls -l oldfiles
    -rwxr-xr-x 1 bjorn engsig 49 Jun 17 13:54 oldfiles
    bjorn@nas:~$ ./oldfiles

     

NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology! 

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More