DEV Community


Easily Manage Dot Files (Config Files)

ujwal dhakal
MMA Fighter, Boxer, Part time doctor, teacher, stunner, seasonal model, heavy weight lifter, athlete well i am not any of them.
・2 min read

Whenever I migrated from an old laptop to a new laptop or re-installed the whole OS, I always ended up copying all the config files(Ide configuration, bash history, app profiles, etc) in a hard disk.

I either ended up copying all unnecessary configs(by zipping all) from the home folder or if I pick particular configs, I keep on missing things.


Even if I manage to zip all those things, storing them was another big challenge for me. Storing data comes with a cost as one would need to preserve it by storing locally or in any cloud. Updating the configs is even harder as I have to manually repeat all these steps.

So I started using Git to track my config files, so I created a Private Repo where I could push my all config files.

At first, I created a bash script with the name sync. sh inside directory dotfiles

declare -a filesToSync=(".bashrc" ".bash_history" ".zshrc" ".zsh_history" ".gitignore_global" ".gitconfig")
## now loop through the above array
for i in "${filesToSync[@]}"
   cp ~/$i ~/dotfiles/$i
   # or do whatever with individual element of the array
declare -a foldersToSync=(".config/Terminator",".config/JetBrains") 
## now loop through the above array
for i in "${foldersToSync[@]}"
  cp -r ~/$i ~/dotfiles
   ## or do whatever with individual element of the array
Enter fullscreen mode Exit fullscreen mode

So after running bash the script would copy all my local config files and folders into the directory into the folder dotfiles.

Now all I need to do is run git add . git commit -m “message” git push -u origin master these commands to push to my Git Repository.

Then I again wanted to automate the above manual process on a weekly basis, so I created a file inside the same dotfiles directory with the name

cd ~/dotfiles
git add .
git commit -m “weekly changes”
git push -u origin master -f 
Enter fullscreen mode Exit fullscreen mode

Finally, I created a weekly Cron job with crontab -e

0 0 * * 0 bash /home/ujwal/dotfiles/


Every week my config files are getting synced automatically and I don't need to remember at all.

There are other great tools for managing dotfiles that have many more features than the above script like
I simply made my own script as I could learn bash scripting side by side too.

Discussion (2)

moopet profile image
Ben Sinclair

Why do you use sudo for every copy command? The implication is that your user account doesn't have access to things in its own home directory. You're then running a chown command to make sure everything's back to normal at the end. What's the reasoning there?

I recommend using something like GNU stow to handle this stuff automatically.

ujwaldhakal profile image
ujwal dhakal Author

Yep, thanks for pointing it out. Actually, dotfiles was created by other user so i had to use sudo and unknowingly i put in all codes since these code works without sudo too as i have chown my home with the current user ujwal