在 Unix/Linux 中将文件移动到不同目录所需的权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20948946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:46:44  来源:igfitidea点击:

Permissions required to move file to different directory in Unix/Linux

linuxunixfile-permissionsmv

提问by Andy

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.

我想澄清所需的权限,以便将文件 A 从目录 B 移动到目录 C(我认为命令是“mv B/AC/A”),名称不变。

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)
  1. 执行移动的用户/组必须对目录 B 具有写入权限(或 B 必须设置权限标志以允许所有用户/组写入)
  2. 执行移动的用户/组必须对目录 C 具有写权限(或 C 必须设置权限标志以允许所有用户/组对其进行写入)
  3. 执行移动的用户/组必须对文件 A 具有写入权限(或 A 必须设置权限标志以允许所有用户/组写入它)

Thank you.

谢谢你。

采纳答案by Alfe

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 executeandof course writepermissions 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 notneed anypermissions on the file itself. It can be cleared of all permissions and still you can move (rename) it (as long as you have writeand executepermissions for the directories).

在这两种情况下,你需要执行当然的写权限到目标目录和源目录。然而,对于一个单纯的重命名(从一个目录移动到另一个可能只是)你做一个单一的文件系统上并不需要任何文件本身的权限。可以清除它的所有权限,但您仍然可以移动(重命名)它(只要您对目录具有写入执行权限)。

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

对于真正的副本(因为将文件移动到不同的文件系统时需要它),您需要对文件本身具有读取权限。 不需要对原始文件的权限,因为删除文件不是写入它(而是写入它所在的目录)。