加载中

Welcome to the second post in this "Windows Command-Line" series. In this post we'll discuss some of the background & history behind the Windows Command-Line. Specifically, we’ll explore its humble origins in MS-DOS, to its modern-day incarnation supporting tools like PowerShell and Windows Subsystem for Linux.

Posts in this series:

  1. Command-Line Backgrounder

  2. The evolution of the Windows Command-Line (this post)

In this series' previous post, we discussed the history and fundamentals of the Command-Line and saw how the architecture of Command-Lines in general has remained largely consistent over time, even while terminals evolved from electromechanical teletypes through to modern terminal applications.

Our journey now continues along a rather tangled path, starting with early PC's, winding through Microsoft's involvement with several Operating Systems, to the newly reinvigorated Command-Line of today:

欢迎来到“Windows 命令行”系列的第二篇文章。在本文中,我们将讨论 Windows 命令行背后的一些背景和历史。具体来说,我们将探索它在 MS-DOS 中的卑微起源,到它的现代化身支持工具,如 PowerShell 和 Linux 系统中的 Windows 子系统。

本系列的帖子:

  1. 命令行的起源

  2. Windows 命令行的演变史 (这篇文章)

在本系列的前一篇文章中,我们讨论了命令行的历史和基本原理,并了解了命令行的架构如何随着时间的推移保持基本一致,即终端从机电式电传演变为现代终端应用程序。

我们的旅程现在继续沿着一条相当复杂的道路前进,从早期的 PC 开始,通过微软与几个操作系统的合作,到今天重新焕发活力的命令行:

From humble beginnings - MS-DOS

Back in the early years of the PC industry, most computers were operated entirely by typing commands into the command-line. Machines based on Unix, CP/M, DR-DOS, and others tussled for position and market share. Ultimately, MS-DOS rose to prominence as the de-facto standard OS for IBM PC's & compatibles, especially in businesses:


MS-DOS 6.0

Like most mainstream Operating Systems of the time, Microsoft's MS-DOS' "Command-Line Interpreter" or "shell" provided a simple, quirky, but relatively effective set of commands, and a command-scripting syntax for writing batch (.bat) files.

MS-DOS was very rapidly adopted by businesses large and small, that, combined, created many millions of batch scripts, some of which are still in use today! Batch scripts are used to automate the configuration of users' machines, setting/changing security settings, updating software, building code, etc.

You may never/rarely see batch or command-line scripts running since many are executed in the background while, for example, logging into a work PC. But hundreds of billions of command-line scripts and commands are executed every day on Windows alone!

While the Command-Line is a powerful tool in the hands of those with the patience and tenacity to learn how to make the most of the available commands and tools, most non-technical users struggled to use their Command-Line driven computers effectively, and most disliked having to learn and remember many seemingly arcane/abbreviated commands to make their computers do anything useful.

A more user-friendly, productivity-oriented user experience was required.

简陋的开始- MS-DOS

回顾计算机工业的早期,大部分的计算机都是通过输入命令到命令提示行中进行操作。基于 Unix、CP/M、DR-DOS 以及其他操作系统的计算机一起争夺领导地位及市场份额。最后,MS-DOS 脱颖而出成为 IBM 个人电脑以及组装机上的标准操作系统,特别是在商业领域。

MS-DOS 6.0

同当时大部分的主流操作系统一样,微软的 MS-DOS 的“命令行解释程序”或者“外壳程序”提供了一套简单、奇怪、但却相对有效的命令,以及一套用来写批处理(.bat)文件的命令脚本语法。

MS-DOS 迅速被大大小小的业务所采用,组合创建了几百万个批处理脚本,有些甚至今天仍然在使用。批处理脚本被用于自动化配置用户的机器,设置/变更安全设定,更新软件,编译代码等等。

由于命令行脚本都是在后台运行,所以你可能从来没有看到过命令行脚本运行。比如:登录到一台工作电脑,其实每天都有几百亿的命令行脚本和命令随同 Windows 一同运行。

