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
Use tar. It will preserve all the file metadata.
In <Debian>, create
myfiles.tar.gz
:Copy
myfiles.tar.gz
to your windows drive e.g. withexplorer.exe
or with/mnt/c
, and then copymyfiles.tar.gz
to <Ubuntu>. In <Ubuntu>, untar it:See also my similar question: How to access wsl$othercontainersomefile from within a WSL container? where the short answer is:
NOTE: It looks like symbolic links aren’t supported.