Dec 09

Does mv keep extended file attributes (xattribs)?

Category: Linux,Tools   — Published by goeszen on December 9, 2021 at 3:28 pm

Recently I had to move a large directory containing many files having xattribs (extended attributes or file attributes). These xattribs are also sometimes called "file metadata". And the mv I wanted to execute wasn't only renaming the directory locally BUT I wanted to move a directory across file system boundaries!
What I asked myself is: would mv would behave like cp does by default and NOT keep file attributes..?
Or would mv keep xattribs and do what I want??

The answer is: mv does retain xattribs.

It does so when moving/(renaming) locally and it does so when you move across file system boundaries!

That said, I executed the mv on Ubuntu/Linux with mv from GNU coreutils 8.30. Also, the mv was between two drives formatted with ext4. And naturally, xattribs need to be enabled on both drives. Read this on how to enable xattribs for a drive.
In contrary, a copy with cp would discard xattribs. cp by default does so, only if you use the -a (archive) flag it will retain xattr.

If you'd like to dig deeper, here's a detailed account of all the various options, also here.

Leave a Reply