How do I copy directory structure as symlinks inside other directory
0
votes
1
answer
53
views
I am looking for an easy way to backup all my dotfiles in a git repository.
Solution that I'm aiming for:
- have git as my source of truth for my dotfiles contents
- in my home directory backed up files would be symlinks to files in repository (so when I edit it, it's going to be edited in repository)
- I can create symlinks for all files in repo with one command (directory structure would be preserved but only files should be linked
For example, I have this backup repository structure:
.config
|_ nvim
|_ init.lua
.tmux
|_ tmux.conf
.zshrc
And I want to get this structure out of it:
home
|_ .config
| |_ (other contents)
| |_ nvim
| |_ (other contents)
| |_ link to init.lua
|_ .tmux
| |_ (other contents)
| |_ link to tmux.conf
|_ link to .zshrc
|_ (other home files and directories)
Other contents might exist before backup process starts, should not be backed up or affected by backup process
To my surprise I wasn't able to find an already existing solution for this. I thought that rsync
does it, but googling didn't give an answer on how to do it. I tried to hack a simple bash script, but drowned in testing and amount of edge cases (i.e. for every dir ignore .
, ..
and .git
, recurse into subdirectories and etc.)
I am sure that there should be a util for this. Maybe someone can point it out for me? Or already has a script that does this?
**UPD:**
Using Stéphane's idea from comments to use cp
I wrote this script that fully covers my usecase:
find ./dotfiles -maxdepth 1 -mindepth 1 | xargs realpath | xargs -i cp {} $HOME -rs --remove-destination
Asked by Artem Sevos
(1 rep)
Apr 5, 2024, 08:36 AM
Last activity: Apr 9, 2024, 10:05 AM
Last activity: Apr 9, 2024, 10:05 AM