Operating System - HP-UX
1825795 Members
2211 Online
109687 Solutions
New Discussion

how to remove symlink to directory where target directory is not empty

 
SOLVED
Go to solution
John Kittel
Trusted Contributor

how to remove symlink to directory where target directory is not empty

How can I remove a symbolic link to a directory, when the target directory is not empty?

( rm doesn't work because the link is to a directory. rmdir doesn't work because the directory isn't empty. I want to remove the sybolic directory link, not the target directory or files.)

- John
4 REPLIES 4
Sandman!
Honored Contributor

Re: how to remove symlink to directory where target directory is not empty

Shouldn't matter...rm should do the job unless there are invisible characters in the symbolic link name.

~cheers
Pete Randall
Outstanding Contributor

Re: how to remove symlink to directory where target directory is not empty

$ mkdir testdir
$ touch testdir/teststuff
$ ln -s testdir test_dir
$ rm test_dir
$ ll testdir
total 0
-rw-rw-r-- 1 plr support 0 Dec 6 13:22 teststuff


Pete

Pete
Heironimus
Honored Contributor
Solution

Re: how to remove symlink to directory where target directory is not empty

When you remove the link make sure it doesn't have a trailing slash in the rm command line. If it has a trailing slash it will look at the target directory, without a trailing slash it refers to just the symlink.
John Kittel
Trusted Contributor

Re: how to remove symlink to directory where target directory is not empty

Ah! Thanks Heironimus! The trailing slash was goofing me up. I normally wouldn't type the trailing slash myself, but I was using the shell's filename completion, and it was putting it in there for me.

- JOhn