windows子系统wsl_您(或我)不知道的Cool WSL(Linux的Windows子系统)提示和技巧

windows子系统wsl

windows子系统wsl

It's no secret I dig WSL (Windows Subsystem for Linux) and now that WSL2 is available in Windows Insiders Slow it's a great time to really explore the options that are available. What I'm finding is so interesting about WSL and how it relates to the Windows system around it is how you can cleanly move data between worlds. This isn't an experience you can easily have with full virtual machines, and it speaks to the tight integration of Linux and Windows.

我挖WSL(Linux的Windows子系统)已经不是什么秘密了,现在Windows Insiders中可以使用WSL2了。现在是真正探索可用选项的好时机。 我发现的有关WSL的内容非常有趣,它与周围的Windows系统之间的关系是如何在各个世界之间干净地移动数据。 对于完整的虚拟机来说,这不是一次轻松的体验,它说明了Linux和Windows的紧密集成。

Look at all this cool stuff you can do when you mix your peanut butter and chocolate!

看看混合花生酱和巧克力时可以做的所有这些酷事!

从Linux运行Windows资源管理器并访问发行版的文件 (Run Windows Explorer from Linux and access your distro's files)

When you're at the WSL/bash command line and you want to access your files visually, you can run "explorer.exe ." where . is the current directory, and you'll get a Windows Explorer window with your Linux files served to you over a local network plan9 server.

当您在WSL / bash命令行中并且想要直观地访问文件时,可以运行“ explorer.exe”。 在哪里。 是当前目录,您将获得一个Windows资源管理器窗口,其中包含通过本地网络plan9服务器提供Linux文件。

Accessing WSL files from Explorer

从Windows使用Real Linux命令(非Cgywin) (Use Real Linux commands (not Cgywin) from Windows)

I've blogged this before, but there are now aliases for PowerShell functions that allow you to use real Linux commands from within Windows.

我以前已经写过这篇文章,但是现在有PowerShell函数的别名,这些别名使您可以从Windows内部使用真正Linux命令

You can call any Linux command directly from DOS/Windows/whatever by just putting it after WSL.exe, like this!

只需将其放在WSL.exe之后,就可以直接从DOS / Windows /任何地方调用任何Linux命令!

C:\temp> wsl ls -la | findstr "foo"
-rwxrwxrwx 1 root root 14 Sep 27 14:26 foo.bat

C:\temp> dir | wsl grep foo
09/27/2016 02:26 PM 14 foo.bat

C:\temp> wsl ls -la > out.txt

C:\temp> wsl ls -la /proc/cpuinfo
-r--r--r-- 1 root root 0 Sep 28 11:28 /proc/cpuinfo

C:\temp> wsl ls -la "/mnt/c/Program Files"
...contents of C:\Program Files...

从Linux使用Real Windows命令(不是Wine) (Use Real Windows commands (not Wine) from Linux)

Windows executables are callable/runnable from WSL/Linux because the the Windows Path is in the $PATH until Windows. All you have to do is call it with .exe at the end, explicitly. That's how "Explorer.exe ." works above. You can also notepad.exe, or whatever.exe!

Windows可执行文件可从WSL / Linux调用/运行,因为Windows路径在Windows之前一直在$ PATH中。 您要做的就是在末尾显式地使用.exe进行调用。 这就是“ Explorer.exe”的方式。 上面的作品。 您也可以notepad.exe或任何其他文件!

运行Visual Studio代码并在Windows上本地访问(并构建!)您Linux应用 (Run Visual Studio Code and access (and build!) your Linux apps natively on Windows)

You can run "code ." when you're in a folder within WSL and you'll get prompted to install the VS Remote extensions. That effectively splits Visual Studio Code in half and runs the headless VS Code Server inside Linux with the VS Code client in the Windows world.

您可以运行“代码”。 当您位于WSL中的文件夹中时,系统会提示您安装VS Remote扩展。 这样可以有效地将Visual Studio Code分成两部分,并通过Windows世界中的VS Code客户端在Linux内部运行无头VS Code Server。

You'll also need to install Visual Studio Code and the Remote - WSL extension. Optionally, check out the beta Windows Terminal for the best possible terminal experience on Windows.

您还需要安装Visual Studio CodeRemote-WSL扩展。 (可选)查看Beta Windows Terminal ,以获得Windows上最佳的终端体验。

Here's a great series from the Windows Command LIne blog:

这是Windows Command LIne博客的精彩系列文章:

You can find the full series here:

您可以在此处找到完整的系列:

Here's the benefits of WSL 2

这是WSL 2的好处

  • Virtual machines are resource intensive and create a very disconnected experience.

    虚拟机占用大量资源,并且会产生非常脱节的体验。
  • The original WSL was very connected, but had fairly poor performance compared to a VM.

    原始的WSL连接非常紧密,但是与VM相比,性能却相当差。
  • WSL 2 brings a hybrid approach with a lightweight VM, a completely connected experience, and high performance.

    WSL 2带来了一种混合方法,该方法具有轻量级VM,完全连接的体验和高性能。

Again, now available on Windows 10 Insiders Slow.

再次,现在Windows 10 Insiders Slow上可用。

在几秒钟内并排运行多个Linux (Run multiple Linuxes in seconds, side by side)

Here I'm running "wsl --list --all" and I have three Linuxes already on my system.

在这里,我正在运行“ wsl --list --all”,并且我的系统上已经有三个Linux。

C:\Users\scott>wsl --list --all
Windows Subsystem for Linux Distributions:
Ubuntu-18.04 (Default)
Ubuntu-16.04
Pengwin

I can easily run them, and also assign a profile to each so they appear in my Windows Terminal dropdown.

我可以轻松地运行它们,还可以为每个文件分配一个配置文件,以便它们出现在Windows Terminal下拉列表中。

使用Pengwin在Windows下运行X Windows Server (Run an X Windows Server under Windows using Pengwin)

Pengwin is a custom WSL-specific Linux distro that's worth the money. You can get it at the Windows Store. Combine Pengwin with an X Server like X410 and  you've got a very cool integrated system.

Pengwin是值得定制的WSL特定于Linux的发行版。 您可以在Windows Store中获得它。 将Pengwin和X410之类X服务器结合使用,您将获得一个非常酷的集成系统。

在Windows系统之间轻松移动WSL发行版 (Easily move WSL Distros between Windows systems)

Ana Betts points out this great technique where you can easily move your perfect WSL2 distro from one machine to n machines.

Ana Betts指出了这项出色的技术,您可以轻松地将完美的WSL2发行版从一台机器转移到n台机器。

wsl --export MyDistro ./distro.tar

# put it somewhere, dropbox, onedrive, elsewhere

mkdir ~/AppData/Local/MyDistro
wsl --import MyDistro ~/AppData/Local/MyDistro ./distro.tar --version 2

That's it. Get your ideal Linux setup sync'ed on all your systems.

而已。 在所有系统上同步理想Linux安装程序。

在WSL中使用Windows Git凭据提供程序 (Use the Windows Git Credential Provider within WSL)

All of these things culminate in this lovely blog post by Ana Betts where she integrates the Windows Git Credential Provider in WSL by making /usr/bin/git-credential-manager into a shell script that calls the Windows git creds manager. Genius. This would only be possible given this clean and tight integration.

所有这些事情在Ana Betts的这篇可爱的博客文章中达到了高潮,她通过将/ usr / bin / git-credential-manager制作为调用Windows git creds管理器的shell脚本,在WSL中集成了Windows Git凭据提供程序。 天才。 鉴于这种干净紧密的集成,这才有可能。

Now, go out there, install WSL, Windows Terminal, and make yourself a shiny Linux Environment on Windows.

现在,去那里,安装WSL, Windows Terminal ,并使自己成为Windows上闪亮Linux环境

Sponsor: Like C#? We do too! That’s why we've developed a fast, smart, cross-platform .NET IDE which gives you even more coding power. Clever code analysis, rich code completion, instant search and navigation, an advanced debugger... With JetBrains Rider, everything you need is at your fingertips. Code C# at the speed of thought on Linux, Mac, or Windows. Try JetBrains Rider today!

赞助商:喜欢C#吗? 我们也这样做! 这就是为什么我们开发了一个快速,智能,跨平台的.NET IDE的原因,它为您提供了更多的编码能力。 巧妙的代码分析,丰富的代码完成,即时搜索和导航,高级调试器...使用JetBrains Rider,您所需的一切都唾手可得。 在Linux,Mac或Windows上以思考的速度编写C#代码。 立即尝试JetBrains Rider

翻译自: https://www.hanselman.com/blog/cool-wsl-windows-subsystem-for-linux-tips-and-tricks-you-or-i-didnt-know-were-possible

windows子系统wsl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值