python简史

by Gitter

通过吉特

命令行简史 (A Brief History of the Command Line)

This post by Andy Trevorah, Engineer at Gitter, has been adapted from a talk that he originally gave at codebar, a non-profit initiative that facilitates the growth of a diverse tech community by running regular programming workshops.

Gitter工程师Andy Trevorah的帖子改编自他最初在 Codebar上 发表的演讲,该演讲是 一项非盈利性计划,通过举办定期的编程研讨会来促进多元化技术社区的发展。

This post is in two parts: a little history, followed by some live command line examples.

这篇文章分为两部分:一段历史,然后是一些实时命令行示例。

一个简短的历史 (A Brief History)

Way back in the 1960s — 70s, computers were becoming more than just calculators. They could save files to disk and have multiple running applications with multiple users. But these things were difficult to control and easy to break. Thankfully, there was a very smart idea to cover all these internal bits in a nice, usable shell.

追溯到1960年代-70年代,计算机已不仅仅是计算器。 他们可以将文件保存到磁盘,并具有多个用户的多个正在运行的应用程序。 但是这些事情很难控制并且容易打破。 值得庆幸的是,有一个非常聪明的主意,可以用一个不错的,可用的外壳覆盖所有这些内部位。

These shells have since evolved to be Windows desktop, Mac OS, and all the touchy screeny bits of your phone. Basically all the user interaction stuff. They make your computer easy to use and (reasonably) hard to break.

从那时起,这些外壳就发展成为Windows台式机,Mac OS和手机的所有触摸屏。 基本上所有用户交互的东西。 它们使您的计算机易于使用,并且(合理地)难以损坏。

But before these shells started looking pretty and graphical, they were just a command line. You would type something in, and you would get a response. They looked like this:

但是在这些shell看起来漂亮而图形化之前,它们只是命令行。 您将输入一些内容,您将得到响应。 他们看起来像这样:

Here’s a shell running the cal command and printing out a calendar.

这是一个运行cal命令并打印日历的shell。

This particular shell is called bash which is short for “Bourne Again SHell” because before that there was the “Bourne Shell” by Stephen Bourne. Never let a software engineer name something that will end up lasting.

这种特殊的外壳称为bash ,是“ Bourne Again SHell”的缩写,因为在此之前,Stephen Bourne曾使用过“ Bourne Shell” 。 永远不要让软件工程师命名那些会持久的东西。

There’s a rich history of shells, and these “Unix style” shells began with Unix System 1’s shell in 1969. But even that was influenced by older programs such as RUNCOM. If you’ve ever noticed that some config files end in “rc” (e.g .vimrc), thats why.

外壳的历史很悠久,这些“ Unix风格”的外壳始于1969年Unix System 1的外壳 。但是,即使那样,它也受到RUNCOM等旧程序的影响。 如果您曾经注意到某些配置文件以“ rc”结尾(例如。vimrc ),那就是为什么。

If these shells have changed since the 1960s, then why do developers keep on using them?

如果这些外壳自1960年代以来发生了变化,那么为什么开发人员会继续使用它们呢?

Because they haven’t really changed since the 60s. Graphical interfaces for your phone or computer fashionably change with every update (with usability improvements), but command line shells don’t. When you are scripting things or dealing with an entire farm of servers, you really don’t want your (user) interface to change, as it will break your scripts.

因为自60年代以来它们并没有真正改变。 手机或计算机的图形界面会随每次更新而更改(具有可用性方面的改进),但命令行外壳程序却不会。 当您编写脚本或处理整个服务器场时,您确实不希望更改(用户)界面,因为它会破坏脚本。

Thankfully, both command line and graphical shells are both shells around the same thing, so we can use them both interchangeably. Here’s some examples to show what command line shells can do.

值得庆幸的是,命令行和图形外壳程序都是围绕同一事物的外壳程序,因此我们可以将它们互换使用。 这是一些示例,说明命令行外壳程序可以做什么。

行动中的炮弹 (Shells in Action)

We can start small and just get the computer to repeat what we say:

我们可以从小做起,只是让计算机重复我们所说的话:

bash-3.2$ echo hello  hello

The computer also has some special words like $RANDOM:

计算机上还有一些特殊的词,例如$ RANDOM:

bash-3.2$ echo $RANDOM  23914

Bear in mind that almost all of these commands are just little programs that accept some input and emit output. You can find out where they are using which:

请记住,几乎所有这些命令都是接受某些输入并发出输出的小程序。 你可以找出他们正在使用其中:

bash-3.2$ which echo  /bin/echo

With Mac OS, we can even make the computer say stuff:

使用Mac OS,我们甚至可以让计算机说出一些东西:

bash-3.2$ say hello  ["hello" comes from the speakers]
bash-3.2$ say butts butts butts  ["butts butts butts" comes from the speakers without complaint]

There’s also cat which will print out file contents. It’s from 1971.

还有会打印出文件内容。 是从1971年开始的。

bash-3.2$ cat cool_websites.txt  Some websites that I like:
http://codebar.io  http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt

