Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
How to delete large number of files (almost all the files having hard links) at once? Is there any script available to do this.
Here is actual situation:
I have copied the backups of BackupPC to an external drive using "cpio" command preserving all hard links.
Now I want to delete the backup of one host.Deleting the directory of Host from "/pc" doesn't empty any space because all the files in /pc/Host have hard links in /cpool directory
Hi
I just writed a script for this .And I also had a test in my own laptop.Maybe it can help you!
Code:
#!/bin/bash
sourcepath=/pc
linkpath=/cpool
find $sourcepath -type f |ls -li |awk '{if(NR!=1) print $1}'>./inodetmp
for i in $(cat ./inodetmp)
do
find $linkpath -type f -inum $i -exec rm -f {} \;
done
rm -f ./inodetmp
This can help you to remove the hard link in the path of /cpool as you mentioned.Then you can manually remove all files in the path of /pc or add a statement into the end of this script.
Hope this can be useful for you!
I need to delete both files in /BackupPC/pc/<Hostname> and their hard links in /BackupPC/cpool/
So will this script delete the files in /cpool or just remove the hard link and keep files in /cpool.
Thanks,
Mohan
Hi
Actually, if you want to delete the files in order to release some space ,you have to delete both the /pc and /cpool .I think you should read some info about hard link.That will make you more plentiful to understand this .This script will delete the hard link in the path of /cpool,then as I say before,you can manually remove all files in the path of /pc/.So there is no record in the inode info link the space.Hope this is useful.
And you should replace the variable "sourcepath" "linkpath" to your own path,like"/BackupPC/pc/<Hostname>" maybe the sourcepath,and"/BackupPC/cpool/" is the "linkpath".
So you are saying only hard links are removed , but corresponding files are still present in /cpool?
I know about hard links theoretically, but I am not good at scripting so I didn't understand what this line does:
find $linkpath -type f -inum $i -exec rm -f {} \;
Can modify the script so that it will delete the files in "cpool". Deleting file is main concern, removing just hard link and keeping files is of not much use for me.
I have used actual directory paths in the script.
Thanks very much!!!
mohan, you mixed some things I think:
1. cpio cannot make hard links, but probably I missed some options related to it.
2. if you make a new directory structure with cpio and you removes it with rm -rf <target directory> everything will be destroyed what was created by cpio.
3. "removing just hard link and keeping file" means you do not really know what does hard link really means. So please read this first: http://www.cyberciti.biz/tips/unders...ard-links.html
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.