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

2023-11-12

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文件。

从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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • 普罗米修斯指标 - 未找到

    我有 Spring Boot 应用程序 并且正在使用 vertx 我想监控服务和 jvm 为此我选择了 Prometheus 这是我的监控配置类 Configuration public class MonitoringConfig Bea
  • python 集合可以包含的值的数量是否有限制?

    我正在尝试使用 python 设置作为 mysql 表中 ids 的过滤器 python集存储了所有要过滤的id 现在大约有30000个 这个数字会随着时间的推移慢慢增长 我担心python集的最大容量 它可以包含的元素数量有限制吗 您最大
  • 如何在 Java 中测试一个类是否正确实现了 Serialized(不仅仅是 Serialized 的实例)

    我正在实现一个可序列化的类 因此它是一个与 RMI 一起使用的值对象 但我需要测试一下 有没有办法轻松做到这一点 澄清 我正在实现该类 因此在类定义中添加 Serialized 很简单 我需要手动序列化 反序列化它以查看它是否有效 我找到了
  • 编辑文件名在 JComboBox 中的显示方式,同时保持对文件的访问

    我对 Java 很陌生 对堆栈溢出也很陌生 我正在尝试利用 JMF API 创建一个用 Java 编码的简单媒体播放器 到目前为止 我已经能够设置一个简单的队列 播放列表来使用JComboBox called playListHolder
  • Python - 在窗口最小化或隐藏时使用 pywinauto 控制窗口

    我正在尝试做的事情 我正在尝试使用 pywinauto 在 python 中创建一个脚本 以在后台自动安装 notepad 隐藏或最小化 notepad 只是一个示例 因为我将编辑它以与其他软件一起使用 Problem 问题是我想在安装程序
  • 我可以创建自定义 java.* 包吗?

    我可以创建一个与预定义包同名的自己的包吗在Java中 比如java lang 如果是这样 结果会怎样 这难道不能让我访问该包的受保护的成员 如果不是 是什么阻止我这样做 No java lang被禁止 安全管理器不允许 自定义 类java
  • HQL Hibernate 内连接

    我怎样才能在 Hibernate 中编写这个 SQL 查询 我想使用 Hibernate 来创建查询 而不是创建数据库 SELECT FROM Employee e INNER JOIN Team t ON e Id team t Id t
  • 检查所有值是否作为字典中的键存在

    我有一个值列表和一本字典 我想确保列表中的每个值都作为字典中的键存在 目前我正在使用两组来确定字典中是否存在任何值 unmapped set foo set bar keys 有没有更Pythonic的方法来测试这个 感觉有点像黑客 您的方
  • glpk.LPX 向后兼容性?

    较新版本的glpk没有LPXapi 旧包需要它 我如何使用旧包 例如COBRA http opencobra sourceforge net openCOBRA Welcome html 与较新版本的glpk 注意COBRA适用于 MATL
  • 用于运行可执行文件的python多线程进程

    我正在尝试将一个在 Windows 上运行可执行文件并管理文本输出文件的 python 脚本升级到使用多线程进程的版本 以便我可以利用多个核心 我有四个独立版本的可执行文件 每个线程都知道要访问它们 这部分工作正常 我遇到问题的地方是当它们
  • spring中如何使用jackson代替JdkSerializationRedisSerializer

    我在我的一个 Java 应用程序中使用 Redis 并且正在序列化要存储在 Redis 中的对象列表 但是 我注意到使用 RedisTemplate 会使用 JdkSerializationRedisSerializer 相反 我想使用 J
  • Eclipse 中 Spring MVC 模型对象的 (jsp /jstl) 视图中的代码辅助

    在 Spring MVC 中 当将对象放置在视图模型中时 如下所示 public String getUser Model model fetch user model addAttribute user user return viewN
  • 从 Python 中的类元信息对 __init__ 函数进行类型提示

    我想做的是复制什么SQLAlchemy确实 以其DeclarativeMeta班级 有了这段代码 from sqlalchemy import Column Integer String from sqlalchemy ext declar
  • 在python中,如何仅搜索所选子字符串之前的一个单词

    给定文本文件中的长行列表 我只想返回紧邻其前面的子字符串 例如单词狗 描述狗的单词 例如 假设有这些行包含狗 hotdog big dog is dogged dog spy with my dog brown dogs 在这种情况下 期望
  • 具有特定参数的 Spring AOP 切入点

    我需要创建一个我觉得很难描述的方面 所以让我指出一下想法 com x y 包 或任何子包 中的任何方法 一个方法参数是接口 javax portlet PortletRequest 的实现 该方法中可能有更多参数 它们可以是任何顺序 我需要
  • 如何使用 JSch 将多行命令输出存储到变量中

    所以 我有一段很好的代码 我很难理解 它允许我向我的服务器发送命令 并获得一行响应 该代码有效 但我想从服务器返回多行 主要类是 JSch jSch new JSch MyUserInfo ui new MyUserInfo String
  • 在 Python 类中动态定义实例字段

    我是 Python 新手 主要从事 Java 编程 我目前正在思考Python中的类是如何实例化的 我明白那个 init 就像Java中的构造函数 然而 有时 python 类没有 init 方法 在这种情况下我假设有一个默认构造函数 就像
  • ServletContainer 类未找到异常

    我无法再编译我的球衣项目 并且出现以下异常 GRAVE Servlet Project API threw load exception java lang ClassNotFoundException com sun jersey spi
  • Python - 字典和列表相交

    给定以下数据结构 找出这两种数据结构共有的交集键的最有效方法是什么 dict1 2A 3A 4B list1 2A 4B Expected output 2A 4B 如果这也能产生更快的输出 我可以将列表 不是 dict1 组织到任何其他数
  • 带有 Maven Wrapper 的 Java 17 导致无法识别的 VM 选项“MaxPermSize=512m”

    I use OpenJDK 17 https jdk java net 17 使用 Maven Wrapper 3 8 2 从春季初始化 https start spring io Maven项目 JAR打包 Java 17 Spring

