How to mv files while keeping attributes

June 13, 2020
Linux rsync

This afternoon I wanted to move some files between two folders, on two different filesystems.

You can read a lot of thing about mv and attributes preservation, and people seems to imply that mv can change them upon action. But (at least in my case on a desktop Fedora), it does seems to preserve attributes (owner, group, permissions, creation time and modification time) in any cases (it may not be if you use some kind of reduced flavor like busybox or an other Unix like BSD). The only altered attribute is atime (as shown by the stat command).

Hence mv path/source path/dest is a perfectly valid move, and so is cp -r -p /path/source /path/dest. But if you are looking for a slightly more flexible solution with rsync and speed/progress:

# 1. be careful to keep the trailing slash on the old folder!
# 2. --info=progress2 show the overall progress accross all
#    files currently discovered by rsync, it may NOT be accurate
#    at first, until the whole tree is listed
rsync -a --remove-source-files --info=progress2 old-folder/ new-folder

--remove-source-files will ensure each file is properly copied on the other end and delete it from the source. It does so on a file-by-file basis.