3

It looks like I have a folder containing a folder with empty file name.

$ ls -alF Antonin_Dvorak/
total 12
drwx------ 3 VUW\me VUW\domain users 4096 Jan 22  2015 /
drwx------ 3 VUW\me VUW\domain users 4096 Jan 22  2015 ./
drwx------ 3 VUW\me VUW\domain users 4096 Aug 25 11:10 ../

It does show up as empty in python.

$ python
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.listdir()
['']
>>> len(os.listdir('Antonin_Dvorak')[0])
0

When I switch into the directory and run ls, I get an error

$ cd Antonin_Dvorak
$ ls
ls: cannot access '': No such file or directory

$ ls -alF
ls: cannot access '': No such file or directory
total 8
d????????? ? ?             ?                   ?            ? /
drwx------ 3 VUW\kaipingga VUW\domain users 4096 Jan 22  2015 ./
drwx------ 3 VUW\kaipingga VUW\domain users 4096 Aug 25 11:10 ../

I assume that at some point, the file name may have been an album/music title containing cyrillic characters, but in the meantime moving the folder to a different fs, moving it to trash, and a distribution upgrade happened. The filesystem containing this folder is

$ mount | grep grep $(pwd | head -c 9)
/etc/auto.master.d/issc_nfs_homedir.conf on /vol/home type autofs (rw,relatime,fd=6,pgrp=1310,timeout=300,minproto=5,maxproto=5,direct)
vuwunix01:/vol/vfiler_vuwunix01_data01/users on /vol/home type nfs4 (rw,nosuid,relatime,vers=4.0,rsize=65536,wsize=65536,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=krb5,clientaddr=132.229.239.78,local_lock=none,addr=132.229.18.60)

I do not want to recover the content, I just want to delete that whole Antonin_Dvorak folder.

$ cd ..; rm -rf Antonin_Dvorak/
rm: cannot remove 'Antonin_Dvorak/': Directory not empty

I do not have root access to this machine at the moment, and note that this is on a network share. What should I do?


Wait, what? I'll edit this into the question body, but:

$ ls -ial Antonin_Dvorak/
total 12
24005685 drwx------ 3 VUW\kaipingga VUW\domain users 4096 Jan 22  2015 
24005685 drwx------ 3 VUW\kaipingga VUW\domain users 4096 Jan 22  2015 .
47956345 drwx------ 3 VUW\kaipingga VUW\domain users 4096 Aug 25 11:10 ..
$ #So, no surprise here:
$ find . -maxdepth 1 -type d -inum 24005685 -delete
find: cannot delete ‘./Antonin_Dvorak’: Directory not empty

It's not just a nameless random folder. It's a nameless hard link to the folder itself??

  • 1
    Run fsck. Does that get rid of the problem? – Hauke Laging Aug 25 '17 at 9:37
  • @HaukeLaging He can't run fsck without root access. – Kusalananda Aug 25 '17 at 9:38
  • Try to copy files/directories from parent directory to other directory and remove entire parent directory with rm -rf – mrc02_kr Aug 25 '17 at 9:39
  • 2
    Possible duplicate of How can I delete a file with no name – X Tian Aug 25 '17 at 9:55
  • 2
    This is on a network (SMB probably) share. So either the exported directory is corrupt and it should be fixed on the server side (the one that shares the directory) or your local SMB driver (the one that mounts it) has a bug and it should be updated. – xhienne Aug 25 '17 at 10:30
3

You can delete the folder by inode.

First, find the inode number with ls -ial Antonin_Dvorak/.

Sample output:

$ ls -ial Antonin_Dvorak/
total 12
25306387 drwx------ 3 VUW\me VUW\domain users 4096 Jan 22  2015 /
23592962 drwx------ 3 VUW\me VUW\domain users 4096 Jan 22  2015 ./
23592391 drwx------ 3 VUW\me VUW\domain users 4096 Aug 25 11:10 ../

You cannot pass an inode to rm directly, but there is a trick with find.

find . -maxdepth 1 -type d -inum 25306387 -delete

Do make sure you replace my sample inode (25306387) with the one on your system!

  • Excellent idea. Unfortunately in this case it turns out It's not just a nameless random folder. It's a nameless hard link to the folder itself! What on earth?? – Anaphory Aug 25 '17 at 10:08
  • I do not know the answer, but this makes the question significantly more interesting! I suggest you edit the title, or maybe even ask a different question: some of the details are no longer relevant to what the issue turns out to be. – marcv81 Aug 25 '17 at 10:38
0

Try using unlink. Since its a hard link you will need to unlink it then rm -r will work.

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.