7

I have a directory with images. Suddenly I found out that there's a new image with a new name. The image content is similar to another image in another directory but with a different name. I didn't copy this image to this directory.

Also a directory with the same name as the image suddenly appeared there. I didn't create any of them. When I tried to delete them I got this message "No such file or directory" even though it already existed there. I used the command sudo rm -rf imagename.jpg to delete it but it didn't work.

Can anyone explain why this is happening and how to solve it?

The output of ls -l "large (2).jpg":

-rw------- 1 alaa alaa 2859942 Jun  8 04:01 large (2).jpg

The output of rm "large (2).jpg":

rm: cannot remove ‘large (2).jpg’: No such file or directory

The output of printf %s\\0\\n ./large* | sed -n l

./large (20).jpg\000$
./large (26).jpg\000$
./large (2).jpg\000$
./large (5).jpg\000$

The filesystem is NTFS.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Alaa
  • 325
  • 3
  • 6
  • 13

2 Answers2

4

I once posted a pretty in-depth look at NTFS file-streams as related to the linux ntfs-3g driver due to a similar issue on a different question. I remembered it, and - guessing that your problem was also on an NTFS partition - I posted this comment here:

If it's NTFS I suspect this. This can occur if a file's basic permissions are modified as you end up affecting the stream. I think that's what happens. It's complicated - and probably at least a little beyond me. But it happens. Anyway, run chkdsk in Windows.

Apparently, and happily, this has solved your issue.

mikeserv
  • 57,448
  • 9
  • 113
  • 229
  • I ran chkdsk utility in Win, but to no avail. The files are still there. I created them in Linux, and they contained ":" character, which is prohibited in Windows. What should I do? – soshial Dec 01 '15 at 09:44
  • @soshial - delete them. do it from your unix boot first. them reboot and chkdsk. – mikeserv Dec 01 '15 at 09:51
  • deleting with rm in linux gives me only "no such file or directory". – soshial Dec 01 '15 at 13:43
  • 1
    Be *very* careful running Microsoft's chkdsk after using NTFS from another OS like Linux. chkdsk will consider all filenames with colons that it finds as invalid, and *immediately* delete them without warning (rather than altering the filename and preserving the data). See my answer here for more info: https://unix.stackexchange.com/a/128697/12947 – Royce Williams Oct 06 '17 at 19:26
0

Try:

rm -i large*.jpg

This will ask you whether to delete every matching file. Say "no" for all the files other than this one.

Barmar
  • 9,648
  • 1
  • 19
  • 28