Script to copy or move folders from your current directory into ~/.config, merging contents instead of deleting existing files/folders. Existing files in ~/.config will only be overwritten if they have the same name as files/folders being copied — no entire directories are removed.
-
Merging, Not Deleting
- If
~/.configalready has a folder (e.g.,themes), the script copies/moves the contents of your source folder into it without deleting the entire destination folder. - Example:
~/.config/themes/already hasold_style.css.- Your source
themes/hasnew_style.css. - After running:
~/.config/themes/will contain bothold_style.cssandnew_style.css.
- If
-
Overwriting Specific Files
- If a file exists in both the source and destination, the source file overwrites the destination file (e.g.,
themes/style.cssin the source replaces~/.config/themes/style.css).
- If a file exists in both the source and destination, the source file overwrites the destination file (e.g.,
-
Hidden Files Included
- The
/.suffix in"$folder"/.ensures hidden files (e.g.,.config.json) are copied/merged too.
- The
-
Move vs. Copy
- Copy: Keeps your original folders untouched.
- Move: Deletes the contents of your source folders after moving them (the empty source folder remains).
-
Save the script:
nano restore.sh
Paste the code above, then save (
Ctrl+O) and exit (Ctrl+X). -
Make it executable:
chmod +x restore.sh
-
Run the script:
./restore.sh
- You’ll get a confirmation prompt before proceeding.
- To switch from copy to move, edit the script and set
ACTION="move".
Before:
./
├── themes/
│ ├── old_style.css # Exists in ~/.config/themes/
│ └── new_style.css # Will overwrite ~/.config/themes/new_style.css
└── shortcuts/
└── config.json # New file After running with ACTION="copy":
~/.config/
├── themes/
│ ├── old_style.css # **Preserved** (not deleted!)
│ └── new_style.css # **Overwritten** from source
└── shortcuts/
└── config.json # **Added** - Test with
copyfirst: Always start withACTION="copy"to avoid accidental data loss. - Backup important config:
cp -r ~/.config ~/.config_backup
- Avoid running as root: Running with
sudocould overwrite system-wide config files!
This script is ideal for syncing personal configuration folders while preserving existing settings in ~/.config.