由于命令行是一个需要耐心坚持学习如何使用这些绝大多数有效的命令和工具,大部分非技术用户苦于用命令行来有效地驱动他们的电脑,而大多数不喜欢的人却不得不学习记忆大量看起来不可思议的简短的命令来让他们的电脑做任何有用的事情。

所以迫切需要一个更加用户友好,更具生产力的用户体验。

The GUI goes mainstream

Enter, the Graphical User Interface (GUI), inspired by the work of Xerox' Alto.

Many competing GUI's emerged rapidly in the Apple Lisa and MacintoshCommodore Amiga (Workbench)Atari ST (DRI's GEM)Acorn Archimedes (Arthur/RISC OS)Sun WorkstationX11/X Windows, and many others, including Microsoft Windows:

Windows 1.0 arrived in 1985, and was basically an MS-DOS application that provided a simple tiled-window GUI environment, allowing users to run several applications side-by-side:


Windows 1.01 running on MS-DOS

Windows 2.x, 3.x, 95, and 98, all ran atop an MS-DOS foundation. While later versions of Windows began to replace features previously provided by MS-DOS with Windows-specific alternatives (e.g. file-system operations), they all relied upon their MS-DOS foundations.

Note: Windows ME (Millennium Edition) was an interesting chimera! It finally replaced the MS-DOS underpinnings and real-mode support of previous versions of Windows with several new features (esp. Gaming & Media tech). Some features were incorporated from Windows 2000 (e.g. new TCP/IP stack), but tuned to run on home PC's that might struggle to run full NT. This story might end up being an interesting post in and of itself someday!  (Thanks Bees for your thoughts on this :))

However, Microsoft knew that they could only stretch the architecture and capabilities of MS-DOS and Windows so far: Microsoft knew it needed a new Operating System upon which to build their future.

图形化界面变成主流

施乐的 Alto 启发,图形化用户界面 (GUI) 变成了主流。

很多有竞争力的 GUI 快速出现,包括苹果的 Lisa 和 MacintoshCommodore Amiga (Workbench)Atari ST (DRI's GEM)Acorn Archimedes (Arthur/RISC OS)Sun工作站X11/X Windows,以及其他很多,包括 Microsoft Windows

Windows 1.0 在1985年问世, 它基本上就是一个 MS-DOS 应用程序,提供了一个简单的窗口 GUI 环境,允许用户同时运行多个应用程序:

Windows 1.01 运行在 MS-DOS上

Windows 2.x,3.x、95 和 98 都是在 MS-DOS 基础上运行的。虽然后来的 Windows 版本开始取代以前由 MS-DOS 提供的功能,但它们都是基于 Windows 的替代方案(例如文件系统操作),它们都依赖于它们的 MS-DOS 基础。

注意:Windows ME(千禧年版)是一个有趣的嵌合体!它最终取代了 MS-DOS 的基础和以前版本的 Windows 的实模式支持,还有一些新特性(特别是游戏和媒体技术)。一些功能是在 Windows 2000(比如新的 ip 协议栈)中加入的,在家用电脑上运行的时候,可能会很难运行。这个故事最终可能会成为一个有趣的帖子。(感谢蜜蜂对这一点的看法:))

然而,微软知道,到目前为止,他们只能扩展 MS-DOS 和 Windows 的架构和功能:微软知道它需要一个新的操作系统来构建他们的未来。

Microsoft - Unix Market Leader! Yes, seriously!

While developing MS-DOS, Microsoft was also busy delivering Xenix - Microsoft's port of Unix version 7 - to a variety of processor and machine architectures including the Z8000, 8086/80286, and 68000.

By 1984, Microsoft's Xenix had become the world's most popular Unix variant!

However, the US Government's breakup of Bell Labs - home of Unix - resulted in the spin-off of AT&T which started selling Unix System V to computer manufacturers and end-users.