We can use it to read some built in files on your computer:

我们可以使用它来读取您计算机上的一些内置文件:

bash-3.2$ cat /usr/share/dict/words  [skip a few thousand lines]zymotically  zymotize  zymotoxic  zymurgy  Zyrenian  Zyrian  Zyryan  zythem  Zythia  zythum  Zyzomys  Zyzzogeton

That’s every word that your computer knows! That list is pretty long (almost too long to scroll!), but we can use the head command to see the top of it:

那就是您的计算机知道的每一个字! 该列表很长(几乎太长,无法滚动!),但是我们可以使用head命令查看它的顶部:

bash-3.2$ head /usr/share/dict/words  A  a  aa  aal  aalii  aam  Aani  aardvark  aardwolf  Aaron

And there is an opposite command, tail:

还有一个相反的命令, tail

bash-3.2$ tail /usr/share/dict/words  zymotoxic  zymurgy  Zyrenian  Zyrian  Zyryan  zythem  Zythia  zythum  Zyzomys  Zyzzogeton

It would be neat to just get the last word. tail can do this, but requires a special argument. We can look it up using man:

拿到最后的话会很整齐。 tail可以做到这一点,但是需要一个特殊的参数。 我们可以使用man查找它:

bash-3.2$ man tail
TAIL(1)                   BSD General Commands Manual
NAME       tail -- display the last part of a file
SYNOPSIS       tail [-F | -f | -r] [-q] [-b number | -c number | -n number] [file ...]
DESCRIPTION       The tail utility displays the contents of file or, by default, its stan-     dard input, to the standard output.
The display begins at a byte, line or 512-byte block location in the     input.  Numbers having a leading plus (`+') sign are relative to the     beginning of the input, for example, ``-c +2'' starts the display at the     second byte of the input.  Numbers having a leading minus (`-') sign or     no explicit sign are relative to the end of the input, for example, ``-n     2'' displays the last two lines of the input.  The default starting loca-     tion is ``-n 10'', or the last 10 lines of the input.
The options are as follows:
:

Ah! The argument is -n (you press “q” to exit the manual btw):

啊! 参数为-n (按“ q”退出手册btw):

bash-3.2$ tail -n 1 /usr/share/dict/words  Zyzzogeton

I have no idea how to pronounce “Zyzzogeton”, but we can get the computer to do it using the say command. We just pipe the output of tail into the input of say using the pipe character (|):

我不知道如何发音“ Zyzzogeton”,但我们可以使用say命令让计算机来完成它。 我们只是使用竖线字符(|)将tail的输出通过管道输入到say的输入中:

bash-3.2$ tail -n 1 /usr/share/dict/words | say  ["Zyzzogeton" comes from the speakers]

Neat! We can even have multiple pipes. We can pipe cat into tail into say and get the same result:

整齐! 我们甚至可以有多个管道。 我们可以将cat 尾巴 说出来,并得到相同的结果:

bash-3.2$ cat /usr/share/dict/words | tail -n 1 | say  ["Zyzzogeton" comes from the speakers]

Now if we wanted to get a random word, we could get all the words up to a random point and then get the last word of that. We can do that with head and tail:

现在,如果我们想得到一个随机单词,我们可以将所有单词都取到一个随机点,然后得到该单词的最后一个单词。 我们可以用做到这一点:

bash-3.2$ cat /usr/share/dict/words | head -n $RANDOM | tail -n 1 | say  ["atmological" comes from the speakers]

cat reads files from your hard drive, but we can use curl to read files from the internet. Here’s a url for a file that contains the full works of shakespeare:

cat会从您的硬盘驱动器读取文件,但是我们可以使用curl来从Internet读取文件。 这是包含莎士比亚全部作品的文件的url:

bash-3.2$ curl -s http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt  [skip a few thousand lines]  Would yet again betray the fore-betrayed,  And new pervert a reconciled maid.'
THE END
<<THIS ELECTRONIC VERSION OF THE COMPLETE WORKS OF WILLIAM  SHAKESPEARE IS COPYRIGHT 1990-1993 BY WORLD LIBRARY, INC., AND IS  PROVIDED BY PROJECT GUTENBERG ETEXT OF ILLINOIS BENEDICTINE COLLEGE  WITH PERMISSION.  ELECTRONIC AND MACHINE READABLE COPIES MAY BE  DISTRIBUTED SO LONG AS SUCH COPIES (1) ARE FOR YOUR OR OTHERS  PERSONAL USE ONLY, AND (2) ARE NOT DISTRIBUTED OR USED  COMMERCIALLY.  PROHIBITED COMMERCIAL DISTRIBUTION INCLUDES BY ANY  SERVICE THAT CHARGES FOR DOWNLOAD TIME OR FOR MEMBERSHIP.>>
End of this Etext of The Complete Works of William Shakespeare

If we used this curl as an input to our random word pipes, we can get the computer to quote us random lines of Shakespeare!

如果我们将此卷曲用作随机单词管道的输入,则可以使计算机引用莎士比亚的随机行!

bash-3.2$ curl -s http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt | head -n $RANDOM | tail -n 1 | say  ["The sister to my wife, this gentlewoman" comes from the speakers]

We can achieve quite a lot with only a few commands. This philosophy of having small reusable programs that can be combined together has lasted for a long time, much like lego bricks. By combining the right ones, you can make quite an impressive program!

仅需几个命令,我们就可以实现很多目标。 具有可以组合在一起的小型可重用程序的哲学已经持续了很长时间,就像乐高积木一样。 通过组合正确的程序,您可以制作出令人印象深刻的程序!

翻译自: https://www.freecodecamp.org/news/the-command-line-1fdbc692b3bf/

python简史

python简史_命令行简史相关推荐

  1. python登录微信客户端_命令行下的微信客户端

    _____ _ _ _____ _ _ ___ _____ |_ _| | | / __ \| | | | / _ \_ _| | | | | | | / \/| |_| |/ /_\ \| | | ...

  2. Python教程:命令行参数处理

    sys模块 sys模块代表了Python解释器,主要用于获取和Python解释器相关的信息,其中 sys.argv 可以获取命令行参数 在Python交互式解释器中可以先导入sys模块 import ...

  3. python程序在命令行执行提示ModuleNotFoundError: No module named ‘XXX‘ 解决方法

    python程序在命令行执行提示ModuleNotFoundError: No module named 'XXX' 解决方法 参考文章: (1)python程序在命令行执行提示ModuleNotFo ...

  4. kafka _命令行操作

    kafka _命令行操作 #启动zk zkServer.start #启动kafka kafka-server-start.sh -daemon /opt/kafka/config/server.pr ...

  5. mac系统如何转换python版本_mac命令行切换python版本

    brew安装anaconda3 brew cask install anaconda3 安装之后打开路径查看:/usr/local/anaconda3/bin anaconda3环境变量设置 vim ...

  6. python自动化办公模块有哪些-python常见的命令行交互自动化模块有哪些

    用Python写的程序,保存为.py,添加什么命令才能使我一般都是在后面加一个输入语句. python可不可以采用非命令行方式 可以,预先写好代码 使用pythonw.exe执行py文件可以不打开黑框 ...

  7. 干货-运行Python脚本的命令行操作(2)

    本文用到的数据,可以加QQ跟群主获取: 群名称:PYTHONERS-数据 群   号:663468799 学习python和数据分析推荐地方: www.lynda.com   获取lynda官网会员的 ...

  8. 终于要把魔爪伸向shell编程了_命令行参数数量预检测——莫韵乐的小脚印笔记

    终于要把魔爪伸向shell编程了_命令行参数数量预检测 有时候我们在时使用shell的时候都需要传入一些参数,但是有时候我们传入的命令行参数数量不正确就很容易发生错误,因此我们需要在需要传入参数的sh ...

  9. 用Python写一个命令行火车票查看器

    Linux编程点击右侧关注,免费入门到精通! 作者丨protream https://www.jianshu.com/p/f411d7e10c41 当你想查询一下火车票信息的时候,你还在上12306官 ...

最新文章

  1. (七)STM32的RTC简单操作
  2. OrgChart 组织架构与PHP结合使用
  3. java 文件crc校验_JavaCRC校验原理
  4. 中间人攻击框架以及工具,中国寒龙出品欢迎下载!~
  5. wangEditor - 轻量级web富文本编辑器(可带图片上传)
  6. Qt之Q_GLOBAL_STATIC创建全局静态对象
  7. linux学习笔记:1.基础知识和命令行基本操作
  8. C语言、C++学习路线
  9. Python练习:同符号数学运算
  10. 如何使用Maven创建具有依赖项的可执行JAR?
  11. phpcms url伪静态
  12. php微信公众号回复换行,PHP 微信公众号开发,关键字回复使用switch出错
  13. 支付宝支付服务端对接记录(小程序/APP 预支付统一下单及回调处理)
  14. 袁国宝:从“人口红利”到“人才红利”,我们的机会在哪?
  15. c#控件弹幕效果_求C#弹幕游戏弹幕的代码
  16. 2021年电子设计大赛预测--球形机器人设计方案
  17. PC端如何同时登录多个微信账号
  18. html 输入选择框
  19. Drools 7 用OOPath遍历嵌套类型的实体对象
  20. [BZOJ1911] [Apio2010]特别行动队

热门文章

  1. 清华计算机学院新成立,清华AI更进一步:清华大学成立人工智能国际治理研究院...
  2. WCF 第二章 契约
  3. Algs4-1.1.13编写一段代码,打印出一个M行N列的二维数组的转置(交换行和列)
  4. 使用 SQL Server 的 uniqueidentifier 字段类型
  5. sql语句中left join和inner join中的on与where的区别分析
  6. Java BIO、NIO、AIO
  7. CentOS 7.0,启用iptables防火墙
  8. 自己动手,做一款抬头显示的「Todo Hud」
  9. SQL Server 一些重要视图3
  10. shell之冒号的作用