FreeBSD/UNIX: Hard linked directories? How to remove?

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
OK, I have a (what I think is) hard link called /usr/local/www/testHomeDirs which links to /home.

I want to delete the /usr/local/www/testHomeDirs directory, BUT NOT DELETE ALL THE STUFF IN THE /home directory.

rm -i testHomeDirs tells me 'testHomeDirs is a directory.'


How can I just delete the link, without deleting all of my files?
 

doornail

Senior member
Oct 10, 1999
333
0
0
Hmmm, I thought you couldn't make a hard link to a directory.

What does:

$ file testHomeDirs

give you?
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
# file testHomeDir
testHomeDir: directory

I don't know exactly what I did to get it like this, I did it a while ago... I think you might be able to create hard links to directories, but just as root or something...?

Will rmdir delete the files in the directory?
# rmdir testHomeDir
rmdir: testHomeDir: Directory is not empty
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
I can't seem to make a hardlink to a directory on OpenBSD, even as root.

ln -id testHomeDir
ln -id /home
 

doornail

Senior member
Oct 10, 1999
333
0
0
Wow, that's odd. I assume:

# file /home

Gives the same?

Iffen I was you, I'd:

*** Edit: don't use this yet, it didn't seem to copy the ownership correctly when I tried ***

# cp --preserve --recursive /home /home.backup
# rm -rf /usr/local/www/testHomeDirs

(and if /home is gone)
# mv /home.backup home

(else)
# rm -rf /home.backup
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: doornail
Wow, that's odd. I assume:

# file /home

Gives the same?

Iffen I was you, I'd:

*** Edit: don't use this yet, it didn't seem to copy the ownership correctly when I tried ***

# cp --preserve --recursive /home /home.backup
# rm -rf /usr/local/www/testHomeDirs

(and if /home is gone)
# mv /home.backup home

(else)
# rm -rf /home.backup

Those options aren't available in cp(1). Those are GNUisms. ;)
 

Bluestealth

Senior member
Jul 5, 2004
434
0
0
Originally posted by: Superwormy
# file testHomeDir
testHomeDir: directory

I don't know exactly what I did to get it like this, I did it a while ago... I think you might be able to create hard links to directories, but just as root or something...?

Will rmdir delete the files in the directory?
# rmdir testHomeDir
rmdir: testHomeDir: Directory is not empty

Not sure how you linked it... but yes rmdir probably would erase /home given that error message.
 

scottws

Senior member
Oct 29, 2002
468
0
0
Wait a minute....

Now, I can't say I can call myself an expert or anything, but in a Linux system admin class I took I learned that hard links are basically two files with the same inode (whereas a symbolilc link simply points to another inode iirc).

Personally, I think it's safe to delete testHomeDir. However, you might have to copy the entire contents of /home to some other place for backup, then clear out everything there in order for it to appear empty so that you can remove testHomeDir.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
No sane system will allow you to create hardlinks to directories because it makes impossible to detect infinite loops. I would backup the directory and run fsck on the drive, there's a good chance it'll 'fix' the situation by removing one of the links, if one really is a hard link.

Those options aren't available in cp(1). Those are GNUisms.

It's not our fault you have a subpar cp. =)