随机推荐

  • java上传视频文件到服务器,java视频上传到远程服务器

    java视频上传到远程服务器 内容精选 换一换 该步骤必须在root用户下执行 若以普通系统用户登录 需要执行su切换到root用户下执行后续操作 ssh keygen t rsa过程中需要 可选 输入保存的文件名 默认为在 root ss
  • C#学习笔记 委托

    定义委托 有时候可能想要将一个方法传递给另一个方法 在C 中使用函数指针来实现 在JavaScript中由于函数也是对象所以直接可以在参数列表中传递 而在C 中需要使用委托 要使用委托 首先需要定义它 定义一个接受两个int参数 返回一个i
  • 【HDU4741】空间解析几何

    1 题目链接 题目大意 给出两条空间中不平行的直线 求出这两条直线的距离和对应的点 2 分析 在空间中我们知道 直线有三种关系 相交 平行 异面 但是题目中已经说了 是不相交的直线 所以只可能有两种关系 平行或者异面 在空间中 直线方程并不
  • PATH环境变量变化,导致无法找到基本命令

    解决办法 好多命令的位置在 usr bin 恢复办法如下 1 由于找不到sudo 所以必须写全路径 其他命令如果提示找不到 也需要写全路径 usr bin sudo vi etc profile 2 末尾添加以下内容后保存 export P
  • android fwk开发之堡垒机的使用

    在Android堡垒机 Ubuntu 服务器上编译android AOSP源码 1 添加用户 1 切换到root用户 sudo su 2 添加账户 useradd m username 删除用户 userdel r username 使用u
  • 使用elementUI实现el-table表格跨行

    1 概述 element table 有一个属性 span method 可以设置单元格合并 通过给table传入span method方法可以实现合并行或列 方法的参数是一个对象 里面包含当前行row 当前列column 当前行号rowI
  • new bing聊天机器人免翻命令行使用--大佬逆向工程api

    使用 可以看到 IP地址在美国 使用步骤 下载地址 GitHub地址 或者命令行 python3 m pip install EdgeGPT upgrade 获取bing的cookie 不会控制台获取的 可以在edge插件里面下载cooki
  • 爬虫实战之《流浪地球》豆瓣影评分析(一)

    背景与挖掘目标 获取豆瓣评论数据 分析好评与差评的关键信息 分析评论数量及评分与时间的关系 分析评论者的城市分布情况 1 背景与挖掘目标 豆瓣 douban 是一个社区网站 网站由杨勃 网名 阿北 创立于2005年3月6日 该网站以书影音起
  • ChatGPT漫谈(二)

    ChatGPT 脱胎 于OpenAI在2020年发布的GPT 3 任何外行都可以使用GPT 3 在几分钟内提供示例 并获得所需的文本输出 GPT 3被认为是当时最强大的语言模型 但现在 ChatGPT模型似乎更强大 ChatGPT能进行天马
  • VUE 自定义 穿梭框

    某次项目要使用穿梭框进行数据选择 项目使用的element ui框架 框架中的穿梭框是这样子的 好像不能满足我的需求 因为需要展示很多内容 包括图片等信息 也要加上很多样式等等 我尝试这去改造 一会后觉得还是自己动手去写一个靠谱 几经鼓捣效
  • [华为云云服务器评测] 华为云耀云服务器 Java、node环境配置

    系列文章目录 第一章 linux实战 华为云耀云服务器L实例 Java node环境配置 文章目录 系列文章目录 前言 一 任务拆解 二 修改密码 三 配置安全规则 四 远程登录并更新apt 五 安装 配置JDK环境 5 1 安装openj
  • 数据结构和简单算法思想

    只为自己学习进行一下记录 虽然之前上了一些关于数据结构 算法之类的课 但之前都没有怎么搞懂 尤其是算法里面的一些算法思想 现在看能不能补上 就是一些大佬的算法指导 刷LeetCode的一些题 回看之前的书上面的重点 教材是清华大学出版社的数
  • IDEA vs VSCode在java开发上的横向对比

    讲讲出身 了解一个人需要了解他的出身 一个app也是如此 Visual Studio Code 简称 VS Code 是Microsoft在2015年4月30日Build开发者大会上正式宣布一个运行于 Mac OS X Windows和 L
  • java文件操作报错:java.io.FileNotFoundException:D:\..(拒绝访问)

    import java io Description 复制文件 从一个输入流中读取数据 然后通过输出流写入目标位置 一边读一边写 ClassName CopyFile Version V1 0 public class CopyFile p
  • softmax回归

    softmax回归 线性回归不同 softmax回归的输出单元从 个变成了多个 且引 了softmax运算使输出更适合离散值的预测和训练 softmax回归跟线性回归 样将输 特征与权重做线性叠加 它将logistic 激活函数推广到C类
  • 面向对象:类的概念和定义!

    面向对象的概念 对象 Object 含有 物体 的概念 一切皆物体 对象 对象由静态的属性和动态的行为组成 属性 行为 存储 保温 类 一组具有相同属性和行为的对象的抽象 杯子 车 不管白猫黑猫 抓到老鼠就是好猫 这句话中存在两个对象 白猫
  • Kubernetes调度器介绍

    特邀文章 原载于Gemini Open Cloud的博客 作者是Gemini Open Cloud的CEO Patrick Fu Kubernetes是一个可移植的 可扩展的 开源的集群管理器 用于管理容器化工作负载和服务 Kubernet
  • Jumperserver堡垒机管理服务器实战

    一 Jumpserver堡垒机简介 1 跳板机简介 跳板机就是一台服务器 开发或运维人员在维护过程中首先要统一登录到这台服务器 然后再登录到目标设备进行维护和操作 跳板机缺点 没有实现对运维人员操作行为的控制和审计 使用跳板机的过程中还是会
  • 智能家居之设备配网(理论篇)

    前言 记录杭州疫情 独自在杭州跨年了 不过也可以抽出点时间来写写博客分享一下 在这也要祝大家虎年大吉 本篇目标 介绍当前智能家居产品中 关于设备配网中用到的一些技术 配网的作用 现在家庭生活中 智能设备越来越多 大到手机 电脑 小到插座 灯
  • windows子系统wsl_您(或我)不知道的Cool WSL(Linux的Windows子系统)提示和技巧

    windows子系统wsl It s no secret I dig WSL Windows Subsystem for Linux and now that WSL2 is available in Windows Insiders Sl