Microsoft felt that without their own OS, their ability to achieve their future goals would be compromised. This led to the decision to transition away from Xenix: In 1987, Microsoft transferred ownership of Xenix to its partner The Santa Cruz Operation (SCO) with whom Microsoft had worked on several projects to port and enhance Xenix on various platforms.

Microsoft - Unix 市场的引领者!是的,我是认真的!

在开发 MS-DOS 的过程中,微软也在忙着交付 Xenix —— 微软的 Unix 版本 7 - 到各种处理器和机器架构,包括 Z8000、8086/80286 和 68000。

到1984年,微软的 Xenix 已经成为世界上最流行的 Unix 变体!

然而,美国政府拆分了贝尔实验室 —— Unix 的故乡 —— 导致了 AT&T 的分拆,该公司开始向电脑制造商和终端用户销售 Unix 系统 V 。

微软认为,如果没有他们自己的操作系统,他们实现未来目标的能力将受到损害。这导致了从 Xenix 转型的决定:1987年,微软将 Xenix 的所有权转让给了其合作伙伴 —— 圣克鲁斯运营公司(SCO),微软曾在 Xenix 上开发过多个项目,以在不同的平台上移植和增强 Xenix 。

Microsoft + IBM == OS/2 … briefly

In 1985, Microsoft began working with IBM on a new Operating System called OS/2. OS/2 was originally designed to be "a more capable DOS" and was designed to take advantage of some of the modern 32-bit processors and other technology rapidly emerging from OEM's including IBM.

However, the story of OS/2 was tumultuous at best. In 1990 Microsoft and IBM ended their collaboration. This was due to a number of factors, including significant cultural differences between the IBM and Microsoft developers, scheduling challenges, and the explosive success and growth in adoption of Windows 3.1. IBM continued development & support of OS/2 until the end of 2006.

By 1988 Microsoft was convinced that its future success required a bigger, bolder and more ambitious approach. Such an approach would require a new, modern Operating System which would support the company's ambitious goals.

微软+IBM==OS/2

1985年,微软开始与 IBM 合作开发一种名为 OS/2 的新操作系统。OS/2 最初被设计为“一个更有能力的 DOS ”,它的设计目的是利用一些现代 32 位处理器和其他来自 OEM 厂商的技术,包括 IBM 。

然而,OS/2 的故事一直是很混乱的。1990年,微软和 IBM 结束了他们的合作。这是由于许多因素造成的,包括 IBM 和微软开发人员之间的显著文化差异、日程安排的挑战,以及 Windows 3.1 采用的爆炸性成功和增长。IBM 继续开发和支持 OS/2 ,直到 2006 年底。

到1988年,微软确信它未来的成功需要一个更大、更大胆、更有野心的方法。这种方法需要一个新的、现代的操作系统来支持公司的雄心勃勃的目标。

Microsoft's Big Bet - Windows NT

In 1988, Microsoft hired Dave Cutler, creator of DEC's popular and much respected VAX/VMS Operating System. Cutler's goal - to create a new, modern, platform-independent Operating System that Microsoft would own, control, and would base much of its future upon.

That new Operating System became Windows NT - the foundation that evolved into Windows 2000, Windows XP, Windows Vista, Windows 7, Windows 8, and Windows 10, as well as all versions of Windows Server, Windows Phone 7+, Xbox, and HoloLens!

Windows NT was designed from the start to be platform independent, having initially been built to support Intel's i860, then the MIPS R3000, Intel 80386+, DEC Alpha, and PowerPC. Since then, the Windows NT OS family has been ported to support the IA64 "Itanium", x64, and ARM / ARM64 processor architectures, among others.

Windows NT provided a Command-Line interface via its "Windows Console" terminal app, and the "Command Prompt" shell (cmd.exe). Cmd was designed to be as compatible as possible with MS-DOS batch scripts, to help ease business' adoption of the new platform.

微软的大赌注——Windows NT

