1

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

0

To unlink files,

unlink /path/to/the/link_file

If you delete the dir it doesn't unlink themselves.And if you click on the link after deleting dir,it will shows like this,

enter image description here

  • what's /path/to/the/link_file according my question: /some_path or /dir/file1? – アレックス Nov 26 '13 at 8:04
  • you doesn't know where the link was located. – Avinash Raj Nov 26 '13 at 8:07
  • no, I don't. So how can I unlink /path/to/the/link_file then if I don't know what /path/to/the/link_file is ? – アレックス Nov 26 '13 at 8:08
  • If a link was created on Downloads folder for an avinash folder in desktop.Then removing the link by running this command. unlink ~/Downloads/avinash – Avinash Raj Nov 26 '13 at 8:19
  • I know only path to dir and nothing else. – アレックス Nov 26 '13 at 8:21
0

If somepaths 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 approach

find -L / -xdev -samefile /dir/file1

So 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

find -lname "*passwd*"

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 post

find / -xdev -type l ! -exec test -e {} \; -print

If you intent to get rid of those broken symlink, you can use -delete flag as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.