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??

Anaphory
  • 712

2 Answers2

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!

marcv81
  • 620
  • 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.

enZyme
  • 364