1988年,微软聘请了戴夫卡特勒,他是 DEC 广受欢迎的 vax/vms 操作系统的创建者。卡特勒的目标 —— 创建一个新的、现代的、独立于平台的操作系统,微软将拥有、控制它,并将其未来的大部分时间建立在它的基础上。

这个新的操作系统变成了 Windows NT ——它发展成为 Windows 2000、Windows XP、Windows Vista、Windows 7、Windows 8 和 Windows 10 ,以及所有版本的 Windows Server、Windows Phone 7+、Xbox 和 HoloLens !

Windows NT 从一开始就被设计为独立于平台,最初是为了支持英特尔的 i860 ,然后是 MIPS R3000,英特尔 80386+,DEC Alpha 和 PowerPC 。从那时起,Windows NT 操作系统已经被移植到支持 IA64“Itanium”、x64 和 ARM/ARM64 处理器架构等硬件。

Windows NT 通过其“Windows 控制台”终端应用程序提供了一个命令行界面,以及“命令提示”shell(cmd.exe)。Cmd 被设计成尽可能兼容 MS-DOS 的批处理脚本,以帮助简化业务对新平台的采用。

The Power of PowerShell

While Cmd remains in Windows to this day (and will likely do so for many decades to come), because its primary purpose is to remain as backward-compatible as possible, Cmd is rarely improved. Even "fixing bugs" is sometimes difficult if those "bugs" existed in MS-DOS or earlier versions of Windows!

In the early 2000's, the Cmd shell was already running out of steam, and Microsoft and its customers were in urgent need of a more powerful and flexible Command-Line experience. This need fueled the creation of PowerShell (which originated from Jeffrey Snover's "The Monad Manifesto").

PowerShell is an object-oriented Shell, unlike the file/stream-based shells typically found in the *NIX world: Rather than handling streams of text, PowerShell processes streams of objects, giving PowerShell script writers the ability to directly access and manipulate objects and their properties, rather than having to write and maintain a lot of script to parse and manipulate text (e.g. via sed/grep/awk/lex/etc.)

Built atop the .NET Framework and Common Language Runtime (CLR), PowerShell's language & syntax were designed to combine the richness of the .NET ecosystem, with many of the most common and useful features from a variety of other shells scripting languages, with a focus on ensuring scripts are highly consistent, and extremely ... well ... powerful 

To learn more about PowerShell, I recommend reading "PowerShell In Action" (Manning Press), written by Bruce Payette - the designer of the PowerShell syntax and language. The first few chapters in particular provide an illuminating discussion of the language design rationale.

PowerShell has been adopted by many Microsoft platform technologies, and partners, including Windows, Exchange Server, SQL Server, Azure and many others, and provides commands to administer, and control practically every aspect of a Windows machine and/or environment in a highly consistent manner.

PowerShell Core is the open-source future of PowerShell, and is available for Windows and various flavors of Linux, BSD, and macOS!

PowerShell 的力量

虽然 Cmd 仍然存在于 Windows 中(并且在未来的几十年里可能都会这样做),因为它的主要目的是尽可能保持向后兼容,Cmd 很少得到改进。甚至“修复 bug ”有时也会很困难,如果这些“bug”存在于 MS-DOS 或早期版本的 Windows 中!

在2000年早期,Cmd shell 已经失去了动力,微软和其客户迫切需要一个更强大、更灵活的命令行体验。这一需求推动了 PowerShell 的创建(这源于Jeffrey Snover的“Monad宣言”)。

PowerShell 是一种面向对象的 Shel l,与在 *NIX 世界中的基于文件/流的 Shell 不同的是:PowerShell 脚本作者能够直接访问和操作对象和它们的属性,而不是处理文本流,也不必编写和维护大量的脚本解析和操作文本(例如通过 sed / grep / awk / lex / 等等)。

