Pass `find` results to `rclone delete` command

I'm wondering if it's possible to pass find results to an rclone delete command.

For example, I have the following command to list certain files:
find ./ -name 'search_term*' -type f ! -newer /tmp/mytime

This finds files in the current folder with a name including search_term that's older than a specified file. Works great.
But
When I add | xargs rm -rf to delete those files, the operation just hangs forever.

So I wonder if I could pass the results to an rclone delete command, like this:
find ./ -name 'search_term*' -type f ! -newer /tmp/mytime | rclone delete remote:

where the remote path(s) are the results returned from the find command.

You could use find to create an intermediate file with the results. And then use the '--include-from' as part of a delete command.

You could also think about changing your processing to just use rclone instead. that is, read the time from /tmp/mytime, calculate the difference in seconds or some number, and then use rclone to natively do the search.

rclone delete -include=search_term** --min-age x --max-age y etc

1 Like

calisro's solutions are what I typically use when doing these kinds of deletes.

But if you are more comfortable/happier with find then you can try piping the results into rclone deletefile. Just be sure you have the syntax correct for the path. Easy to check with --dry-run.

https://rclone.org/commands/rclone_deletefile/

That is what I'd do, except I'd use --files-from rather than --include-from, like this

find ./ -name 'search_term*' -type f ! -newer /tmp/mytime | sed 's/^.\///' > filez
rclone delete --dry-run -files-from filez remote:
1 Like

These are fantastic suggestions. Worked like a charm. The sed bit is what made it all work, so thanks for that as well @ncw

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.