So that title isn’t exact…as most of you should know, you cant create hard links for directories…you also can’t create hard links across filesystems….there are pretty obvious and more technical reasons for that.

So the alternative is to create the dirs and hard link the files in the dirs…which if done manually using ln continuously, would be painful. However, the cp command can do it for you in one fell swoop!

cp -R -l ../../awsesomedirsource .

^That will create “awseomedirsource” in the cwd and then recursively place hard links to the files in the original directory in this new directory (and make any other subdirs etc..)

Pretty nifty!

Mario Loria is a builder of diverse infrastructure with modern workloads on both bare-metal and cloud platforms. He's traversed roles in system administration, network engineering, and DevOps. You can learn more about him here.