I am doing a rsync through ssh to download some files, my remote is now full and I want…
- User
I am doing a rsync through ssh to download some files, my remote is now full and I want to find a way to delete the files there once they are downloaded. Tell me ways I could do that safely
Assistant
Here are a few safe ways to delete remote files after downloading them with rsync:
-
Use rsync's built-in
--remove-source-filesoption:rsync -avz --remove-source-files user@remote:/path/to/source/ /local/destination/This only removes files after successful transfer, but leaves empty directories.
-
Create a simple verification and deletion script:
#!/bin/bash rsync -avz user@remote:/path/to/source/ /local/destination/ if [ $? -eq 0 ]; then ssh user@remote "rm -rf /path/to/source/*" fi -
Use find to target specific files you've downloaded:
# First download rsync -avz user@remote:/path/to/source/ /local/destination/ # Then delete files matching certain criteria (e.g., older than 7 days) ssh user@remote "find /path/to/source/ -type f -mtime +7 -delete" -
For incremental deletion, maintain a list of transferred files:
rsync -avz user@remote:/path/to/source/ /local/destination/ --log-file=transfer.log cat transfer.log | grep "^send" | awk '{print $5}' > transferred_files.txt ssh user@remote "xargs -a /path/to/transferred_files.txt rm -f"
Would you like me to explain or elaborate on any of these approaches?
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.