1840213 Members
3619 Online
110162 Solutions
New Discussion

Symbolic links

 
SOLVED
Go to solution
Dan Decker
Frequent Advisor

Symbolic links

How do you remove a link from the directory location where the file is referenced from. For instance I move a file to another location and in the process created a link in its former location pointing to the new location. The link was improperly created but once created I cannot remove it. there is a "- ->" ahead of the file name instead of behind it. I want the file in the new location and i want to reference it there and I also want the link to be in the old location. any help would be greatly appreciated. I have a number of files to move.

Thanks
DKD
It's not done Till I am satisfied
6 REPLIES 6
Rodney Hills
Honored Contributor

Re: Symbolic links

- and > are bad in filenames.

cd to the directory with the bad name. Enter
rm ./--\>restofname

This will delete the file.
\> prevents the > to mean send output to.

-- Rod Hills
There be dragons...
S.K. Chan
Honored Contributor

Re: Symbolic links

Not quite get what you mean .. I'm sure someone would. I'm throwing something here that you might know already. When moving files or dir, to preserve the sym link you can do this .. (simple eg : to move everything under /var/source to /var/dest)

# mkdir /var/dest
# cd /var/source
# find . |cpio -pvdumx /var/dest

hope it helps a little ..
Darrell Allen
Honored Contributor
Solution

Re: Symbolic links

Hi Dan,

I'm not sure I follow but here goes (pardon me if this is too elementary):

fileA exists in dirA
you want to move fileA to dirB
you want a symlink in dirB to fileA

cd /dirA
mv fileA /dirB/fileA
ln -s /dirB/fileA symlnkA

Now you should have a symlink (/dirA/symlnkA) pointing to /dirB/fileA
You can rm /dirA/symlnkA just as though it's a normal file.
You can rm /dirB/fileA and /dirA/symlnkA will still exist - it just points to a file that doesn't exist.

It sounds like from your post that the filename for the symlink you are trying to remove actually has --> in it's name. Try rm -i *filename.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
harry d brown jr
Honored Contributor

Re: Symbolic links

Did you create a hardlink?

Do this:

ls -li *partofthefilename*

go to the other directory and do the same. then post the results.

thanks

live free or die
harry
Live Free or Die
ramesh_6
Frequent Advisor

Re: Symbolic links

A file should never be - and >

cd to the directory with theat name. Enter
rm ./--\>restofname

This will delete the bad file.

If you want to symbolically link a file

file y exists in dir x
You like to move file y to dir z
you want a symbolic link in dir z to file y

cd /dir x
mv file y /dir z/file y
ln -s /dirz/filey linkY

Now you will be having a symlink (/dirX/lnkA) pointing to /dirz/filey
You can rm /dirx/lnky just as though it's a normal file.
You can rm /dirz/filey and /dirz/lnky will still exist. It just points to a file that doesn't exist.


Hope this helps

Ramesh


Dan Decker
Frequent Advisor

Re: Symbolic links

Thanks to everyone who responed. Sometimes when we aren't thinking very straight and the flu sort of takes control of your brain cells things happen that we don't intend or we just aren't thinking clearly. You all have proved what a valuable resource this program is. Thanks for your help. Some instructions were more clearer than others and some time the most elemetary explainations are the most helpful. Thanks again
It's not done Till I am satisfied