建立在 . net 框架和公共语言运行时(CLR)上,PowerShell 的语言和语法是为了结合 .net 的丰富的生态系统与许多最常见的、其他有用的特性的不同的 shell ,重点确保了脚本是高度一致的,也是非常强大的。

为了解更多关于 PowerShell 的知识,我推荐阅读“PowerShell In Action”(曼宁出版社),作者是 Bruce Payette ,他是 PowerShell 语法和语言的设计者。前几章特别对语言设计的基本原理进行了有启发性的讨论。

PowerShell 已经被许多微软平台技术和合作伙伴采用,包括 Windows、Exchange Server、SQL Server、Azure 和许多其他技术,并提供了管理的命令,并以高度一致的方式控制 Windows 机器和/或环境的各个方面。

PowerShell Core,是 PowerShell 的开源未来版本,它适用于 Windows 和各种版本的 Linux、BSD 和macOS !

POSIX on NT, Interix, and Services For UNIX

When designing NT, Cutler & team specifically designed the NT kernel and OS to support multiple subsystems - interfaces between user-mode code, and the underlying kernel.

When Windows NT 3.1 first shipped in 1993, it supported several subsystems: MS-DOS, Windows, OS/2 v1.3, and POSIX v1.2. These subsystems allowed NT to run applications targeting several Operating System platforms upon the same machine and base OS, without virtualization or emulation - a formidable capability even today!

While Windows NT's original POSIX implementation was acceptable, it required significant improvements to make it truly capable, so Microsoft acquired Softway Systems and its "Interix" POSIX-compliant NT subsystem. Interix was originally shipped as a separate add-on, and then later combined with several useful utilities and tools, and released as "Services For Unix" (SFU) in Windows Server 2003 R2, and Windows Vista. However, SFU was discontinued after Windows 8, due largely to a lack of customer interest.

And then a funny thing happened...

在 NT、Interix 和 UNIX 服务上的 POSIX

在设计 NT 时,卡特勒和团队专门设计了 NT 内核和操作系统来支持多个子系统——用户模式代码和底层内核之间的接口。

当 Windows NT 3.1 在1993年首次发布时,它支持几个子系统:MS-DOS、Windows、os/2 v1.3 和POSIX v1.2。这些子系统允许 NT 在相同的机器和基本操作系统上运行应用程序,而不需要虚拟化或仿真——即使在今天,这也是一种强大的功能!

虽然 Windows NT 的原始 POSIX 实现是可以接受的,但是它需要显著的改进才能使它真正有能力,所以微软收购了 Softway Systems 和它的 “Interix” 的 NT 子系统。Interix 最初是作为一个单独的附加组件发布的,然后再结合几个有用的实用工具和工具,并在 Windows Server 2003 R2 和 Windows Vista 中以“Unix服务”(SFU)发布。然而,SFU 在 Windows 8 之后就停止了,主要原因是客户缺乏兴趣。

然后一件有趣的事情发生了。

Windows 10 - a new era for the Windows command-line!

Early in Windows 10's development, Microsoft opened up a UserVoice page, asking the community what features they wanted in various areas of the OS. The developer community was particularly vociferous in its requests that Microsoft:

  1. Make major improvements to the Windows Console

  2. Give users the ability to run Linux tools on Windows

Based on that feedback, Microsoft formed two new teams:

  1. The Windows Console & command-line team, charged with taking ownership of, and overhauling the Windows Console & command-line infrastructure

  2. A team responsible for enabling genuine, unmodified Linux binaries to run on Windows 10 - the Windows Subsystem for Linux (WSL)

The rest, as they say, is history!

Windows 10 - 新时代的 Windows 命令行!

在 Windows 10 开发初期,微软开放了一个用户反馈的页面,向社区征询在操作系统的各个方面需要什么样的功能。开发者社区强烈要求微软:

  1. 重点改进 Windows 控制台

  2. 让用户可以在 Windows 下运行 Linux 的工具

