mac命令行复制文件权限问题

mac osx系统 我在一个目录下执行了下面的操作

cp -R backend/ api

ls -al
drwxr-xr-x@  9 root    admin    306  7 15 09:46 api
drwxr-xr-x@ 10 xinyue  admin    340  7 15 10:40 backend

复制之后发现 他是属于root的,如何让复制后也和上面的backend一样属于xinyue

阅读 10k
4 个回答

不需要切换用户,sudo就可以。

sudo chown xinyue:admin api

切换成那个用户,或者拷贝之后 chown 更换拥有人

sudo chown xinyue:admin api

cp -Rp backend/ api

# man cp
-p    Cause cp to preserve the following attributes of each source file in the       copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by
       permissions.  Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved.
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题