Proper way to move user directory to a new home partition

homeusers

If I have an existing user user with an existing home directory /home/user, what is the proper way to move his home directory a new home partition?

Simply copying the directory with cp does not preserve owner and timestamps (unless I use the appropriate cp options). Would cp be enough? And what options should be used to make sure everything is copied correctly?

Best Answer

I use cp -vfa, but the rsync -vaH (mentioned by @Kusalananda in a comment) would also work. In the case of latter, don't forget that all directories should end with / (i.e. /home/gradient will be not okay, /home/gradient/ yes).

Once in a life we all should really read the ls, cp, rm, bash and rsync manual pages, they can really a lot.


If the target directory is on the same partition, a simple mv -vf would be also ok.

Don't forget to update the home directory entry belonging to the user in /etc/passwd.

Related Question