Linux – How to mass move files one directory up

linuxmvssh

I have about 200 directories in /home/. The problem is that they all exist in this way:

/home/{user}/homedir/

While it should just be:

/home/{user}/

With what command can I mass move all content of homedir one directory up for each user?

Thanks for the help.

Best Answer

This might be different depending on your shell, but assuming bash:

for a in $(find /home -maxdepth 1 -type d); do mv $a/homedir/* $a/; rmdir $a/homedir; done

Run the find command separately to verify the list is what you expect before you run the full command and remove the rmdir part if you want to keep the empty homedir in each folder.