hard links problem: how to delete all pointers to an inode at once?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
there is really no way i know of to follow links backwards. i think that might be for security reasons ? not sure. it would also violate the basic "no special cases" rule.
I don't know a quick method to do this. A slow method would be to use find to scan the whole filesystem. The only real optimisation you can do is to note where the volume (partition) is mounted and only search down that tree - hard links cannot link across volumes.
e.g. if you have /dev/sda2 mounted at /home, and you want to find all files which are hard links to /home/matthew/.bashrc, you might do it like this:
Code:
i=$(ls -i /home/matthew/.bashrc |cut -f1 -d" ")
find /home -type f -print0 |xargs -0 ls -i |grep "^$i "
If you want to perform this operation for multiple files, you might want to make a list of all the inode / filenames in one find operation, sort it, find repeated inode numbers and print those. One approach is to create a (sorted) temporary file with the inode and file names, another with the inodes which are found more than once, and then use the join command to print all lines in the first file for each inode in the seconds. Don't forget to clean up your temporary files afterwards.
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Rep:
If you run the command repeatedly "locate" would be faster than "find", since it is working with an existing database (which can be brought to the newest information of your system by "updatedb").
<edit> "slocate" is said to be more advanced as locate... </edit>
Last edited by JZL240I-U; 10-17-2007 at 01:07 AM.
Reason: Forgot to mention "slocate"
sorry i totally forgot about the question since my idea to implement a packet manager for LFS with hard links was proved wrong. To put it short - deleting hard linked files (all inode pointers at once) is to slow (i was looking for solution with constant time). One can modify the file table on the disk to keep record of inode pointers, but... Anyway thx for suggestions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.