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 would like to mirror a folder with hardlinks.
Then I can go through and change some of the files, while keeping most the same.
The script I have so far is this:
Code:
#!/bin/bash
old="jaunty"
new="lucid"
dir="/conf"
cd $dir
find . -type d -exec mkdir -p $dir/$new/{} \;
find . -type f -exec ln $dir/$old/{} $dir/$new/{} \;
The problem with this is since I make the folders again, this doesn't preserve their permissions.
Is there any way to do this better? I feel like rsync should have an option for this, but I can't find it...
Are you aware that hard links point to the same file and that changing a hard linked file under one name will change it under all names that refer to it?
How about using chmod and chown with the --reference option, something like find . -type d -exec mkdir -p $dir/$new/{} \; -exec chmod --reference {} $dir/$new/{} \; -exec chown --reference {} $dir/$new/{} \;
You cannot hardlink a directory, at least when using filesystems that use traditional POSIX semantics; I bet BtrFS will let you do it with a judicious use of subvolumes sometime in the future.
Now, you can create directory trees with hardlinked files easily if using GNU coreutils and rsync. Use "cp -Hlr <fromdir> <targetdir>" to create the initial copy and "rsync -aHP --delete <fromdir> <targetdir>" for keep the target directory clean of cruft from time to time, else just fuggit about the latter. :-)
Now, you can create directory trees with hardlinked files easily if using GNU coreutils and rsync. Use "cp -Hlr <fromdir> <targetdir>" to create the initial copy and "rsync -aHP --delete <fromdir> <targetdir>" for keep the target directory clean of cruft from time to time, else just fuggit about the latter. :-)
Actually, I'm pretty sure that these commands only keep Hard Links if there are any.
They don't make any new Hard links...
Once again you are jumping to conclusions without even trying it youself.
Well, if you want to live like if it were 1985 and to discard information on what a poorly written man page says instead of trying it yourself, be my guest. :-)
Once again you are jumping to conclusions without even trying it youself.
Well, if you want to live like if it were 1985 and to discard information on what a poorly written man page says instead of trying it yourself, be my guest. :-)
I'm going to ignore you insulted me, and ignore the fact that 1) you didn't notice that at the end I tried it and 2) you're apparently not trying yourself.
Instead, since we're two perfectly reasonable people, I'm going to preform a test that you can try yourself.
1) df -h:
Code:
Filesystem Size Used Avail Use% Mounted on
/dev/sdd2 9.9G 8.2G 1.3G 87% /media/gamma
It seeems that Comics is just bigger then the space to fill the drive. No matter, if it's hard links it shouldn't take up space at all:
As you say, this should hard link the whole folder:
an hour later it finishes. No errors
and the drive is full:
Code:
Filesystem Size Used Avail Use% Mounted on
/dev/sdd2 9.9G 9.7G 0 100% /media/gamma
Now, I'll admit that I'm surprised that this 1.5 GB turned into 1.3 GB... however I'm not convinced that any hardlinks were made.
I would expect an apology towards anyone else who would have (no doubt) explained their situation better then I did. However, since I did a terrible job of explaining myself, I'll take the blame.
I just found this thread since I had a similar problem, and I figured I should post how I solved it.
My problem was that I wanted to keep file and folder structure intact in case i messed up when renaming all my music files and folders.
cd /mnt/
rsync -a Music/ OldMusicDir/ --link-dest=/mnt/Music/
$ find Music/|wc -l
47732
$ find OldMusicDir/|wc -l
47732
$ du -h -s OldMusicDir/
1003G OldMusicDir/
$ du -h -s Music/
1003G Music/
$ du -h -s Music/ OldMusicDir/
1003G Music/
15M OldMusicDir/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.