The operation I'm trying to do is take directory 1:
Dir1
Dir A
File A
Dir B
File B
Then use the find
command to check every file in Dir 1 for whether or not they have an existing hardlink with something like:
find . -type f -links 1 -exec cp -al {} /path/to/Dir2/{} \;
Then I want to end up with:
Dir2
Dir A
File A (hardlink)
Dir B
File B (hardlink)
Right now I know how to find every non-hardlinked file in a directory, and place a hardlink to those files in a different directory, but I want to maintain the same directory structure when I make the new hardlinks. My current command would produce this:
Dir2
File A (hardlink)
File B (hardlink)
Say I'm looking at File B, and File B has only 1 link (has not been hardlinked), how would I refer to "Dir B" in order to copy that directory to the new directory? I wouldn't want "/Path/To/Dir B" just "Dir B".
Is there a way to accomplish this task in bash?