Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I backup some of my Linux files in a NTFS removable hard disk several days ago, this time I need to remove those files. But I find it difficult since:

  1. On windows, it complains that "Could not find this item"

  2. On a virtual machine whose OS is ubuntu 12.04, when I mount the hard disk(I guess it's using "ntfs-3g") and use "rm", it complains "No such file or directory"; even "ls" fails for the file.

So are there any ways to smash this file correctly?

share|improve this question
1  
Run chkdsk on Windows. It should fix filenames with invalid characters. The colon is normally used for alternate datastream, so maybe the question unix.stackexchange.com/questions/14297/… can help you. –  jofel Nov 21 '13 at 9:09
    
@jofel works when using chkdsk /f, thanks! –  Hongxu Chen Nov 21 '13 at 9:59
    
As it has helped you, I converted my comment into an answer. –  jofel Nov 21 '13 at 13:14

6 Answers 6

up vote 3 down vote accepted

Run chkdsk /f on Windows. It should remove files with invalid characters or fix their filenames so that they can be removed manually.

share|improve this answer
2  
Beware that for filenames that contain colons, the 'fix' is that the files are deleted. –  Royce Williams May 9 at 16:22
    
@RoyceWilliams thanks for your comment, I clarified my answer. The real question is actually how to delete files with invalid filenames. –  jofel May 12 at 15:16
    
Unfortunately, from my testing, once files with colons have been created, chkdsk (and its forced deletion) are the only way to delete the files. –  Royce Williams May 17 at 6:46

NTFS supports "streams", like HFS+'s "forks" and unlike anything on the usual unix filesystems.

The convention on Windows is to name streams as part of the file name, separating the filename from the stream name with a :, which is why you were getting "could not find this item" -- for name "here: try this", Windows was looking for stream " try this" in file "here". I gather you can tell Windows not to parse filenames like this, but I don't know how.

ntfs-3g has a mount option to enable compatible stream-name parsing, mount the fs with -o streams_interface=windows and ntfs-3g will treat : the same way in filenames. So to check for this, mount|grep windows should work well enough.

share|improve this answer

If you've previously tried to run Windows chkdsk on an ntfs-3g filesystem containing colons but that was mounted and used under Linux without either thewindows_names or streams_interface=windows option, the only way to restore NTFS filesystem integrity is to boot a Windows operating system and allow Windows chkdsk to permanently delete all files containing colons.

Put another way: be very, very careful running Windows chkdsk on an NTFS filesystem that has been written to using ntfs-3g under Linux. You will lose all files containing colons.

There are two consequences of using ntfs-3g that interact to cause this:

  1. Tuxera adheres to the letter of the NTFS spec, which allows colons in filenames. However, there is virtually no one using filesystems that are exclusively non-Windows-compatible NTFS, and never intended to be used with Windows, so almost everyone actually needs the non-default behavior.

  2. Tuxera's recommended failsafe way to repair a corrupted NTFS filesystem is to boot a Windows operating system, and run chkdsk. (This will also happen automatically if you boot a Windows operating system and the filesystem is detected as needing repair.)

So if you are interested in long-term stability and safety of your filesystem, you will eventually need to boot a Windows OS and run chkdsk to repair it. But when Windows chkdsk runs, it will delete all files with colons in their filenames without any prompt or warning.

Unfortunately, many folks use NTFS as a universal filesystem for portability and backups. Two common files containing filenames in Linux are emails named after their subject line (Re:, Fwd:, etc.) and emails stored using the Maildir format. So if you are creating an ntfs-3g filesystem from scratch for this purpose, make sure that you always mount it using the windows_names mount option and in /etc/fstab. When you have to eventually run chkdsk, all files created on the filesystem should be valid.

If you don't do this, you may not be able to remove or salvage most or all of your Windows-invalid files (those containing colons, etc.). Once you've created invalid files, Windows will consider the filesystem to be corrupt until those files are purged -- and only Windows will be able to repair the filesystem. So repairing or deleting the files from Linux will be impossible.

share|improve this answer

try rm ./: or rm ./":" or rm ./\: in this order :)

share|improve this answer
    
I tried, but it doesn't work. –  Hongxu Chen Nov 21 '13 at 9:40

I don't understand why this is causing your problems. The following tests were run on an NTFS filesystem:

 $ mount| grep win
/dev/sda3 on /winblows type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other,blksize=4096)
$ grep winb /etc/fstab
UUID=C0BCD19CBCD18D72   /winblows   ntfs    defaults    0   0
$ pwd
/winblows/foo

So, I am in an NTFS partition and I run:

$ touch :a a: a:b
$ ls
:a  a:  a:b
$ rm :a a: a:b

All of those commands work, anyway, possible workarounds are:

rm \:a
rm -- :a
rm ':a'
rm *:*
find . -name "*:*" -delete
share|improve this answer
1  
I'm betting it's the streams_interface mount option: "By using the options "streams_interface=windows", with the ntfs-3g driver (not possible with lowntfs-3g), you will be able to read any named data streams, simply by specifying the stream's name after a colon. For example: cat some.mp3:artist. Named data streams act like normal files, so you can read from them, write to them and even delete them (using rm). You can list all the named data streams a file has by getting the "ntfs.streams.list" extended attribute." –  jthill Nov 22 '13 at 2:00
    
@jthill yes, that sounds like the OP's issue, why not post an answer? Still, all of my suggested workarounds should work. –  terdon Nov 22 '13 at 3:40

Try archiving with winrar - select 'delete files after archiving' in the archiving options. This should move your files to the rar file and delete the original files. Then delete the rar file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.