Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The problem is I want to be able to see errors when moving a file, but not see errors with permissions problem. In other words - I care if the file is not fully transmitted, but don't want to see errors like this:

mv: failed to preserve ownership for `/home/blah/backup/pgsql.tar.gz': Operation not permitted

So I want something like: mv $backupfile $destination --ignore-permissions.

The backup file can be anything from 1 MiB to 5 GiB and is transfered through NFS.

share|improve this question
Excuse me, do you happen to mean NTFS ? Because this is a typical NTFS thing that I always get flooded with these pointless messages. I know I cannot preserve ownership information, but it would be nice if mv didn't tell me that a gazillion times because once would be enough. :) – syntaxerror Nov 21 '14 at 8:51
It happens also on connected NTFS device, but this is not the only case. It happens in all cases were you do not have rights to change permissions or it is not possible (like on NTFS). – Nux Nov 24 '14 at 10:23
Well, I thought as much. – syntaxerror Nov 24 '14 at 11:12
If you want to preserve permissions even across NTFS, you could tar up the files. – Wildcard Apr 23 at 7:24
up vote 18 down vote accepted

mv is the wrong tool for this job; you want cp and then rm. Since you're moving the file to another filesystem this is exactly what mv is doing behind the scenes anyway, except that mv is also trying to preserve file permission bits and owner/group information. This is because mv would preserve that information if it were moving a file within the same filesystem and mv tries to behave the same way in both situations. Since you don't care about the preservation of file permission bits and owner/group information, don't use that tool. Use cp --no-preserve=mode and rm instead.

share|improve this answer
Thanks, it works. Ended up doing: cp --no-preserve=mode,ownership $backupfile $destination, check exit code and then do rm $backupfile if everything is fine. – Nux May 21 '14 at 16:54

When you move a file within the same filesystem, mv detaches the file from its old location and attaches it to its new location; metadata such as permissions remains the same. When you move a file to a different filesystem, mv copies the file, attempts to replicate as much metadata as possible, and removes the original.

Since you're moving to a different filesystem and you don't want to replicate much metadata, you might as well copy the file then remove the original.

cp "$backupfile" "$destination" && rm "$backupfile"

This preserves the file's permissions to some extent (e.g. world-readability, executability). The file's modification time isn't preserved. With GNU cp, you can use the --preserve=… option to contol what metadata is replicated more finely, e.g. --preserve=mode,timestamps.

You can also use rsync and tell it what you want to preserve. The option -a means “preserve most metadata”, which includes the owner if running as root only.

rsync -a --no-owner --no-group --remove-source-files "$backupfile" "$destination"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.