Skip to content

Instantly share code, notes, and snippets.

@Josh5
Created September 11, 2018 19:24
Show Gist options
  • Save Josh5/3dadff856b7277c19780fa336773f390 to your computer and use it in GitHub Desktop.
Save Josh5/3dadff856b7277c19780fa336773f390 to your computer and use it in GitHub Desktop.
Changing user ubuntu
# The idea of this series of commands is to rename your home folder files asynchronously.
# If you do your whole /home/ folder in one go, it will take forever. Better to open up several terminals and run this command splitting up the task
HOME_DIR=/mnt/encrypted/home/josh5
OLD_USER=
# Make a temp directory.
# This is where we run from to prevent our for loop from checking every folder if we add '*'
mkdir -p /tmp/blah
cd /tmp/blah
# Allow whitespace
OLDIFS=$IFS
IFS=$'\n'
# Create an array of folders to check "./a*", "./.a*"
# Make sure you leave out anything you don't want to scan. Eg, Dropbox, MEGA, etc.
declare -a FOLDERS=(
"./.v*"
"./.w*"
"./.x*"
"./.z*"
)
# Loop through the folders
for folder in "${FOLDERS[@]}"; do
cd ${HOME_DIR};
echo "Scanning for ${folder}";
for f in $(grep -rl '/home/<OLDUSER>/' ${folder}); do
echo "Refactoring $f";
sed -i 's|/home/<OLDUSER>/|/home/josh5/|g' "$f";
done
cd /tmp/blah
done
IFS=$OLDIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment