Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a large directory with many files and directories. A few of those MAY be targets to symlinks. I don't really know if they exist much less which ones they are. How do I find those?
ls -l will color its output and you will see. You can use find to identify links. And there are a lot of other ways using test, perl, python, shell, whatever.
ls -l will color its output and you will see. You can use find to identify links. And there are a lot of other ways using test, perl, python, shell, whatever.
There was a recent thread on this here...suggest the OP search for it. It's been in the last couple of weeks and contained considerable discussion.
If I understood that thread, it's not possible to know that a given file is a target of a softlink. It may be possible to detect targets of hard links.
find ~ -type l -exec readlink --canonicalize {} \;
Or also the symlink?
Now that is a useful answer! I knew that there had to be some unix tool that would make that task easier. I was just hoping that someone would point it out. Thank you!
I also found a program called symlinks on the Debian repository that will do exactly that. It takes a while to scan all potential directories, but once I have that report, grep will tell me exactly what I need.
Solved. Thank you again, Turbocapitalist. Nice nickname, btw.
from grammatical point of view the question "how do I find those" may mean both "how do I find those symlinks" or "how do I find those files".
from the other hand we need to scan the whole directory tree and collect all the symlinks and finally print links, targets or both. That is completely irrelevant. I mean technically. What Turbocapitalist posted is most probably the slowest solution, implementing the same algorithm in perl/python - or bash will do the job too. Including the "postprocessing" mentioned in post #7.
And the problem is still not completely solved, because there can be links pointing to nowhere and there can be link chains pointing finally to a file (or dir or ?), there can be link loops ...
As for the links pointing to nowhere, they can be culled or identified. See --canonicalize-existing or --canonicalize-missing for readlink. In the case of a loop, it gets treated as a link with a missing target.
Edit: agreed about perl being faster to run.
Last edited by Turbocapitalist; 02-04-2019 at 10:26 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.