I have a folder with many files those have a few sym links pointing to them like
/some_path -> /dir/file1
/some_path2 -> /dir/file2
/some_path3 -> /dir/file3
But I don't remember neither the some_path
s no which files from dir
have sym links pointing to them.
Now I need to delete dir
(I really need it for some reason). And I also want no file to point to any file from dir
since I'll delete it.
How do I unlink those files? What if I just delete dir
, will they unlink by themselves?
To unlink files,
If you delete the
dir
it doesn't unlink themselves.And if you click on the link afterdeleting dir
,it will shows like this,If
somepath
s are in the same location and assuming they are on the same filesystem as/dir
, we could make a guess and use Dennis Williamson's approachSo assuming
/dir/file1
is original and say/opt/foo
is symlink, this command should traverse/
without crossing/
's filesystem boundaries and find all files that are the same as original. That would include symlinks and hard links.We could also use
lname
to see if contents of symlink point to/dir/file1
However, more reasonable approach would probably be to either move or delete
dir
first, and then look for broken symlinks as suggested by the user rozcietrzewiacz's answer on the relevant postIf you intent to get rid of those broken symlink, you can use
-delete
flag as well