I’m trying to write a shell script that automatically moves the default home folders (Desktop, Documents, etc.) to a new location. It’s on a separate partition but still in the main home folder via a symlink.
I found a file called user-dirs.dirs located at /home/[USER]/.config that seems to be the file that I need to target with my script in order to change the home folders locations. However, for some reason, even when the home folder locations are changed, dolphin still refers to the old location.
My script is below. Is there another config file I need to target? Is there something wrong with my script?
# Get currently logged on user
user=$(whoami)
# Define home folder and data folder (new partition)
datafolder="/data/$user"
homefolder="/home/$user"
# Store the sudo password for the sudo commands
read -p "Enter password: " -s sudoPW
# Make a data folder in the /data partition (requires sudo since it's owned by root)
echo $sudoPW | sudo -S mkdir $datafolder
# Take ownership of the folder (same as above, sudo needed)
echo $sudoPW | sudo -S chown $user $datafolder
# Set correct permissions on folder
chmod 700 $datafolder
# Define home folders
homefolders=('Desktop' 'Documents' 'Downloads' 'Music' 'Pictures' 'Public' 'Templates' 'Videos')
# Make the symlink
ln -s $datafolder "$homefolder/data"
# Copy the home folders, set the new location in the config file, and remove the old folders
for i in "${homefolders[@]}"; do
cp -r "$homefolder/$i" "$datafolder/$i"
sed -i "s|\$HOME/$i|\$HOME/data/$i|g" $homefolder/.config/user-dirs.dirs
rm -r "$homefolder/$i"
done
Extra info: This is on EndeavourOS (with KDE obviously) inside a Virtualbox VM.