home blog portfolio Ian Fisher

What file permissions does mv need?

20 November 2024 systems 6
Subscribe

What Unix file permissions are required for mv path/to/src/file path/to/dest, assuming that dest/ is an existing directory that is not src/?

Neither I nor ChatGPT nor any of the dozen programmers I asked could give a completely correct answer off the top of their heads.

If you'd like, take a moment to think about it for yourself. Otherwise, scroll down to see the answer.

  1. +w on src/ and dest/
  2. +x on every directory named in path/to/src/ and path/to/dest/, including the implicit current directory for relative paths
  3. If file is a directory on the same filesystem as dest/, +w on file
  4. If src/ has the sticky bit set, then you must be either the owner of file or the owner of src/
  5. If src/ and dest/ are on different filesystems, then +r on file
  6. If src/ and dest/ are on different filesystems and file is a directory, then +r on every regular file and directory in file (and all subdirectories), and +wx on every non-empty directory.

(This was tested on Linux and macOS. Email me if you think I've missed something.)

Commentary:

What does it mean for me?

Further reading