我通过 WSL 安装了 Ubuntu,WSL 是 Windows 虚拟化工具。我想将一些文件从Windows控制的内存分区移动(复制)到Ubuntu控制的分区。我尝试使用
通过 Bash 来完成此操作sudo cp <lc_disk>:\\<dir_with_files>\\<file.txt> \\wsl.localhost\\Ubuntu\\home\\<username_for_Ubuntu>\\<target_dir>
命令。但运行后出现错误:
cp: cannot stat <lc_disk>:\\<dir_with_files>\\<file.txt>: No such file or directory.
我尝试用
\\
替换 /
但没有帮助:存在相同的错误。
我尝试使用
copy
命令通过 cmd 复制文件:
copy "<lc_disk>:\<dir_with_files>\<file.txt>" "\\wsl.localhost\Ubuntu\home\burks_tedold_ubuntu\Test"
但是有错误:
Copy-Item: Access to the path '\\wsl.localhost\Ubuntu\home\<username_for_Ubuntu>\<target_dir>\<file.txt>' is denied.
那么,如何复制我的文件?
WSL版本:2.1.5.0
内核版本:5.15.146.1-2
WSLg 版本:1.0.60
MSRDC 版本:1.2.5105
Direct3D版本:1.611.1-81528511
DXCore版本:10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows版本:10.0.22631.3374
发行商 ID:Ubuntu
描述:Ubuntu 22.04.3 LTS
发布时间:22.04
代号:jammy
如果您在 WSL 中从 bash 运行复制命令 (
cp
),则可以通过以下方式访问 C 驱动器 /mnt/c
例如,
C:\Users
文件夹可以通过以下方式访问:
/mnt/c/Users/
另一个例子:如果您需要移动此 Windows 文件夹(及其所有子文件夹)
C:emp oo
进入 WSL 用户的主页,您可以启动此命令:
mv -R /mnt/c/temp/foo ~/
(您可能需要也可能不需要添加
sudo
,具体取决于源文件夹权限 - 大多数情况下,所有本地用户都可以读取和写入目录 c:\temp
)