skip to Main Content

I am upgrading my WSL2 instance from Debian 10 to Ubuntu 20.04 LTS, because I need some newer packages.

How do I copy files and directories from Debian to Ubuntu, preserving the permissions and owner? (uid and gid are the same in the two Linuxes.)

Copying to windows first changes the permissions and owner of files.

explorer.exe also changes permissions and owner.

Preferably, I’d also like to avoid having to create a shared disk image file that I could mount from Debian and Ubuntu in turn.

I’d like something simpler, like accessing the second WSL instance directly from the first, e.g.,

    $ cp -a <Debian>/myfiles/ <Ubuntu>/myfiles

Is this possible?

2

Answers


  1. Use tar. It will preserve all the file metadata.

    In <Debian>, create myfiles.tar.gz:

    tar zcvf myfiles.tar.gz myfiles
    

    Copy myfiles.tar.gz to your windows drive e.g. with explorer.exe or with /mnt/c, and then copy myfiles.tar.gz to <Ubuntu>. In <Ubuntu>, untar it:

    tar zxvf myfiles.tar.gz myfiles
    
    Login or Signup to reply.
  2. See also my similar question: How to access wsl$othercontainersomefile from within a WSL container? where the short answer is:

    sudo mkdir /mnt/othercontainer
    sudo mount -t drvfs '\wsl$othercontainer' /mnt/othercontainer
    ls -l /mnt/othercontainer/some/file
    

    NOTE: It looks like symbolic links aren’t supported.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search