Tuesday, December 13, 2016

Make a backup of your dotfiles

Make a backup of your dotfiles


If you are a regular Linux user, chances are you change distros to experiment with them. I am one of such persons who like to experiment with various Linux distros for both educational and experimental reasons. This activity may sometimes lead to problems regarding your Desktop Environment (DE) and others. It also might be the case that you just want to clean up your /home but keep your configurations intact using your dotfiles (The directories and files in your /home whose name start with a .). Moving these files manually is cumbersome (at least for me). The following script does it for me. And moves it to a folder called "dotfiles" in your ~/.
CAUTION: It removes any folder called dotfiles" in you ~/ and creates a new one.
You MUST run this in your ~/

rm -rf dotfiles
mkdir dotfiles
while read line; do
if [ "$line" = "" ]; then
continue
fi
if [ -d "$PWD/$line" ]; then
echo "$PWD/$line is a folder"
cp $PWD/$line $PWD/dotfiles/$line # substitute cp with mv to move the files
else
echo "$PWD/$line is a file"
cp $PWD/$line $PWD/dotfiles/$line # substitute cp with mv to move the files
fi
done < <(find . -maxdepth 1 -name ".*" -printf %P )


Go to link download