Software⏱️ 4 min read📅 2026-06-11

How to Fix: Don't copy files that cause an input/output error

Learn how to skip faulty files during file copy operations.

Quick Answer: Use the --ignore-existing option with rsync or scp, or delete the destination directory and recreate it after copying.

When copying files from a faulty hard drive using cp, rsync, or scp, users may encounter an issue where partially copied files are still written to the destination directory. This can be frustrating for those who rely on these tools for data transfer and backup.

This problem is often caused by the operating system's inability to properly handle corrupted file data during the copy process. The faulty files that cannot be read anymore may still be sent to the destination drive, potentially causing further damage or data loss.

🔍 Why This Happens

  • The primary reason for this issue lies in the way these copying tools handle file metadata and error checking. When a file fails to be copied due to an input/output error, the tool may not properly mark it as corrupted or skip it altogether. As a result, partially copied files can still be written to the destination drive, leading to further issues.
  • An alternative reason for this issue could be related to the specific operating system or file system being used. In some cases, the file system's journaling mechanism may not be able to handle corrupted file data effectively, causing partial copies to be written to the destination drive.

🔧 Proven Troubleshooting Steps

Using the -i option with cp and rsync

  1. Step 1: To fix this issue using cp, use the -i option, which tells the tool to prompt for confirmation before overwriting each file. This can help prevent partially copied files from being written to the destination drive: `cp -i source_directory destination_directory`.
  2. Step 2: For rsync, use the --delete option, which removes files from the destination directory if they are no longer present in the source directory. This can also help remove partially copied files: `rsync -ai source_directory destination_directory`.
  3. Step 3: Using the -i option with scp provides a similar solution for secure copy operations: `scp -i user@host:/path/to/source /local/destination`.

Using the --delete and -- prune options with rsync

  1. Step 1: For an alternative approach, use the --delete option with rsync to remove files from the destination directory if they are no longer present in the source directory. This can help remove partially copied files: `rsync -ai --delete source_directory destination_directory`.
  2. Step 2: Additionally, using the --prune option with rsync can help remove empty directories and files from the destination directory. However, this may not directly address partially copied files, but it can help maintain a more organized file system.

💡 Conclusion

To avoid copying files that cause an input/output error, it is recommended to use the -i option with cp and rsync, or the --delete and --prune options with rsync. By taking these precautions, users can ensure that partially copied files are not written to the destination drive, reducing the risk of further data loss or corruption.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions