Is there, perhaps, an *honest* alternative to the basic cp command?

The basic Linux cp command, and also other tools that might use it under the hood, seem to be basically “dishonest” about what’s going on while they’re copying things. They’ll tell you that a file is already completely copied when they’re really still busy writing the file, or even an earlier file in the same copying task, to the target location.

I find it pretty annoying how sometimes, when I’m copying files to or from a USB device, the system tells me that the copying job is already done, but at the same time, also tells me that I can’t unmount the device yet because writing stuff to it or reading stuff from it is still going on, and I have no idea how much longer that will last.

So, is there, perhaps, some alternative to the standard cp tool where I wouldn’t run into this issue?

What you’re seeing is not really cp being dishonest.
It’s mostly caused by write caching in the kernel.

When a program writes data, the filesystem often stores it in RAM first and then flushes it to the device in the background. So the copy command finishes when the data is safely handed to the kernel, not necessarily when it is fully written to the USB device.

If you want better feedback while copying, some alternatives are:

  • rsync --progress
  • gcp (a cp replacement with a progress bar)
  • pv for monitoring transfer progress

And if you want to be sure everything has actually been written to the device, you can run:

sync

This forces the system to flush all cached writes before returning to the shell.

6 Likes

Thank you! I think I’ll go with rsync for now.

1 Like

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