2

I just ran some self-written program in which I make files and fill them with stuff. However, I did something wrong (or at least, not as intended) with the name generation and now there are four files stuck in the folder which cannot be removed as they 'do not exist'.

Outputs of commands:

ls -li:

ls: cannot access één: No such file or directory
ls: cannot access wetenschap­pen.: No such file or directory
ls: cannot access verantwoor­delijk: No such file or directory
ls: cannot access woord wordt: No such file or directory
total 0
? -????????? ? ? ? ?            ? één
? -????????? ? ? ? ?            ? woord wordt
? -????????? ? ? ? ?            ? verantwoor­delijk
? -????????? ? ? ? ?            ? wetenschap­pen.

rm -i -- *:

rm: remove regular file `één'? y
rm: cannot remove `één': No such file or directory
rm: remove regular file `woord wordt'? y
rm: cannot remove `woord wordt': No such file or directory
rm: remove regular file `verantwoor­delijk'? y
rm: cannot remove `verantwoor­delijk': No such file or directory
rm: remove regular file `wetenschap­pen.'? y
rm: cannot remove `wetenschap­pen.': No such file or directory

rm -rf folder: (with 'folder' being the folder the files reside in)

rm: cannot remove `folder': Directory not empty

find . -type f -delete: (as from the answer of Uditha Desilva)

find: cannot delete `./één': No such file or directory
find: cannot delete `./wetenschap­pen.': No such file or directory
find: cannot delete `./verantwoor­delijk': No such file or directory
find: cannot delete `./woord wordt': No such file or directory

strace -o out rm -f -- *: Contents of out

How can I remove these files?
Important to note is that I do not have root access, so I would prefer an option which does not require that.

  • What OS are you running? – Andrew Henle Mar 3 '16 at 11:41
  • Ubuntu 12.04.5 LTS with Linux 3.13.0-79 – Simon Klaver Mar 3 '16 at 11:46
  • What filesystem? Can you unmount it and fsck it? The output from strace -o /some/output/file rm -f -- * or strace -o /output/file find . -type f -delete run from in the directory would also be interesting. – Andrew Henle Mar 3 '16 at 12:04
  • The filesystem is ext4. As stated I have no root access, so no unmounting and fsck'ing. Output of strace is in question. – Simon Klaver Mar 3 '16 at 12:47
  • Well, that's really strange. Can you post the output from strace running the find . -type f -delete command? – Andrew Henle Mar 3 '16 at 13:26
2

Just delete the file from UI as Move to trash. and then go to trash and delete from there. This process will permanently delete your file from your linux system.

  • Someone care to explain why this worked while the rest did not? (did not test tachomi's answer though) – Simon Klaver Mar 3 '16 at 17:03
0

This behavior is due to the missing execute permission in the directory, the user can't do a stat() but can read the dir entries.

To avoid this you can do chmod 700 to the main directory.

To reproduce again this behavior you can do a chmod 600 or chmod 400 on any dir and it will have the same issue.

$ chmod 400 folder
$ ls - ltr folder
-????????? ? ? ? ?            ? omd
-????????? ? ? ? ?            ? file5
-????????? ? ? ? ?            ? file4
-????????? ? ? ? ?            ? file3.txt
-????????? ? ? ? ?            ? file2.txt

$ chmod 700 folder
$ ls - ltr folder
-rw-rw-r-- 1 tachomi tachomi  2 Mar  2 08:53 file4
-rw-rw-r-- 1 tachomi tachomi  2 Mar  2 08:53 file5
-rw-rw-r-- 1 tachomi tachomi  0 Mar  2 08:53 omd
-rw-rw-r-- 1 tachomi tachomi  2 Mar  2 09:01 file1.txt
-rw-rw-r-- 1 tachomi tachomi  2 Mar  2 09:01 file2.txt

Give a try

0

It's almost as if you've managed to write garbage into the directory inode itself rather than into files within it. However, try

find . -type f -delete

which doesn't try to do shell expansions of the files and may thus succeed.

EDIT: The answer by tachomi does appear to be the most likely explanation, but it isn't possible to "cd" into a directory with 400 mode, or list its' contents once you are in it, so that does not fit perfectly either:

$ chmod 400 test
$ ls -li test
ls: cannot access test/Pictures: Permission denied
ls: cannot access test/Music: Permission denied
ls: cannot access test/Shows: Permission denied
ls: cannot access test/TV: Permission denied
ls: cannot access test/Movies: Permission denied
total 0
? -????????? ? ? ? ?            ? Movies
? -????????? ? ? ? ?            ? Music
? -????????? ? ? ? ?            ? Pictures
? -????????? ? ? ? ?            ? Shows
? -????????? ? ? ? ?            ? TV
$ cd test
bash: cd: test: Permission denied
$ chmod 700 test
$ cd test
$ ls -li
total 0
267447 -rw-r--r-- 1 abcd abcd 0 Mar  3 19:45 Movies
267448 -rw-r--r-- 1 abcd abcd 0 Mar  3 19:45 Music
267449 -rw-r--r-- 1 abcd abcd 0 Mar  3 19:45 Pictures
267451 -rw-r--r-- 1 abcd abcd 0 Mar  3 19:45 Shows
267450 -rw-r--r-- 1 abcd abcd 0 Mar  3 19:45 TV

However, the delete may have worked if the GUI delete process changed directory permissions "behind the scenes" prior to removal.

  • Didn't work, updated the question. – Simon Klaver Mar 3 '16 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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