faster way to get all files with links in a directory
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
faster way to get all files with links in a directory
hi,
I search all files that have a link into a directory
currently I go through all files in this directory,
check if this file is a link, and if ...
if this is a huge dir (lots of files), this takes very long time.
I wounder if there is a faster/more efficient way to this
What do you mean "have a link"? Are you trying to find all links in a directory, or all files that have a link pointing to them from elsewhere? Symbolic links or hard links?
symbolic links
I need the targets of all links in a directory
currently I go through all files in the directory, if the file is a link than I readlink the link and the result goes into a list.
and this is, if there are very many files and some of them are symbolic links, a very expensive operation,
so I wounder if there is a better way, maybe a file system that knows something or something else, a magic trick possible :-)
You can use the -type l flag in find to find symbolic links, then exec to pass it to readlink. It would probably be faster than looping through every file and checking if it's a link.
will check this,
I suspect that find -type l will do the same loop I do, I guess, go through all names, stat each name and check type
I do not run a bash script, I use the C api, but I will measure it there is a difference between my code and find -type l
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.