基于这些反馈,微软组建了两个新团队:

  1. Windows 控制台&命令行团队,接管并彻底改进 Windows 控制台&命令行底层。

  2. 另一个团队负责在 Windows 10 下运行真正的、未经修改的 Linux 二进制文件 —— Windows A的 Linux 子系统(WSL)

其他的,他们都说,那是历史!

Windows Subsystem for Linux (WSL)

Adoption of GNU/Linux based "distributions" (combinations of the Linux kernel and collections of user-mode tools) had been growing steadily, especially on servers and in the cloud. While Windows had a POSIX compatible runtime, SFU lacked the ability to run many Linux tools and binaries because of the latter's additional System Calls and behavioral differences vs. traditional Unix/POSIX.

Due to the feedback noted received from technical Windows customers and users, along with an increasing demand inside Microsoft itself, Microsoft surveyed several options, and ultimately decided to enable Windows to run unmodified, genuine, Linux binaries!

In Mid 2014, Microsoft formed a team to work on what would become the Windows Subsystem for Linux (WSL). WSL was first announced at Build 2016, and was previewed in Windows 10 Insider builds shortly afterwards.

In most Insider builds since then, and in each major OS release since Anniversary Update in fall 2016, WSL's feature-breadth, compatibility, and stability has improved significantly: When WSL was first released, it was an interesting experiment, ran several common Linux tools, but failed to run many common developer tools/platforms. The team iterated rapidly, and with considerable help from the community (thanks all!), WSL quickly gained many new capabilities, enabling it to run increasingly sophisticated Linux binaries and workloads.

Today (mid 2018), WSL happily runs the majority of Linux binaries, tools, compilers, linkers, debuggers, etc. Many developers, IT Pro's, devops engineers, and many others who need to run or build Linux tools, apps, services, etc. enjoy dramatically improved productivity, being able to run their favorite Linux tools alongside all their favorite Windows tools, on the same machine, without needing to dual-boot.

The WSL team continues to work on improving WSL's ability to execute many Linux scenarios, and improve its performance, and integration with the Windows experience.

Linux 的 Windows 子系统(WSL)

基于 GNU/Linux 的“发行版”(Linux 内核的组合和用户模式工具的集合)的使用率一直在稳步增长,特别是在服务器和云计算上。虽然 Windows 有一个 POSIX 兼容的运行时,但是 SFU 缺乏运行许多 Linux 工具和二进制文件的能力,因为后者的系统调用和行为差异与传统的 Unix/POSIX 不兼容。

由于从 Windows 客户和用户那里得到的反馈,以及微软内部不断增长的需求,微软做了多次调查,并最终决定让 Windows 运行未经修改的、真正的 Linux 二进制文件!

在2014年中期,微软成立了一个团队,负责开发 Linux 的 Windows 子系统(WSL)。WSL 最初是在2016年的 Build 发布会上宣布的,之后不久就在 Windows 10 的内部版本中进行了预览。

自那以后,在大多数内部版本中,在2016年秋季发布周年纪念更新以来,WSL 的功能广度、兼容性和稳定性都有了显著的提高:当 WSL 首次发布时,这是一个有趣的实验,运行了几个常见的 Linux 工具,但未能运行许多通用的开发者工具/平台。团队快速地迭代,并且在社区的大量帮助下(感谢所有社区!),WSL 很快获得了许多新功能,使它能够运行越来越复杂的 Linux 二进制文件和工作负载。

今天(2018年中期),WSL 能够愉快地运行大多数 Linux 二进制程序、工具、编译器、链接器、调试器等等。许多开发人员,IT专业人士,devops工程师,和许多需要运行或构建 Linux 工具、应用程序、服务的人享受显著提高的生产力,能够在同一台机器上运行自己钟爱的 Linux 工具与所有 Windows 工具,而不需要双系统。

WSL 团队继续致力于改进 WSL 执行许多 Linux 场景的能力,并改进其性能,以及与 Windows 集成的体验。

返回顶部
顶部