I need to remove all the files from specific folder that is copied to remote machine using following command:

tar -c test_sandy | ssh sky@my_home_vm 'tar -xf - -C /scratch/backup'

I see all the files from test_sandy has been copied to remote machine, now I wanted to remove these files after say one minute:

ssh my_home_vm find $backup_path/test_sandy/* -type d -mmin +1 -exec rm -rf {} \;

But I don't see those file getting deleted, but if, I run the delete it directly from remote machine (instead doing "ssh my_home_vm") it worked.

  • $backup_path is being evaluated on the local system, not on the remote server. Does using find /scratch/backup/test_sandy/ (no * is necessary) change the process?
    – doneal24
    Nov 16, 2021 at 20:55

1 Answer 1


It looks to me like you have forgot to put braces for command after ssh:

ssh my_home_vm 'find $backup_path/test_sandy/* -type d -mmin +1 -exec rm -rf {} \;'

And also $backup_path env variable may not be set when trying to run cmd from ssh, so you can try using the full path. Hope this helps.

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.