I have an external usb-drive where some of the filenames contain a ":", e.g.. Screenshot-08-09-12 -08:10:45.png (Old screenshots). I can copy these files towards the hard-disc of my computer, but I cannot copy them back to the external hard-disc as there renamed automatically by the files-application. The cp command in the terminal returns an error with an illegal argument.
I'm using this drive on Ubuntu 20.10 as well on LinuxMint 20. How can I copy such a file back to the external hard-drive without being renamed?
I understand that the feature of renaming such kind of filenames has been implemented in order to deal with filesystems which are only supporting Microsoft-filenaming.
Filetype of the external disc : NTFS (Partitiontype : NTFS/exFAT/HPFS)
I don't know how the file was saved to the HDD in the first place as the colon character (
:
) us reserved in NTFS. I suppose the filename is left "as is" when copying the file to Ubuntu or Mint as they can deal with the colon in the filename without a hitch.If copying them back to the NTFS formatted HDD works in Mint you maybe have a "middleman" translating the filename so that it's NTFS compatible. As proposed this StackOverflow question you can maybe try to use Unicode characters that are NTFS compatible and that visually resemble a colon.
If you could provide the exact error message you get when running
cp
as well as the exact command causing it I would maybe be able to provide further guidance.All in all, try using a different Unicode character instead of a colon as it's "reserved" on the NTFS file system.
I describe how it works in Ubuntu when the file systems of the source and the target are Linux file systems, for example ext4, which is the standard file system of Ubuntu. (Other [non-linux] file systems may cause problems.)
It works for me to copy files with colon in the name using
cp
when quoting the file name with single quotes or double quotes.Example: if you want to keep the file name
or
Example: if you wish, you can change the file name
and this may help, if the target file system does not accept colon in the file name.
Edit 1:
I can confirm that it works for me to write a file with colon in the file name to an NTFS file system. This makes me think that you have problems with either the mount options or the file system.
If mount options (ownership and/or permissions) is the problem, maybe this link can help.
It is also possible that the file system is dirty (was shut down without flushing the buffers) or damaged in some other way. In such cases Linux will often default to mounting read-only. You can try to repair the file system, and Microsoft file systems should be repaired using Windows.
Edit 2:
See also the following link, that asks how to forbid certain characters (e.g. colon) in file names so that they work correctly in Windows (which is not the same thing as being stored and accessed by Linux in NTFS).
Make Linux forbid colons in file names on NTFS partitions