Copying files while retaining permissions

Now here is one very basic system administration issue that pops up from time to time and still seems to create a lot of confusion “in the field”. When copying files from one location to another there are some cases where permissions are automatically retained, and some where you have to take special precaution. Here are the basis conditions: First, when copying and moving on the same drive:

  • If you COPY files or folders on the same drive, they will inherit the permissions from the new location, and lose it’s own permissions
  • If you MOVE files or folders on the same drive, they will keep its own permissions unchanged

When working with another target drive, this changes to:

  • If you COPY files or folders to a new drive, they will inherit the permissions from the target location, and lose it’s own permissions
  • If you MOVE files or folders to a new drive, they will now also inherit the permissions from the target location.

So, to keep the permissions and attributes of files and folders intact while relocating content we will fall back to the good old command prompt, and use XCOPY in the following format: XCOPY “sourcepath” “targetpath” /X /E /H /K

  • /X will copy audit settings and auto trigger /O which retains ownership and ACL information.
  • /E will copy sub directory’s including empty ones.
  • /H will include hidden files
  • /K will copy file attributes

After relocation you will still have to recreate basis shares, as these information is not included with xcopy.