Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permissions required to move file to different directory in Unix/Linux [closed]

I would like clarification on the permissions required, in order to move a file A from directory B to directory C (the command would be "mv B/A C/A", I think), with name unchanged.

Am I correct to think that the following are required?

  1. The user/group doing the move must have write permission for directory B (or B must have permission flag set to allow all users/groups to write it)
  2. The user/group doing the move must have write permission for directory C (or C must have permission flag set to allow all users/groups to write it)
  3. The user/group doing the move must have write permission for file A (or A must have permission flag set to allow all users/groups to write it)

Thank you.

like image 794
Andy Avatar asked Jan 06 '14 11:01

Andy


1 Answers

Actually, moving a file is either a rename of a file on a single file system or creating a copy and deleting the original (typically only done if the move is a migration from one file system to another).

In either case you need execute and of course write permissions to the target directory and the source directory. However, for a mere rename (and moving from one directory to another can be just that) on a single file system you do not need any permissions on the file itself. It can be cleared of all permissions and still you can move (rename) it (as long as you have write and execute permissions for the directories).

For a real copy (as it is needed when you move the file to a different file system), you need read permissions on the file itself. No write permissions on the original are necessary, as deletion of a file is not writing to it (but to the directory it is in).

like image 66
Alfe Avatar answered Oct 21 '22 09:10

Alfe