So I can do this: sftp user@server

These are the files https://gist.github.com/438a6b82aff3064a19c9

i need to delete files older than 60 days.

Any way to automate this?

find command doesn't work. deleting by wildcard doesn't work.

Rsync is supported. How is it done with rsync?


As an alternative to the better options above you could script (using lftp or something) to delete all files using a wildcard and a local date substiatution.

It's very ugly but it works:

for i in 60 999; do lftp sftp://user@host -c "rm /path/to/website_production_$(date -d "$i days ago" +%m-%d-%Y)*" done

You might want to set it up so you don't have to enter the password.


Mount the sftp folder on your system, if you are using OS X you can use Transmit to do that or Linux (Ubuntu in this case) you can use this guide http://blog.damontimm.com/how-to-mount-a-sftp-folder-ssh-ftp-on-ubuntu-linux-using-sshfs-fuse/ .

They all use FuSE, so I bet it also works in Windows as well if you look it up. But once you have it mounted you should be able to use any commands you can natively on your system.


Rsync protects date of creation. So you can rsync all files to your computer. Then run find to select files older than 60 days and delete them. And upload them back via rsync. Or just delete them in destination.


Result of rsync test on local directories:

rsync -av input/ tmp/
find tmp/* -mtime +10 -exec rm {} \;
rsync --delete -av tmp/ input

After this, directory ./input/ is stripped from files modified more then 10 days ago. This should be appliable on remote directory via SFTP.

  • i see. that's not too easy :/ – kgpdeveloper May 20 '10 at 6:50
  • It's not hard, he gave you the exact commands. Replace "input" with sftp://youruser@theserver:/pathname – Joris Jul 2 '10 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.