将主文件夹移动到 SSD:如何确保所有文件、文件夹和设置都被复制?

将主文件夹移动到 SSD:如何确保所有文件、文件夹和设置都被复制?

我要将 El Capitan 上的主文件夹移至单独的 SSD。我熟悉此过程,并且之前也这样做过。

我希望内容主文件夹 - 即其所有子文件夹,例如Desktop- 紧靠在SSD;因此SSD/desktop

如果我单击主文件夹,将其复制并粘贴到中SSD,则结果将是主文件夹本身将包含在路径中;因此SSD/username/desktop

我的问题是我应该怎么做才能复制仅有的主文件夹的内容,不包括其“顶部”文件夹。

如果我打开主文件夹,选择所有文件夹然后粘贴,我相信我不会包含所有隐藏文件和文件夹,但我认为我需要这些。

我知道我可以使用终端显示隐藏的文件和文件夹。但如果我这样做了,选择全部,复制并粘贴,我不确定是否包括所有文件夹设置等。

答案1

点击系统偏好设置,然后点击用户和组。按住 Control 键并点击要修改其主文件夹的用户,然后选择高级选项。在页面的中间位置,您将看到指定主目录的选项。

之后,使用终端将文件复制到新目录。我会使用 cp 进行复制,这样您就可以在删除旧位置之前验证所有内容是否正确移动(例如:cp -R \old\homeDirectory \new\homeDirectory)(我不记得在 Mac 上是否需要 -R 触发器...)。

最后,右键单击两个主位置的父目录,并显示文件夹信息以验证完全相同的大小。

答案2

我刚刚将我的主文件夹复制到一个单独的分区,它似乎运行良好。

所有操作都是使用临时管理员帐户完成的,以确保我在复制主文件夹时不会写入内容,并确保在系统设置中将其设置为新的主文件夹后,如果出现问题,我不会被锁定。

我使用了cp -a /Users/myname /Volumes/MyVolume/Users/myname。在这种特定情况下,您可能希望使用

cp -a /Users/myname/ /Volumes/MyVolume

与该选项结合使用时,源路径后面的尾随/会导致复制其内容而不是目录本身-a

-a选项对应的-pPR选项为:

 -a    Same as -pPR options. Preserves structure and attributes of files but not
       directory structure.

 -P    If the -R option is specified, no symbolic links are followed.  This is the
       default.

 -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.

       If the user ID and group ID cannot be preserved, no error message is displayed
       and the exit value is not altered.

       If the source file has its set-user-ID bit on and the user ID cannot be pre-
       served, the set-user-ID bit is not preserved in the copy's permissions.  If the
       source file has its set-group-ID bit on and the group ID cannot be preserved,
       the set-group-ID bit is not preserved in the copy's permissions.  If the source
       file has both its set-user-ID and set-group-ID bits on, and either the user ID
       or group ID cannot be preserved, neither the set-user-ID nor set-group-ID bits
       are preserved in the copy's permissions.

 -R    If source_file designates a directory, cp copies the directory and the entire
       subtree connected at that point.  If the source_file ends in a /, the contents
       of the directory are copied rather than the directory itself.  This option also
       causes symbolic links to be copied, rather than indirected through, and for cp
       to create special files rather than copying them as normal files.  Created
       directories have the same mode as the corresponding source directory, unmodi-
       fied by the process' umask.

       In -R mode, cp will continue copying even if errors are detected.

       Note that cp copies hard-linked files as separate files.  If you need to pre-
       serve hard links, consider using tar(1), cpio(1), or pax(1) instead.

实际上,我无意中在源文件夹后面留下了一个尾随,/这就是我知道它肯定会包含所有隐藏文件以及排除最顶层目录的原因。

相关内容