I have a kind of problem. I am trying to hard-link all my dotfiles [files that customize certain apps] in one folder for ease of use, called ~/dotfiles/ , but multiple programs that I have, have entire directories for that. Some are in .config, some just have a directory at the home folder, so I tried to check whether I could hard-link a directory.

After looking into it, I saw all the problems, warning, etc. about hard-linking directories, and why it's a giant nono. So I'm fully discouraged from hard-linking directories, however, I still need to do it somehow.

I found a way around this, which is by creating directories within ~/dotfiles/ and hardlinking the contents of the directories INTO those created ones, but that immediately hit a brick wall called boredom and repetition. A bunch of programs had multiple dirs, some with nested directories, and I didn't feel like spending a lot of time creating directories just so that I'm able to hard-link config files.

All I'm wondering is this. Is there a way to simulate a hard-link?

For example, I have a directory called ~/Testconfig/, and I want to hard-link it into ~/dotfiles/. Theoretically, a hardlink would place a directory in ~/dotfiles/ with all of it's contents, including its files and its nested directories.

Is there a way to achieve that without actually creating a hardlink?

My idea is that a bash script could be made that automates all of this, but I know next to nothing about bash, so that would be difficult.

  • 2
    What is your goal? Maybe there's a better way to reach the goal than what you're trying to do... – vidarlo Oct 22 '17 at 14:44
  • My goal is to put all dotfiles into a single directory. I'm looking into alternatives, like YADM and GNU Stow, but since they seem more complicated/specialised than I'm ready to deal with [for now], I'm trying to achieve this with hard-links. – MasterTextman Oct 22 '17 at 14:53
  • In this scenario I imagine it's for easier overview and access? If so, symlinks should work Just Fine? – vidarlo Oct 22 '17 at 14:55
  • Ah, sorry I forgot. I also want to have a github repository for all my dotfiles. I tried symlinks, but that ended up with a repo full of symlinks and not much content. – MasterTextman Oct 22 '17 at 14:56
  • That makes sense :) – vidarlo Oct 22 '17 at 15:05

You could use cp -al .??* ~/dotfiles/ and let it worry about all the complexity. Directories are created and files are linked

| improve this answer | |
  • Seems to work perfectly so far! Although I don't want to save EVERY dotfile that exists, so I changed the .??* part. – MasterTextman Oct 22 '17 at 14:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.