0% found this document useful (0 votes)
19 views

Lecture1 - The Shell

missing semester in CS lecture1

Uploaded by

eastern8ird
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lecture1 - The Shell

missing semester in CS lecture1

Uploaded by

eastern8ird
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

2023/4/19 11:14 For print

Lecture 1: Course Overview + The Shell (2020)


Time Subtitle Machine Translation
0s all right everyone thanks for coming in 好的,谢谢大家的到来,
2s this is the missing semester of your CS 这是您 CS 教育中缺少的一个学期,
Education
7s at least that's what we chose to call 至少这是
9s the class if you're not here for this -
11s class then you're in the wrong room we 我们选择的课程名称。
13s will be here for about an hour just to 小时只是为了
15s set your expectations and I want to talk 设定你的期望,我想
19s to you a little bit first about why 先和你谈谈为什么
21s we're doing this class so this class 我们要上这门课所以这门课
23s stems out of an observation that Anish 源于我和 Anish
25s and Jose and I have made while TA-ing 、Jose 和我
various
29s classes at MIT which is that basically 在麻省理工学院的各种课程中所做的观察 基
本上
31s all of us computer scientists we know 我们所有的计算机科学家都知道
34s that computers are great at doing these 计算机非常擅长执行这些
36s repetitive tasks and automating things 重复性任务和自动化,
38s but we often fail to realize that there 但我们常常没有意识到
41s are lots of tools that can make our own 有很多工具可以使我们自己的
43s development processes better we can 开发过程更好我们可以
be a
45s lot more efficient about how we use our 更有效率 我们如何使用我们的
47s computers because we can use the 计算机,因为我们可以将
49s computer as a tool for ourselves not 计算机用作我们自己的工具,而
51s just for building websites or software 不仅仅是用于构建网站或软件
54s those sorts of things and this class is 之类的东西,本课程
57s an attempt to address this is an attempt 试图解决这个问题,试图向
59s to show you some of the tools that you 您展示一些您
1:03 can use to great effect in your day to 可以使用的工具 在你的
1:05 day in your research and in your 日常研究和学习中产生巨大影响,
studies
1:07 and it's going to be a class where we 这将是一门课,我们
1:10 want you to teach you both how to 希望你教你如何充分利用
make

about:blank 1/37
2023/4/19 11:14 For print

1:15 the most of the tools that you already 你已经


1:16 know but also hopefully teach you 知道的工具,但也希望教你
about
1:19 some tools so you don't know from 一些工具 所以你以前不知道
before
1:20 and how to combine those tools to 如何组合这些工具来
1:23 produce more powerful things than you 产生比你
1:26 think you might be able to do with what 认为
1:28 you know today the class is going to be 你今天所知道的更强大的东西课程将被
1:31 structured as a series of 11 one-hour 组织为一系列 11 个一小时的
1:33 lectures and each one is going to cover 讲座和 每个人都将涵盖
1:36 a particular topic you can see the 一个特定的主题,您可以访问该
1:38 website which is also listed there for 网站,该网站还列出了
1:40 the list of lecture topics and what date 讲座主题列表以及
1:43 will do each one they will mostly be 每个人的演讲日期,他们大多是
1:45 independent and so you can sort of 独立的,因此您可以在某种程度上
show
1:48 up for the ones that you're interested 出现在您喜欢的主题上
1:49 in but we will sort of assume that 感兴趣,但我们会假设
1:51 you've been following along so that as 您一直在跟进,这样当
1:53 we get to later lectures I'm not going 我们进入后面的课程时,我不会再
1:55 to be teaching you bash all over again 教您 bash
1:57 for example we we are also going to 例如,我们也将发布
post
2:02 both the lecture notes and recordings 两个讲座 我们还没有确定在线讲座的笔记和
of 录音,
2:05 the lectures online exactly when we do 具体时间
2:08 that we haven't established yet but it 我们还没有确定,但
2:10 will be after the lectures obviously the 很明显,视频必须在课程结束后
2:12 videos have to be posted after 发布,
2:14 the class is gonna be run by me John 由我主持,约翰和
and
2:16 Anne each sitting over there and Jose 安妮分别坐在那边,何塞
2:19 who is not currently here but we'll be 谁现在不在这里,但我们将
2:21 holding tomorrow's lecture and keep in 举行明天的讲座,请
2:24 mind that we're trying to cover a lot of 记住,我们正试图在
2:25 ground over the course of just 11 短短 11 个
2:27 one-hour lectures and so we will be 一小时的讲座中涵盖很多内容,因此我们的
2:30 moving relatively rapidly but please do 进展相对较快,但请
about:blank 2/37
2023/4/19 11:14 For print

2:33 stop us if there's anything where you 停下来 如果有任何您


2:35 feel like you're not following along if 觉得自己没有跟上的地方 如果您觉得
2:37 you feel like there's something you wish 有一些您希望
2:38 we would spend more time on just let 我们花更多时间做的事情 请告诉我们请
us
2:40 know please interrupt us with questions 打断我们
2:41 and also after each lecture we're going 并在每次讲座后我们将
2:45 to hold office hours on the ninth floor 举行办公时间 在
2:47 of building 30 to the Stata Center of 30 号楼的九楼到
2:49 the computer science building as if you 计算机科学大楼的 Stata 中心,就好像你
2:51 show up up in the ninth floor lounge 出现在九楼的休息室
2:53 there and the gates tower then you can 那里和门塔然后你可以
2:55 come and try some of the exercises 来尝试
that
2:58 we give for each lecture or just ask us 我们为每节课提供的一些练习或者只是 由于
我们可用的时间有限,请就我们
3:00 other questions about things we've -
3:02 talked about in lecturer or other things 在讲师中讨论过的事情或其他有关
3:04 about using your computer efficiently 有效使用您的计算机的事情向我们提出其他
问题,
3:08 due to the limited time that we have -
3:11 available we're not going to be able to 我们将无法
3:13 cover all tools and full detail and so 涵盖所有​​工具和全部细节,因此
3:16 we'll try to do is highlight interesting 我们将 尝试做的是突出有趣的
3:19 tools and interesting ways to use them 工具和使用它们的有趣方式,
3:21 we won't necessarily dig into the deep 我们不一定会深入了解
3:23 details about how all of it works or 所有这些工具的工作原理或
3:25 more elaborate use cases but if you 更详细的用例,但如果您
have
3:27 questions about them please come ask 对它们有疑问,请来问我们
us
3:29 about that too many of these tools are 太多的 这些工具是
3:31 tools that we have used for years and 我们已经使用多年的工具,我们
we
3:33 might be able to point you to additional 可能会向您指出
3:34 interesting things you can do with them 您可以用它们做的其他有趣的事情,
3:36 sort of like take advantage of the fact 比如利用
3:39 that we're here this class is going to I 我们在这里这一事实,这门课将要上课,我
3:42 don't wanna say ramped up quickly but 不想 说快速提升但是在
about:blank 3/37
2023/4/19 11:14 For print

3:45 what's going to happen over the course -


3:46 of this particular lecture is that we'll 这个特定讲座的过程中将会发生的事情是我
们将
3:49 cover many of the basics that we 涵盖许多我们假设
assume
3:51 that you will know for the rest of the 您将在本学期剩余时间知道的基础
3:52 semester things like how to use your 知识,例如如何使用您的
3:54 shell and your terminal and I'll explain shell 和您的终端以及 我将解释
3:56 what those are - those who you're not 它们是什么 - 那些您不
3:57 familiar with them and then will pretty 熟悉的工具,然后会
3:59 quickly ramp up into more advanced 很快开始使用更高级的工具
tools
4:01 and how to use them you can already 以及如何使用它们,您已经
see
4:03 from the lecture notes the kind of 从讲义中看到了
4:05 topics that we're going to be covering 我们将要讨论的主题类型 覆盖,
4:07 and so that brings us to today's lecture 所以这将我们带到今天的讲座
4:10 in which we are going to cover the shell 中,我们将介绍 shell,一旦您想做的事情比
那种类型的更多,
4:12 and the shell is going to be one of the shell 将成为
4:14 primary ways that you interact with your 您与计算机交互的主要方式之一
4:16 computer once you want to do more -
things
4:19 than what the sort of visual interfaces -
4:21 you might be used to allow you to do 您可能用来允许您执行操作的可视化界面
the
4:24 visual interfaces are sort of limited in 可视化界面在
4:26 what -
4:26 they allow you to do because you can 允许您执行的操作方面存在一定的局限性,
因为您只能执行
4:28 only do the things that there are -
4:29 buttons for sliders for input fields for 输入字段中带有滑块按钮的操作,因为
4:32 often these textual tools are built to 这些文本工具通常被构建为
4:34 be both composable with one another 两者都可以相互组合,但
but
4:37 also to have tons of different ways to 也有大量不同的方式来
4:39 combine them or ways to program and 组合它们或编程和
4:41 automate them and that is why in this 自动化它们的方式,这就是为什么在这
4:42 class we will be focusing on these 门课中我们将专注于这些

about:blank 4/37
2023/4/19 11:14 For print

4:44 command line or text-based tools and 命令行或基于文本的工具,而


the
4:48 shell is the place that you would do shell 就是这个地方 您将完成
4:49 most of this work so for those of you 大部分工作,因此对于那些
4:51 are not familiar with the shell most 不熟悉 shell 的人来说,大多数
4:53 platform provides some kind of shell on 平台在 Windows 上提供某种 shell,
4:56 Windows this is often PowerShell but 这通常是 PowerShell,但在 Linux 上的
Windows 上
4:59 there are also other shells available on 也有其他可用的 shell,
5:00 Windows on Linux you will find tons of 您会发现大量的
5:04 terminals these are windows that allow 终端,这些是 允许
5:06 you to display shells and you'll also 您显示 shell 的窗口,您还会
5:08 find many different types of shells the 发现许多不同类型的 shell,
5:10 most common of which is bash or the 其中最常见的是 bash 或 born
born
5:13 again shell because it's such a again shell,因为它是如此常见的
common
5:15 shell it is the one we're primarily shell,它是我们将
5:17 going to be covering in these lectures 在这些中主要介绍的 shell
5:18 if you're on Mac OS you will probably 如果您使用的是 Mac 操作系统,您可能还会
5:21 also have bash maybe an older version 使用 bash
of
5:23 it if you open the terminal app and so 如果您打开终端应用程序,则可能是它的旧
版本,因此
5:26 if you want to follow along on any of 如果您想在这些平台中的任何一个上进行操
作,请
5:27 these platforms feel free but keep in 随意,但请
5:29 mind that most of this is going to be 记住,其中大部分是 就
5:30 sort of Linux centric in terms of how we 我们如何
5:32 teach it even though most of these 教授它而言,即使大多数这些工具都
tools
5:34 work on all the platforms if you want to 适用于所有平台,如果你想
5:39 install a terminal and a shell and you 安装一个终端和一个 shell,但你
5:40 don't know how to do it well we're 不知道如何做好,我们很高兴
happy
5:42 to show you at office hours or it's 在办公时间给你看或者
5:45 usually very easy to just Google like 通常很容易谷歌喜欢
5:47 your platform plus like terminal and you 你的平台加上终端你
5:51 will get one now when you open a 现在会得到一个当你打开一个
5:57 terminal you get something that looks a 终端你会得到一些看起来
about:blank 5/37
2023/4/19 11:14 For print

5:59 little bit like this so it will usually 有点像这样的东西所以它通常


6:01 have just a single line at the top and 只有一行 在顶部,
6:04 this is what's known as the shell prompt 这就是所谓的 shell 提示符,
6:06 you can see that my shell prompt looks 您可以看到我的 shell 提示符看起来
6:07 like this it has my user name the name 像这样它有我的用户名,
6:10 of the machine that I'm on the current 我在当前路径上的机器的名称,
6:12 path I'm on and we will talk about paths 我们将讨论路径
6:14 a little bit later and then it's really 稍后,它真的
6:16 just sort of blinking they're asking me 只是有点闪烁,他们要求我
6:18 for input and this is the shell prompt 输入,这是 shell 提示,
6:20 where you tell the shell what you want 你告诉 shell 你想要
6:22 it to do and you can customize this 它做什么,你可以自定义这个
6:25 prompt a lot and when you open it on 提示,当你打开它时
6:27 your machine it might not look exactly 你的机器 它可能看起来不完全
6:28 like this it might look something like 像这样
6:31 this if you've configured it a little or 如果你稍微配置一下它可能看起来像这样或

6:33 it might look all sorts of different 它可能看起来有各种不同的
6:35 ways we won't go too much into 方式 我们不会过多地
6:38 customizing your shell in this 定制你的 shell
6:39 particularly 特别是
6:40 we'll do that later here we're just 我们会做 稍后在这里我们将
6:41 going to talk about how do you use this 讨论如何使用这个
6:43 shell to do useful things and this is shell 来做有用的事情,这是
6:47 our the main textual interface you have 我们的主要文本界面,你必须
6:49 to your computer's through this shell on 通过这个 shell 在
6:51 the shell prompt you get to write shell 提示符下你可以编写
6:53 commands and commands can be 命令和命令可以是 相对
relatively
6:55 straightforward things usually it'll be 简单的事情通常它会
6:58 something like executing programs with 像执行带有
7:00 arguments what does that look like well 参数的程序什么看起来不错
7:02 one program we can execute is the 我们可以执行的一个程序是日期
date
7:04 program we just type date and press 程序我们只需键入日期并按
7:06 enter and then it will show you 回车键然后它会

about:blank 6/37
2023/4/19 11:14 For print

7:07 unsurprisingly the date and time you 毫不奇怪地显示日期和时间你


can
7:10 also execute a program with arguments 也可以 执行带有参数的程序
7:12 this is one way to modify the behavior 这是修改程序行为的一种方法,
7:14 of the program so for example there is 例如有一个
a
7:17 program called echo and echo just 名为 echo 的程序,echo 只是打印
prints
7:20 out the arguments that you give it and 出你给它的参数,而
7:22 arguments are just white space 参数只是
separated
7:25 things that follow the program name so 程序名称后面的空格分隔的东西所以
7:27 we can say hello and then it will print 我们可以打个招呼,然后它会打印
7:29 hello back 出
7:30 perhaps not terribly surprising but this 你好也许并不令人惊讶,但这
7:32 is the very basics of arguments one 是参数的最基本知识,
7:35 thing that you'll notice is that I said 你会注意到一件事是我说过
7:37 that arguments are separated by 参数是由空格分隔的
7:38 whitespace and you might wonder well ,你可能想知道
7:40 what if I want an argument as multiple 如果我想要一个 作为多个
7:42 words you can also quote things so you 单词的参数你也可以引用一些东西这样你就
7:44 can do things like echo hello space 可以做类似echo hello space
7:47 world and now the echo program world这样的事情现在echo程序接收到
receives
7:50 one argument that contains the string 一个包含字符串
7:52 hello world with a space well you can hello world和一个空格的参数你
7:55 also use single quotes for this and the 也可以使用单引号和
7:57 difference between single quotes and 单引号之间的区别 引号和
7:58 double quotes will get back to and 双引号将回到,当
when
8:00 we talk about bash scripting you can 我们谈论 bash 脚本时,您
8:03 also just escape single characters so 也可以只转义单个字符,
8:06 for example hello world this will also 例如 hello world 这也可以
8:09 work just fine all of these rules about 正常工作所有这些关于
8:12 how you escape and how you parse 如何转义以及如何解析和
and
8:15 quote various arguments and variables 引用各种参数的规则以及
8:17 we'll cover a little bit later hopefully 我们稍后会介绍变量希望
8:19 you won't run into too many we oughta 你不会遇到太多我们应该对此

about:blank 7/37
2023/4/19 11:14 For print

8:21 tease about this just keep in mind at 取笑至少记住


8:23 least that spaces separate arguments 空格分隔参数所以
so
8:26 if you want to do something like make a 如果你想做一些事情比如创建一个
8:27 directory called my photos 名为我的照片的目录
8:29 you can't just type like make directory 你可以' 不只是键入 make directory
8:31 my photos it will create two directories my photos 它将创建两个目录,
8:33 one called my and one called photos 一个名为 my,一个名为 photos
and
8:35 that is probably not what you want now -
8:40 one thing you might ask is how does -
the
8:43 shell know what these programs are -
when
8:45 I type date or when I type echo how 我输入 echo
does
8:48 it know what these programs are 它怎么知道这些程序应
supposed
8:50 to do and the answer to this is your 该做什么 答案是你的
8:53 program your 程序
8:54 computer has a bunch of built-in -
8:55 programs that comes with the machine -
8:57 just like you your machine my chip with -
8:59 like the terminal app or it might chip 它可能
9:02 with like Windows Explorer or at my 与 Windows Explorer 类似,或者在我的芯片
chip 上
9:05 with some kind of browser it also ships 带有某种浏览器它还附带
9:07 with a bunch of terminal centric 了一堆以终端为中心的
9:09 applications and these are stored on 应用程序,这些应用程序存储在
9:11 your file system and your shell has a 你的文件系统中,你的 shell 有
9:14 way to determine where a program is 办法确定程序的
9:18 located basically has a way to search 位置基本上有一个 搜索
9:19 for programs it does this through 程序的方法 它是通过
9:22 something called an invariant 称为不变
9:24 environment variable an environment 环境变量的东西来实现的 环境
9:27 variable is a variable like you might be 变量是一个变量,就像您可能
9:29 used to for programming languages it 习惯于使用编程语言一样 事实
9:31 turns out that the shell and the 证明,shell 尤其是
9:33 bourne-again shell in particular is bourne-again shell 确实是

about:blank 8/37
2023/4/19 11:14 For print

9:35 really a programming language this 一种编程语言 这


9:37 prompt that you're given here is not 这里给出的提示不仅仅是
9:39 just able to run a program with 能够运行带
9:41 arguments. You can also do things like 参数的程序。 您还可以执行诸如
9:43 while loops, for loops, conditionals... while 循环、for 循环、条件...
9:46 All of these - you can define 所有这些 - 您可以定义
9:47 functions, you can have variables, and 函数,您可以拥有变量,以及所有
all
9:49 of these things you can do in the shell. 这些您都可以在 shell 中执行的操作。
9:51 We'll cover a lot of that in the next 我们将在下一
9:52 lecture, on shell scripting. For now, 讲关于 shell 脚本的课程中介绍其中的大部分
内容。
9:56 though, let's just look at this 不过现在,让我们看看这个
9:57 particular environment variable. 特定的环境变量。
9:59 Environment variables are things that 环境变量是在
10:01 are set whenever you start your shell 你启动 shell 时设置的东西,
10:02 they're not things you have to set every 它们不是你每次运行 shell 时都必须设置的东
西,
10:04 time you run your shell there are a 有
10:06 bunch of these that are set things like 很多设置的东西,比如
10:08 where is your home directory what is 你的主目录在哪里,
10:09 your username and there's also one 你的用户名是什么,还有 一个
10:11 that's critical for this particular 对于这个特定
10:13 purpose which is the path variable so if 目的至关重要的路径变量,所以如果
10:16 I echo out dollar path this is going to 我回显美元路径,这将向
10:18 show me all of the paths on my 我显示我的机器上
machine
10:22 that the shell will search for programs shell 将搜索程序的所有路径,
10:25 you'll notice that this is a list that 你会注意到这是一个列表
10:27 is colon separated it might be kind of 冒号分隔它可能有点
10:30 long and hard to read but the essentials 长而且难以阅读,但要点
10:33 is that - whenever you type the name of 是 - 每当您键入
10:36 a program is gonna search through this 程序名称时,它将
10:38 list of paths on your machine and it's 在您的机器上搜索此路径列表,并
10:41 gonna look in each directory for a 在每个目录中查找
10:43 program or a file whose name matches 程序或文件 其名称与
the

about:blank 9/37
2023/4/19 11:14 For print

10:46 command you try to run so in my case 您尝试运行的命令相匹配,所以在我的情况


下,
10:49 when I try to run date or echo it's 当我尝试运行 date 或 echo 时,它
10:51 gonna walk through these one at a time 会一次遍历这些命令,
10:52 until it finds one that contains the 直到找到包含
10:54 program called date or echo and then 名为 date 或 echo 的程序的程序,然后
10:56 it's gonna run it if we want to know 如果我们运行它,它就会运行它 想知道
10:58 which one it actually runs there's a 它实际运行的是哪一个,有一个
11:00 command called which which lets us do 命令叫 which 让我们可以
11:01 that so I can type which echo and will 这样做所以我可以输入 which echo 并
11:04 tell me that if I were to run a program 告诉我如果我要运行一个
11:07 called echo I would run this one it's 名为 echo 的程序我会运行这个程序
11:10 worth pausing here to talk about what 值得在这里暂停一下
11:12 paths are so paths are a way to name 路径是什么路径是
the
11:16 location of a file on your computer on 在
11:18 Linux and Oh Mac OS these paths are Linux 和 Oh Mac OS 上命名文件在计算机上
的位置的方法这些路径
11:21 separated by slashes forward slashes 由斜杠正斜杠分隔所以
so
11:24 you'll see here that this is in the in 你会在这里看到它在
11:28 the root directory so the slash at the 根目录中所以斜杠 在
11:30 very beginning indicates that this is 一开始表明这是
11:32 starting from the top of the file system 从文件系统的顶部开始,
11:34 then look inside the directory called 然后查看名为
11:37 USR then look inside the directory bin USR 的目录,然后查看目录 bin
11:40 and then look for the file called echo ,然后
11:43 on windows paths like this are usually 在 Windows 路径上查找名为 echo 的文件,
这样的路径通常
11:46 separated by back slashes instead and 由反斜杠分隔,
11:48 we're on Linux and Mac OS everything 我们在 Linux 和 Mac OS 上,一切都
11:51 lives under the root name space so all 在根命名空间下,所以所有
11:53 paths start with a slash or all absolute 路径都以斜杠开头,或者
11:56 paths on Windows there is one root for 在 Windows 上所有绝对路径,每个分区都有
一个根,
12:00 every partition so you might have seen 所以你可能已经看到
12:02 things like C colon backslash or D 像 C 冒号反斜杠或 D 冒号
colon

about:blank 10/37
2023/4/19 11:14 For print

12:05 backslash so Windows has separate 反斜杠这样的东西所以 Windows 对您拥有的


sort 每个驱动器都有单独的
12:08 of file system path hierarchies for each 文件系统路径层次结构,
12:11 each Drive that you have -
12:13 whereas on Linux and Mac OS these 而在 Linux 和 Mac OS 上,这些
are
12:14 all mounted under one namespace 都安装在一个名称空间下,您会
you'll
12:18 notice that I said the word absolute 注意到我说的是绝对
12:20 path and you might not know what that 路径这个词,您可能不知道这
12:21 means so absolute paths are paths that 意味着什么如此绝对 路径是
12:27 fully determine the location of a file 完全确定文件位置的路径,
12:29 so in this case this is saying this is 所以在这种情况下,这是说这
12:31 talking only about a specific echo file 只是在谈论一个特定的回显文件,
12:33 and it's giving you the the full path to 它为您提供了
12:36 that file but there are also things 该文件的完整路径,但也有
12:39 known as relative paths so a relative 所谓的相对路径,所以相对
12:42 path is relative to where you currently 路径是相对于你当前位置的
12:45 are and so the way we find out where ,所以我们找出当前
we
12:49 currently are is you can type PWD for 位置的方法是你可以输入 PWD for
12:52 present working directory present print present working directory present print
12:56 working directory so if I type PWD it working directory 所以如果我输入 PWD
13:00 will print out the current path that I'm 它将打印出我所在的当前路径
13:02 in right so currently I'm in the home 所以目前我在
13:05 directory under the root and then John 根目录下的主目录中,然后是 John 在
13:08 under that and then dev under that etc 那个目录下,然后是 dev 在那个目录下等
等,然后
13:11 from here I can then choose to change 我可以选择更改我
my
13:14 current working directory and all 当前的工作目录,所有
13:16 relative paths are relative to the 相对路径都是相对于
13:18 current working directory which is 当前工作目录的,这
13:20 basically where you 基本上是在哪里 你
13:21 they are in this case for example I can 在这种情况下,例如,我可以
13:24 do CD / home CDs change directory 做 CD/home CD 更改目录,这
this
13:28 is the way that I change what my 是我更改当前
current

about:blank 11/37
2023/4/19 11:14 For print

13:30 working directory is in this case I 工作目录的方式,在这种情况下,我


13:32 change to home and I am now you'll 更改为 home,现在你会看到
see
13:34 my my shell prompt change to say that 我的 shell 提示符更改 说我
I
13:37 am now in home it just gives me the 现在在家里,它只给我
name
13:40 of the last segment of the path but you 路径最后一段的名称,但你
13:42 can also configure your terminal to give 也可以配置你的终端,
13:44 you the full path whenever you're 无论你身在何处,都能为你提供完整路径
13:45 anywhere and now if I type PWD again ,现在如果我再次输入 PWD,它
it
13:50 will tell me I'm in slash home there are 会告诉我 我在 slash home 中还有
13:53 also a couple of special directories 一些特殊的目录
13:54 that exist there is dot and dot dot dot 存在点和点点点
13:59 means the current directory dot dot 表示当前目录点点
14:03 means the parent directory so this is a 表示父目录所以这是一种
14:05 way that you can easily navigate 你可以轻松地在系统中导航的方式
around
14:06 the system for example here if I type 例如在这里如果 我输入 CD
CD
14:09 dot dot it will tell me that I am now in dot dot 它会告诉我我现在在
14:13 slash so I'm now in the root of the file 斜线中所以我现在在文件系统的根目录中
14:15 system I was in slash home now I'm in 我在斜线中现在
14:17 slash and indeed if I type PWD well it 我在斜线中实际上如果我正确输入 PWD 它
14:22 will do that right thing and I can also 会做对 东西,然后我还可以
14:24 then use relative paths to go down into 使用相对路径进入
14:26 the file system right so I can do CD dot 文件系统,这样我就可以做 CD 点
14:28 slash home and this is gonna CD into 斜线回家,这将 CD 进入
the
14:31 home directory under the current 当前
14:34 directory right so this will bring me 目录下的主目录,所以
14:36 back to slash home if I now tried CD 如果我 现在再次尝试 CD 点
dot
14:39 slash home again it will say there's no 斜杠 home 它会说没有
14:42 such directory because there is no 这样的目录,因为我所在的
home
14:44 directory under the current directory 当前目录下没有主目录,
14:45 I'm on which I changed by doing CD 我通过正确执行 CD 更改了它,
right
14:49 and I can sort of see de all the way 我可以看到 de 一直
about:blank 12/37
2023/4/19 11:14 For print

14:53 back to the place that I was using 回到那个地方 我使用的是


14:57 relative paths and I can also do things 相对路径,我也可以做
15:01 like dot dot dot dot dot to get back to 类似 dot dot dot dot dot dot 之类的事情来回

15:07 somewhere deep in my file system this 我的文件系统深处的某个地方,这
15:09 happens to be all the way back to the 恰好一直回到
15:10 root so here there's a bin directory and 根目录,所以这里有一个 bin 目录,
15:13 another bin there's an echo file and so 另一个 bin 有一个 echo file 然后
15:15 then I could do world and that runs the 我可以做 world 并且
15:17 echo program under bin alright so this 在 bin 下运行 echo 程序好吧所以这
15:20 is a way that you can construct paths to 是一种你可以构建路径以
15:22 arbitrarily traverse your filesystem 任意遍历你的文件系统的方法
15:24 sometimes you want to absolute paths 有时你想要绝对路径有时
and
15:26 sometimes you want relative ones 你想要相对路径通常
usually
15:28 you want to use whichever one is 你想使用任何一个 一个更短,
shorter
15:29 but if you want to for example run a 但是如果你想运行一个
15:30 program or write 程序或编写
15:34 a program that runs the program like 一个运行程序的程序,比如
15:36 echo or date and you want it to be able echo 或 date,并且你希望它能够
15:38 to run be run from anywhere you either 从任何地方运行,你
15:41 want to just give the name of the 只想给出程序的名称,
15:43 program like date or echo and let the 比如 date 或 echo 并让
the
15:45 shell use the path to figure out where shell 使用路径找出
15:47 it is or you want to give its absolute 它的位置,或者你想给出它的绝对
15:49 path because if you gave a relative 路径,因为如果你给出了相对路径,
path
15:51 then if I ran it in my home directory 那么如果我在我的主目录中运行它
15:53 and you ran it in some other directory 而你在其他目录中运行
15:55 it might work for me but not for you in 它 可能对我有用,但通常对你不起作用,
16:01 general when we run a program it is 当我们运行一个程序时,它
16:04 going to be operating on the current -
16:06 working directory at least by default 至少在默认情况下会在当前工作目录上运
行,
16:08 unless we give it any other arguments 除非我们给它任何其他参数
16:09 and this is really handy because it ,这真的很方便,因为这
about:blank 13/37
2023/4/19 11:14 For print

16:11 means that often we don't have to give 意味着我们通常不会 不必为


16:13 full paths for things we can just use 事物提供完整路径我们可以只使用
16:15 the name of files and in the directory 文件名和
16:17 that we're currently in one thing that's 我们当前所在的目录,
16:20 really useful is to figure out what is 真正有用的一件事是弄清楚
16:22 in the current directory we're in so we 我们所在的当前目录中有什么,所以我们
16:24 already saw PWD which prints where 已经看到了 PWD 它打印出你
you
16:26 currently are there's a command called 当前所在的位置,有一个名为
16:28 LS which will show you it will list the LS 的命令,它会向你显示它将列出
16:31 files in the current directory so if i 当前目录中的文件,所以如果我
16:33 type LS here this is all the files in 在此处键入 LS,这就是当前目录中的所有文

16:35 the current directory right and this is ,这是
16:38 a handy way to just quickly navigate 一种快速导航的便捷方式
16:39 through the filesystem you'll see that 通过文件系统你会看到,
16:43 if I sort of CD dot and then do LS it'll 如果我对 CD 点进行排序然后执行 LS,它会

16:46 show me the files in that directory 我显示该目录中的文件,
16:48 instead but with LS I can also give it 但是使用 LS 我也可以给它
16:53 LS dot dot like I can give it a path and LS 点点,就像我可以给它一个路径
16:56 then will LS that file instead of the 然后将 LS 那个文件,而不是
16:58 one that I'm currently in or LS that 我当前所在的那个文件,或者 LS 那个
16:59 directory and you can see this if I go 目录,如果我一直走到根目录,你可以看到
这个,
17:04 all the way to the root as well right 右
17:05 root has different files one handy trick 根目录有不同的文件,一个
17:09 you might not know about here is there 你可能不知道的方便的技巧是
17:11 are two other special things you can do 你可以做的另外两件特别的事情,
17:13 one is the tilde character this 一个是波浪字符这个
17:16 character brings you to your home 字符带你到你的主
17:18 directory so tilde always expands to the 目录所以波浪总是扩展到
17:21 home directory and you can do relative 主目录你可以做
17:23 paths to it so I can do tilde slash dev 它的相对路径所以我可以做波浪斜线开发
17:25 slash P DOS classes missing semester 斜线 P DOS classes missing semester and
and
17:30 now I'm there because tilde expanded 现在我在那里,因为波浪号扩展为
to
about:blank 14/37
2023/4/19 11:14 For print

17:32 slash home slash John there is also for 斜杠主斜杠约翰还有


17:36 CD in particular a really handy CD 特别是一个非常方便的论点,
argument
17:39 you can give which is - if you do CD - 你可以给出 - 如果你做 CD -
17:42 it will CD to the directory you were 它会 CD 到你
17:44 previously in so if I do CD - I go back 以前所在的目录所以如果我做 CD -
17:47 to root -
17:48 if I do CD - again I go back to missing 如果我做 CD,我会回到根目录 - 我会再次回
到错过的
17:52 semester so this is a handy way if you 学期,所以如果你
17:53 want to toggle between two different 想在两个不同的目录之间切换,
17:55 directories in the case of LS or in the 在 LS 或
18:01 case of CD there might be arguments CD 的情况下,这是一个方便的方法,你可
do 能会有争论吗
18:03 you don't know about right currently we 目前不知道是否正确,除了提供路径之外我
们还
18:06 haven't really been doing anything 没有真正做任何事情,
18:07 except giving paths but how do you 但是你如何发现
even
18:09 discover that you can give a path to LS 你可以首先提供 LS 的路径
18:11 in the first place well most programs 好吧大多数程序都
18:14 take what are known as arguments like 采用所谓的参数,如
18:16 flags and options these are things that 标志和选项这些 是
18:18 usually start with a - one of the Hemi 通常以 a 开头的东西 - 其中一个 Hemi
18:21 is one of these is - help most programs 是其中之一 - 帮助大多数程序
18:24 implement this and if you run for 实现它,如果你运行
18:26 example LS - help it all helpfully print 例如 LS - 帮助它打印
18:30 out a bunch of information about that 出关于该命令的一堆信息
18:34 command and you'll see here that it ,你会在这里看到 它说
says
18:36 the usage is LS and you can give some 用法是 LS 你可以给一些
18:38 number of options and you can give 选项,你可以给一些
some
18:40 number of files the way to read that 文件的方式来读取该
18:42 usage line is triple dot means one like 用法行是三重点表示一个像
18:46 zero or one or more and the square 零或一个或多个,方
18:48 bracket means optional so in this case 括号表示可选所以在这个 如果
18:50 there's an optional number of options 有可选数量的选项
18:52 and there's an optional number of files 和可选数量的文件,
about:blank 15/37
2023/4/19 11:14 For print

18:54 and you'll see that it says what the 你会看到它说明了


18:56 program does and also specifies a 程序的作用,还指定了许多
number
18:58 of different types of flags and options 不同类型的标志和选项,
19:00 you can give usually we call things that 通常我们称之为
19:03 are a single dash in a single letter a 单破折号 在一个字母中,一个
19:04 flag and anything that or anything that 标志和任何
19:07 doesn't take a value a flag and anything 不带值的东西,一个标志和任何
19:09 that does take a value an option so for 带值的东西,一个选项,
19:11 example - a and - all are both flags and 例如 - a 和 - 都是标志,
19:16 - C or - color R is an option one thing - C 或 - color R 是一个选项
19:22 you'll see under here if you scroll down 如果你向下滚动足够远,你会在此处看到的
一件事
19:24 far enough is the - L flag and that's 是 -L 标志,它
19:30 unhelpful the - L flag the - L flag uses 没有帮助 -L 标志 -L 标志
19:37 a long listing format now that's 现在使用长列表格式,这
19:39 particularly helpful in and of itself 本身特别有用,
19:40 but let's see what it actually does so 但让我们看看它实际上做了什么 因此,
19:43 if I do LS dash L it still prints the 如果我执行 LS dash L 它仍然会打印
19:46 files in the current directory but it 当前目录中的文件,但它会
19:48 gives me a lot more information about 为我提供有关
19:49 those files and this is something you'll 这些文件的更多信息,这是您会
19:52 find yourself using quite a lot because 发现自己经常使用的内容,因为
19:54 the additional information it gives you 它提供给您的附加信息
19:56 is often quite handy let's look at what 通常非常多 方便让我们看看
20:00 some of that information 其中的一些信息
20:02 ah so first of all the D at the 啊所以首先
20:09 beginning of some of these entries 这些条目中的一些开头的 D
20:10 indicate that something is a directory 表示某物是一个目录
20:11 so the underscore data entry here for 所以这里的下划线数据条目
20:14 example is a directory 例如是一个目录
20:16 whereas for for hTML is not a directory 而对于 hTML 来说不是一个目录
20:18 it's a file the following letters after 它是 一个文件后面的字母
20:22 that indicate the permissions that are 表示
20:25 set for that file so this like we saw 为该文件设置的权限,所以就像我们
20:28 earlier I might not be able to open a 之前看到的那样,我可能无法打开给
20:30 given file or I might not be able to CD 定的文件,或者我可能无法将 CD
about:blank 16/37
2023/4/19 11:14 For print

20:32 into a given directory and this is all 放入给定的目录,这都是


20:34 dictated by the permissions on that 由该
20:35 particular file or directory the way to 特定文件或目录的权限
20:37 read these is that the the first group 阅读这些的方式是第一组
20:41 of three are the permissions are set for 三个字符是为文件所有者设置的权限
20:43 the owner of the file all of these files -
20:45 you'll see are owned by me the second 您将看到的所有这些文件都归我所有第二
20:49 group of three characters is for the 组三个字符 用于
20:52 permissions for the group that owns 拥有此文件的组的权限
this
20:53 file in this case all of these files are 在这种情况下,所有这些文件
20:56 also known by the john group and a 也为 john 组所知,最后一
final
20:58 group of three is a list of the 组三个是
21:01 permissions for everyone else so 其他所有人的权限列表,因此任何
anyone
21:03 who's not a user owner or a group 不是用户所有者或组的人 owner
owner
21:06 this directory is perhaps kind of boring 这个目录可能有点无聊,
21:08 because all of the things are owned by 因为所有的东西都归
21:10 me but if we do something like CD to 我所有,但如果我们做一些像 CD 的
21:14 slash and do LS dash L you'll see that 斜杠和 LS dash L 你会看到
21:17 here all of them are owned by root we'll 这里所有的东西都归 root 所有,我们将
21:20 get back to what the root user is but 回到 root 用户是什么,但
21:22 here you see some of the permissions 在这里你会看到一些权限
are
21:24 a little bit more interesting the groups 更有趣一点
21:26 of three are read write and execute 三组是读写和执行
what
21:31 these mean differs for files and for 这些意味着文件和
21:34 directories for files it's pretty 文件目录的不同
21:36 straightforward if you have read 如果你对文件有读取
21:37 permissions on a file then you can read 权限就很简单了 然后你可以读取
21:40 its contents if you have write 它的内容如果你有
21:41 permissions on a file then you can save 一个文件的写权限然后你可以保存
21:43 the file you can add more to it or you 文件你可以添加更多或者你
21:46 can replace it entirely and if you have 可以完全替换它如果你已经
21:48 execute to the X bit on a file then 执行到文件的X位那么
21:50 you're allowed to execute that file so 你可以 执行那个文件,所以
about:blank 17/37
2023/4/19 11:14 For print

21:52 if we do LS al in slash bin that's a 如果我们在 slash bin 中执行 LS al 那是一个


21:57 novel and user bin you'll see that all 小说和用户 bin 你会看到
22:00 of them have the execute bit set even 他们都设置了执行位,即使
22:02 for people who are not the owner of the 对于不是文件所有者的人也是如此,
22:04 file and this is because the echo 这是因为 echo
22:06 program for example we want everyone 程序 例如,我们希望计算机上的每个人都
on
22:08 the computer to be able to execute 能够执行,
22:09 there's no reason to say only certain 没有理由说只有某些
22:11 users can run echo that doesn't really 用户可以运行回显,这对目录没有
22:13 make any make any sense 任何意义,
22:15 for directories though these 尽管这些权限
permissions
22:18 are a little bit different so read 有点不同,所以阅读
22:20 translates - are you allowed to see 翻译 - 你允许吗 查看
22:23 which files are inside this directory so 此目录中有哪些文件所以将读取
22:26 think of read as lists for a directory 视为目录列表
22:28 are you allowed to list its contents 是否允许列出其内容
22:30 write for a directory is whether you are 为目录写入是否
22:33 allowed to rename create or remove 允许重命名
files
22:36 within that directory so it's still kind 在该目录中创建或删除文件所以它仍然是
22:39 of right but notice that this means that 正确的但注意 这意味着
22:42 if you have write permissions on a file 如果您对文件具有写权限
22:45 but you do not have write permissions 但对其目录没有写权限,则
on
22:47 its directory you cannot delete the file 无法删除该文件,
22:49 you can empty it but you cannot delete 您可以清空它但不能删除
22:52 it because that would require writing to 它,因为这需要写入
22:54 the directory itself and finally execute 目录本身并最终
22:57 on directories is something that trips 在目录上执行 是使
22:59 people up a lot execute on a directory 人们经常绊倒的东西 在一个目录上执行
23:01 is what's known as search and that's 就是所谓的搜索,这个
not
23:04 terribly helpful a name but what that 名字不是很有用,但这
23:07 means is are you allowed to enter this 意味着
23:10 directory if you want to get to a file 如果你想打开一个文件,你是否允许进入这
个目录

about:blank 18/37
2023/4/19 11:14 For print

23:13 if you want to open it or read it or 或阅读或


23:15 write it whatever you want to do 写入任何你想做的
23:16 basically to CD into a directory you 基本上CD到一个目录你
23:20 must have the execute permission on 必须
all
23:22 parent directories of that directory and 对该目录的所有父目录和
23:25 the directory itself so for example for 目录本身具有执行权限所以例如
23:28 me to access a file inside slash user 我要访问斜杠用户
23:30 slash bin such as user bin echo I must slash bin中的文件例如 user bin echo 我必须
23:34 have executed on route I must have 在路由上执行我必须
23:35 execute on user and I must have 在用户上执行并且我必须
execute
23:38 on bin if I do not have all those 在 bin 上执行如果我没有所有这些
23:40 execute bits I will not be allowed to 执行位我将不允许
23:42 access that file because I won't be able 访问该文件因为我将无法
23:44 to enter the directories along the way 输入 一路上的目录
23:48 there are a number of other bits that 还有许多其他位
23:50 you might come across like you might 你可能会遇到像你可能会
see
23:52 esses or T's in these lists you might 在这些列表中看到 esses 或 T's 你可能会
23:55 see LS those we can talk about in office 看到 LS 那些我们可以在办公时间讨论
23:58 hours if you're curious 如果你好奇的话
23:58 they will mostly not matter for anything 它们几乎无关紧要
24:01 you will do in this class but they are 你会在这门课上做,但它们
24:04 handy to know about so if you're 很容易了解,所以如果你对
curious
24:05 about them look them up on your own 它们感到好奇,可以自己查一下,或者
or
24:08 come ask us in office hours there are 在办公时间来问我们还有
24:11 some other programs that are handy to 一些其他的程序很容易
24:13 know about oh sorry there's one more 了解哦抱歉还有一个
24:14 thing as I mentioned if you just have a 正如我提到的,如果你只有一个
24:16 dash it means you do not have that 破折号,这意味着你没有那个
24:17 permission right so if it says for 权限所以如果它说
24:19 example our dash X it means that you 例如我们的破折号 X 这意味着你
24:21 have read and execute but you do not 已经阅读并执行但你
24:23 have right there are some other handy 没有权利还有一些其他方便的
24:27 programs to know about at this point 程序要知道 大约在这一点上,

about:blank 19/37
2023/4/19 11:14 For print

24:29 one of them is move or the MV 其中一个是 move 或 MV 命令,所以


command so
24:32 if I CD back to missing semester here 如果我在这里 CD 回到缺少的学期,MV
MV
24:35 lets me rename a file and rename here 让我重命名一个文件并在此处重命名
24:39 takes two paths it takes the old path in 采用两条路径,它采用新路径中的旧路径,
24:42 the new path this is means that move 这意味着 move
24:45 lets you both rename a file like if you 可以让你 两者都重命名文件,就像您
24:47 change the name of the file but not the 更改文件名而不是
24:49 directory or it lets you move a file to 目录一样,或者它允许您将文件移动到
24:52 a completely different directory it just 一个完全不同的目录,它只是
24:54 you give the path to the current file 您提供当前文件的路径
24:56 and the path to where you want that file 和您希望该文件所在位置的路径
24:57 to be and that can change its location 这可以改变它的位置
24:59 and its name so for example I can 和它的名字,所以例如我可以移动
move
25:02 dot files dot MD to be food MD 点文件点 MD 成为食物 MD
25:05 unhelpfully right and similarly I can 没有帮助,类似地我可以
25:09 move it back there's also the CP 把它移回去还有 CP 命令
command
25:16 the CP or copy is very similar it lets CP 或复制非常相似它可以让
25:19 you copy a file CP also takes two 你复制一个文件 CP 还采用两个
25:21 arguments it takes the path you want to 参数,它采用您要
25:23 copy from and the path you want to 复制的路径和要复制
copy
25:25 to and these are full paths so I could 到的路径,这些是完整路径,所以我可以
25:28 use this for example to say I want to 用它来举例说明我想将
25:30 copy dot files out MD - dot dot slash 点文件复制出 MD - 点点斜线
25:32 food MD sure food MD and now if I do 食物 MD 确定食物 MD,现在如果我做 LS
LS
25:37 dot you'll see that there's a food MD 点,你会看到该目录中有一个食物 MD
25:39 file in that directory so CP as well 文件,所以 CP 也
25:42 take two paths it does not have to be in 采用两条路径,它不必在
25:44 the same directory and similarly there's 同一目录中,同样有
25:47 the RM command which lets you RM 命令可以让你删除 一个
remove a
25:49 file and there - you can give paths in 文件在那里 - 你可以在
25:52 this case I'm removing dot dot slash 这种情况下给出路径我正在删除点点斜线
25:54 food you should be aware for removing 食物你应该知道删除

about:blank 20/37
2023/4/19 11:14 For print

25:56 especially on Linux removal is by 特别是在 Linux 上删除


25:59 default not recursive so you cannot 默认情况下不是递归的所以你不能
26:01 remove a directory using RM you can 使用 RM 删除目录你可以通过
pass
26:05 the - our flag which lets you do a - 我们的标志 它可以让你进行
26:07 recursive remove and then give a path 递归删除,然后给出一个
26:09 that you want to remove and it will 你想要删除的路径,它将
26:10 remove everything below it there is also 删除它下面的所有内容还有
26:12 the RM dr dir command which lets you RM dr dir 命令,它可以让你
26:16 remove a directory but it only lets you 删除一个目录,但它只允许你
26:18 remove that directory if it is empty so 删除该目录,如果它是空的 所以
26:21 the idea here is to sort of be a safety 这里的想法是
26:22 mechanism for you so you don't 为你提供一种安全机制,这样你就不会
26:23 accidentally throw away a bunch of 不小心扔掉一堆
your
26:25 files and the final little command 文件,最后一个
26:28 that's handy to use is make there which 方便使用的小命令是 make there,它
26:31 lets you create a new directory and as 可以让你创建一个新目录,正如
26:32 we talked about before you don't want 我们所说的 大约在你不想
to
26:34 do something like this because it will 做这样的事情之前,因为它会
26:36 create two directories for you one 为你创建两个目录,一个
26:37 called my and one called photos if you 叫我的,一个叫照片,如果你
26:40 actually want to create a directory like 真的想创建一个
26:42 this you would either 这样的目录,你要么
26:42 escape the space or quote the string if 转义空格,要么引用字符串,如果
26:50 you ever want more information about 你曾经 想要更多关于
how
26:52 any command to basically on these 任何命令在这些平台上基本如何
26:54 platforms work there's a really handy 工作的信息,有一个非常方便的
26:57 command for that as well 命令,还有一个
26:58 there is the program called man for 名为 man 的程序用于
27:00 manual pages this program takes as an 手册页,该程序将
27:04 argument the name of another program 另一个程序的名称作为参数,并
and
27:06 gives you its manual page so for 为您提供其手册页,因此 例如,
example
27:09 we could do man LS and this shows us 我们可以执行 man LS,这向我们展示了
a

about:blank 21/37
2023/4/19 11:14 For print

27:12 manual page for LS you'll notice that in LS 的手册页,您会注意到,在


27:14 the case of LS it is fairly similar to LS 的情况下,它
27:16 what we got with LS - help but it's a 与我们在 LS 中获得的非常相似 - 帮助,但
它更
27:19 little easier to navigate a little 容易导航,
27:20 easier to read usually towards the 通常更容易阅读 在
27:23 bottom you will also get examples 底部,您还将获得
27:26 information about who wrote it where 有关谁编写它的示例信息,您
you
27:28 can find more information and that sort 可以在其中找到更多信息以及这类
27:29 of stuff one thing that can be confusing 东西,
27:32 sometimes 有时
27:32 at least until a recent version where 至少在最近的版本之前可能会造成混淆,
27:35 they added this three at the bottom 他们在底部添加了这三个,上面
27:36 which says Q to quit they do not use to 写着 Q to quit 他们不习惯
27:38 say this you press Q to quit this 说这个你按 Q 退出这个
27:41 program it can be really hard to quit it 程序
27:43 if you do not know that a handy 如果你不知道这里有一个方便的键盘
keyboard
27:48 shortcut here by the way is ctrl L which 快捷键是 ctrl L,它
27:50 lets you clear your terminal and go 可以让你清除你的终端并返回
back
27:52 to the top so so far we've only talked 到 到目前为止,我们只讨论
27:56 about programs in isolation but where 了孤立的程序,但是
27:59 much of the power of the shell really shell 的大部分功能真正
28:01 comes through is once you start 发挥作用的地方是一旦你开始
28:03 combining different programs right so 正确组合不同的程序,而
28:06 rather than just like running CDE 不是像运行 CDE
28:08 running LS and etc you might want to 运行 LS 等你可能想要
28:10 chain multiple programs together you 链接多个 程序在一起你
28:12 might want to interact with files and 可能想与文件交互并
28:13 have files operate in between programs 让文件在程序之间运行,
28:15 and the way we can do this is using this 我们可以做到这一点的方法是使用
28:19 notion of streams that the shell gives 流的概念,shell
28:21 us every program by default has I'm 默认给我们每个程序都有我
28:24 gonna simplify a little and say two 要简化一点,说两个
28:25 primary streams it has an input stream 主要的 默认情况下,它有一个输入流
28:28 and an output stream by default the 和一个输出流 输入
about:blank 22/37
2023/4/19 11:14 For print

28:31 input stream is your keyboard basically 流就是你的键盘


28:33 the input stream is your terminal and 输入流就是你的终端,
28:35 whatever you type into your terminal is 无论你在终端中输入什么,它都会
28:36 going to end up into the program and it 最终进入程序,它
28:38 has a default output stream which is 有一个默认的输出流,无论
28:40 whenever the program prints 何时 该程序打印
something
28:42 it's gonna print to that stream and by 它要打印到该流的东西,
28:44 default that is also your terminal this 默认情况下这也是您的终端,这
28:46 is why when I type echo hello it gets 就是为什么当我键入 echo hello 时它会
28:48 printed back to my terminal but the 打印回我的终端但是
28:50 shell gives you a way to rewire these shell 为您提供了一种重新连接这些
28:54 streams to change where the input 流以更改输入
28:56 output of a programmer pointed the 输出位置的方法 程序员指出
way
28:59 the most straightforward way you do 最直接的方法
this
29:00 is using the angle bracket signs so you 是使用尖括号符号,这样你
29:06 can write something like this or you can 就可以写这样的东西,或者你可以
29:08 write something like this the left angle 这样写左尖
29:11 bracket indicates rewire the input for 括号表示将
29:14 this program to be the contents of this 这个程序的输入重新连接为这个程序的内容
29:16 file and the end angle bracket means file 和结束尖括号意味着将
29:21 rewire the output of the preceding 前面程序的输出重新连接
29:23 program into this file so let's look at 到这个文件中,所以让我们看
29:27 an example of what that would look like 一个例子,
29:28 if I do echo hello I can say I want that 如果我执行 echo hello,我可以说我希望将
29:32 context the content to be stored in a 上下文内容存储在一个
29:34 file called hello dot text and because I 名为的文件中 hello 点文本,因为我
29:36 gave this is a relative path right this 给了它一个相对路径,这
29:39 will construct a file in the current 将在当前目录中构建一个
29:40 directory called hello text and at least 名为 hello text 的文件,至少
29:42 in theory its contents should be the 在理论上它的内容应该是
29:45 word hello so if I run this notice that hello 这个词,所以如果我运行这个通知,我
的输出
29:47 nothing got printed to my output the 没有打印任何内容
29:50 previous time when I ran echo hello it 上次我运行 echo hello 时它

about:blank 23/37
2023/4/19 11:14 For print

29:52 printed hello 打印了 hello


29:52 now that hello is going gone into a file 现在 hello 进入了一个
29:55 called hello text and I can verify this 名为 hello text 的文件,我可以
29:57 by using the program called cat so cat 使用名为 cat 的程序验证这一点,因此 cat
30:00 prints the contents of a file so I can 打印文件的内容,这样我就可以
30:03 do cat hello dot txt and there it shows 执行 cat hello dot txt 在那里它向我展示了
30:07 me hello but cat is a is also something 你好但是 cat 也是一种
30:11 that supports this kind of wiring so I 支持这种接线的东西所以我
30:13 can say cat which by default just prints 可以说 cat 默认情况下只打印
30:16 its input it just duplicates its input 它的输入它只是将它的输入复制
30:17 to its output I can say I want you to 到它的输出我可以说我希望你
30:20 take your input from Hello text what 从中获取你的输入 Hello text
30:23 will happen in this case is that the 在这种情况下会发生什么是
30:25 shell is going to open hello dot txt shell 将打开 hello dot txt
30:26 take its contents and set that to be the 获取其内容并将其设置为
30:29 input of cat and then cat is going to cat 的输入,然后 cat 将
30:32 just print that to its output which 仅将其打印到其输出,
30:34 since I haven't rewired it is gonna be 因为我没有重新布线 它将成为
30:36 my terminal so this will just print 我的终端,所以这只会
30:38 hello to the output and I can use both 向输出打印 hello,我可以
30:41 of these at the same time so for 同时使用这两个,例如,
example
30:43 if I want to copy a file and I don't 如果我想复制一个文件,但
30:45 want to use the CP command for some 出于某种原因我不想使用 CP 命令
30:47 reason I can do this and in this case 我可以做到这一点,在这种情况下,
30:51 I'm telling the cat program nothing at 我什么也没告诉 cat 程序
30:54 all I'm just saying do your normal thing 我只是说做你正常的事情
30:56 right the cat program does not know cat 程序
30:58 anything about this redirection but I'm 对这个重定向一无所知,但我
30:59 telling the shell to use hello dot txt as 告诉 shell 使用 hello dot txt 作为
31:02 the input for cat and to write anything cat 的输入并写入
31:04 that cat prints - hello - dot txt again cat 打印的任何内容 - hello - dot txt 再次
31:08 this prints nothing to my terminal 这不会在我的终端上打印任何内容,
31:09 but if 但是如果
31:10 cat hello to text I get the output as I cat hello to text 我会得到我
31:13 would have expected which is a copy of 预期的输出,这是

about:blank 24/37
2023/4/19 11:14 For print

31:15 the original file there is also a double 原始文件的副本还有 一个双


31:20 end bracket which is append instead of 端括号,它是附加的而不是
31:23 just overwrite so you'll notice that I 只是覆盖所以你会注意到我
31:26 if I do 如果我再次执行
31:27 cat hello dot txt - hello - dot txt cat hello dot txt - hello - dot txt
31:29 again and then I cat hello2 dot txt it 然后我 cat hello2 dot txt 它
31:32 still just contains hello even though it 仍然只包含 hello 即使它
31:34 already contained hello if I switch that 已经包含 hello if 我将其切换
31:36 to instead be a double end bracket it 为双端括号,这
31:38 means append and if I now cat that file 意味着追加,如果我现在 cat 该文件,
31:41 it has a hello twice these are pretty 它有两次问候,这些非常
31:45 straightforward they're usually just 简单,它们通常只是
31:47 ways to interact with files but where it 与文件交互的方式,但
31:49 gets really interesting is an additional 真正有趣的是额外的
31:51 operator the shell gives you called the 运算符 shell 给你称为
31:53 pipe character so pipe is just a 管道字符,所以管道只是一个
31:56 vertical bar and what pipe means is 竖线,管道的意思是将
take
32:00 the output of the program to the left 程序的输出带到左边,
32:02 and make it the input of the program to 并将它作为程序的输入到
32:05 the right right so what does this look 右边,所以这看起来
32:09 like well let's take the example of ls / 像什么让我们来看看 ls /
32:13 or ls dash l / this prints a bunch of 或 ls dash l / 的示例打印了一堆
32:17 things let's say that I only wanted the 东西假设我只想要
32:19 last line of this output well there's a 此输出的最后一行,那么有一个
32:22 command called tail and tail prints the 名为 tail 的命令,tail 打印
32:25 last n lines of its input and I can do 其输入的最后 n 行,我可以
32:28 -n1 so this is a flag called n you 这样做 -n1 所以 这是一个名为 n 的标志,
32:32 can also use dash dash lines if you 如果你想
want
32:34 to use it as a longer option but in this 将它用作更长的选项,你也可以使用破折
号,但在这种
32:36 case this is saying just print the last 情况下,这只是说打印最后
32:38 line and I can wire these together so I 一行,我可以将它们连接在一起,所以我
32:42 can say ls dash l / pipe tail -n1 可以说 ls dash l / pipe tail -n1
32:46 and notice here that ls does not know 并注意这里 ls 不
32:50 about tail and tail does not know about 知道 tail 和 tail 不知道

about:blank 25/37
2023/4/19 11:14 For print

32:53 ls they are different programs and have ls 它们是不同的程序并且


32:55 never been programmed to be 从未被编程
compatible
32:56 with one another all they know how to 为彼此兼容它们所知道的只是
do
32:59 is read from input and write to output 从输入读取并写入输出
33:00 and then the pipe is what wires them 和 然后管道将它们连接
33:02 together and in this particular case I'm 在一起,在这种特殊情况下,我是
33:05 saying I want the output of LS to be the 说我希望 LS 的输出成为
33:07 input to tail and then I want the output tail 的输入,然后我希望
33:09 of tail to just go to my terminal tail 的输出直接转到我的终端,
33:10 because I haven't rewired it 因为我没有重新连接它
33:12 I could also rewire this to say I want 我也可以重新连接它,说我希望
33:14 the output to go to ls dot text and in this 输出转到 ls 点文本,在这种
33:16 case if I cat ls dot text I would get 情况下,如果我 cat ls 点文本,我会得到
33:18 the appropriate output and it turns out 适当的输出,事实证明
33:20 you can do some really neat things with 你可以做一些非常巧妙的事情,这
this
33:23 gonna cover this a lot more in the data 将覆盖这个 在数据
33:25 wrangling lecture there will be in like 争论讲座中会有更多内容大约
33:27 four days or something on the kind of 四天后会有一些关于
33:30 fancy stuff you can do when you start 当你开始构建更高级的管道时你可以做的奇
特的事情
33:32 building more advanced pipelines one -
to
33:36 give you one example we can do 给你一个例子我们可以做一些
something
33:37 like curl - -head --silent google.com 像 curl -- -head --silent 这样的事情
google.com
33:42 so just to show you what that looks 所以只是为了向您展示它的样子
33:46 like this gives me all the HTTP headers 这给了我访问 google.com 的所有 HTTP 标
头,
33:48 for accessing google.com and I can 我可以将
pipe
33:52 that to grep a - like a --ignore-case 其通过管道传递给 grep a - 比如 --ignore-
case
33:56 or just -i if I want content 或者只是 -i 如果我想要内容
34:01 length so this is gonna print the 长度 这将打印
34:04 content length header, grep is a 内容长度标头,grep 是一个
program
34:06 that we'll talk about later they'll let 我们稍后会讨论的程序,它们可以让
about:blank 26/37
2023/4/19 11:14 For print

34:07 you search in an input stream for a 您在输入流中搜索给


34:09 given keyword we can pipe that 定的关键字,我们可以通过
through
34:12 say the cut command which takes a 管道将其传递给带有定界符的 cut 命令,并

34:15 delimiter set that to be space and I 其设置为 是空格,我
34:20 want the second field and this prints 想要第二个字段,
34:22 just the content length this is sort of 它只打印内容长度这是
34:24 a silly example right like this just 一个愚蠢的例子,就像这样,
34:25 lets you extract the content length in 你可以从命令行中提取 google.com 的内容
长度(以
34:28 bytes of google.com from the command 字节为单位)
34:30 line it's not a very useful thing to do 这不是一件很有用的事情
34:32 but you can see how by chaining these 但是你可以看到如何通过将这些链接
34:34 together you can achieve a bunch of 在一起你可以实现一堆
34:36 really interesting text manipulation 非常有趣的文本操作
34:38 effects and it turns out pipes are not 效果而且事实证明管道不仅适用
34:40 just for textual data you can do this 于文本数据你可以
34:43 for things like images as well you can 为图像之类的东西这样做你也可以
34:45 have a program that manipulates a 有一个程序来操纵二进制文件
binary
34:47 image on its input and writes a binary 输入图像并将二进制
34:49 image to its output and you can chain 图像写入输出,您可以
34:51 them together in this way and we'll talk 通过这种方式将它们链接在一起,稍后我们

34:53 about some of those kinds of examples 讨论其中一些示例
34:54 later on - you can even do this for - 如果您愿意,您甚至可以对
34:57 video if you want you can stream this is 视频执行此操作您可以流式传输它
34:59 for example a great way if you have a 例如,如果你
35:00 chromecast at home you can stream a 家里有 chromecast,你可以
35:02 video file like this by having the last 通过将
35:05 program in your pipe be a chromecast 管道中的最后一个程序作为 chromecast
35:07 send program so you stream a video 发送程序来流式传输视频文件,这样你就可
file 以将视频文件流式传输
35:11 into it and it streams or HTTP to your 到它,它可以流式传输或通过 HTTP 传输到
你的
35:13 chromecast we'll take we'll talk a lot chromecast 我们会
35:19 more about this in the data wrangling 在数据争论讲座中对此进行更多讨论,
about:blank 27/37
2023/4/19 11:14 For print

35:20 lecture but there's one more thing that 但还有一件事


35:22 I wanted to talk to you about about sort 我想和你谈谈
35:25 of how to use the terminal and a more 如何使用终端以及一种更
35:27 interesting and perhaps more powerful 有趣、也许更强大的
35:30 way that you might be used to and this 方式,你 可能已经习惯了,
35:31 is perhaps even going to be interesting -
35:33 for the ones of you who feel like you're 对于那些觉得自己
35:35 already comfortable with the term 已经熟悉这个术语的人来说,这甚至可能会
很有趣,
35:37 but first we need to cover a important 但首先我们需要讨论一个重要的
35:41 topic when it comes to Linux systems 话题,特别是涉及 Linux 系统和
and
35:43 Mac OS systems in particular which is Mac OS 系统 这是
35:44 the notion of the root user the root root 用户的概念 root
35:47 user is sort of like the administrator 用户有点像
35:49 user on Windows and it has user IDs Windows 上的管理员用户,它的用户 ID 为
zero 零
35:52 the root user is special because it is root 用户是特殊的,因为它被
35:55 allowed to do whatever it wants on your 允许在你的系统上做任何它想做的事情,
35:56 system even if a file is like not 即使一个文件不是
35:59 readable by anyone or if it's not 任何人都可以读取,或者如果它不能
36:01 writable by anyone root can still access 被任何人写入,根仍然
36:03 that file root is sort of a super user -
36:06 that gets to do whatever they want and -
36:09 most of the time you will not be -
36:11 operating as the super user you will not 可以访问该文件
36:13 be root you will be a user like John or 将是像 John 这样的用户或
36:15 whatever your name is and that's going 无论您叫什么名字,这将
36:17 to be the user you act with because if 是与您一起行动的用户,因为如果
36:19 you were operating your computer as 您
the
36:21 root user at all times if you ran the 始终以 root 用户身份操作计算机,如果您运
行了
36:23 wrong program they could just 错误的程序,他们可能会完全
completely
36:24 destroy your computer and you don't 毁掉您的计算机,而您 不想要
want
36:26 that right but every now and again you 那样做,但有时你
36:29 want to do something that requires that 想做一些需要

about:blank 28/37
2023/4/19 11:14 For print

36:31 you are root usually for these cases 你是 root 的事情,通常在这些情况下你
you
36:34 will use a program called sudo su do or 会使用一个名为 sudo su do 或
36:38 do as su and su in this case is Super su 的程序,而 su 在这种情况下是超级
36:42 User so this is a way to do the 用户,所以这是 作为
36:44 following thing as the super user 超级用户执行以下操作的一种方法
36:46 usually the way sudo works is you write 通常 sudo 的工作方式是编写
36:49 sudo and then a command like you sudo,然后像您
would
36:51 normally on your terminal and it will 通常在终端上执行的命令一样
36:53 just run that command as if you were 运行该命令,就好像您是
36:54 root as opposed to the user you root 用户而不是您实际的用户
actually
36:56 are where might you need something 你可能在哪里需要这样的东西
like
37:01 this well there is a special there are 有一个特殊的
37:04 many special file system on your 在你的计算机上有许多特殊的文件系统
37:05 computer but in particular there's one 但特别是有一个
37:07 called sysfs if you CD to slash sys 叫做 sysfs 如果你 CD 斜线系统
37:11 this is a whole new world this file 这是一个全新的世界 这个文件
37:14 system is are not actually files on your 系统实际上不是文件 你的
37:17 computer instead these are various 计算机而不是这些是各种
37:19 kernel parameters so the kernel is like 内核参数所以内核
37:22 basically the the core of your computer 基本上就像你计算机的核心
37:24 this is a way for you to access various 这是一种让你通过
37:26 kernel parameters through what looks 看起来
37:29 like a file system you'll see here that 像文件系统的东西访问各种内核参数的方法
你会在这里看到
37:32 if I CD into class for example it has 如果我CD进入课堂 例如,它有
37:35 directories for a bunch of different 一堆不同
37:37 types of devices that I can interact 类型的设备的目录,我可以
37:39 with or various queues I can access or 与之交互或我可以访问的各种队列或
all
37:43 sorts of weird knobs internally and 内部各种奇怪的旋钮,
37:47 because they're exposed as files it 因为它们作为文件公开,这意味着
means
37:50 we can also use all the tools have been 我们也可以使用所有工具一直在
37:52 using so far in order to manipulate 使用 到目前为止,为了操纵它们,
them

about:blank 29/37
2023/4/19 11:14 For print

37:54 one example of this is if you go into 一个例子是如果你进入


37:57 sys class backlight so this backlight sys 类背光,那么这个背光
38:01 directly and lets you configure the 直接让你
38:02 backlight on your laptop if you have 在你的笔记本电脑上配置背光,如果你有这
one 样
38:04 so I can CD in to intel backlight this 我可以 CD 进入英特尔背光,这
38:06 is an Intel laptop inside here you'll 是一个英特尔笔记本电脑里面 在这里你会
38:08 see there's a file called brightness and 看到有一个名为 brightness 的文件,
38:10 I can cat the brightness this is the 我可以捕捉亮度这是
38:12 current brightness of my screen but not 我屏幕的当前亮度但
38:16 only that I can modify this too in order 不仅如此我也可以修改它
38:18 to change the brightness of my screen 以改变我的屏幕亮度所以
so
38:21 you might think that I could do let's 你可能认为我可以做 让我们
38:23 see what the max brightness is here 看看这里的最大亮度是多少,
okay
38:25 so it's currently set to the max 所以它当前设置为您
38:26 brightness you might imagine that I 可能想象的最大亮度我
38:29 could do something like if I do echo 可以做一些事情,比如如果我回声让我们
38:32 let's do half or something 做一半或者
38:35 echo 500 to brightness 回声 500 到亮度
38:38 if I do this it says 如果我这样做它说
38:39 permission denied I'm not allowed to 权限被拒绝我是 不允许
38:40 modify brightness because in order to 修改亮度,因为
38:43 basically in order to change things in 基本上为了更改内核中的内容,
38:45 the kernel you need to be the 您需要成为
38:46 administrator and you might imagine 管理员,您可能会想
that
38:48 the way to solve this is to write sudo 解决这个问题的方法是编写 sudo
38:50 echo 500 but I still get a permission echo 500 但我仍然收到权限
38:52 denied error but why is that it's 被拒绝的错误,但为什么 是因为
38:55 because as I mentioned before these 正如我之前提到的,
38:58 redirections of input and output is not -
39:00 something the programs know about 当
when
39:03 we piped Elison to tail tail did not 我们将 Elison 通过管道传输到 tail tail 时,
程序不知道这些输入和输出的重定向 tail 不
39:05 know about LS and LS did not know 知道 LS,而 LS 不知道
about
about:blank 30/37
2023/4/19 11:14 For print

39:07 tail the pipe and the redirection was tail 管道,并且重定向是由
39:09 set up by the shell so in this case shell 所以在这种情况下
39:11 what's happening is I'm telling my shell 发生的事情是我告诉我的 shell
39:14 run the program sudo with the 使用参数
arguments
39:18 echo and 500 and send its output to the echo 和 500 运行程序 sudo 并将其输出发送

39:21 file called brightness but the shell is 名为 brightness 的文件但是 shell
39:24 what is opening the brightness file it 正在打开亮度文件它
39:25 is not the sudo program so in this case 不是 sudo 程序所以 在这种情况下,当
39:29 the shell which is running as me tries 我尝试
39:32 to open the brightness file for writing 打开亮度文件进行写入时正在运行的 shell
39:33 and it's not allowed to do that and 不允许这样做,
39:35 therefore I get a permission down error 因此我得到了一个权限关闭错误,
39:37 you might have seen this if you like 如果你喜欢
39:39 search for something end up on Stack 搜索最终出现在 Stack Overflow 上的东西,
你可能已经看到了这个
39:42 Overflow and it tells just run this 它告诉你只要运行这个
39:43 command and you'll see that it does 命令,你就会看到它做了
39:45 something like they give you 一些事情,比如他们给你一些
39:47 instructions like one two sis what's an 指令,比如 one two sis what's an
39:52 example net ipv4 for word for example example net ipv4 for word 例如,
39:57 this is something you may have seen if 如果
39:59 you're setting up a firewall and this 你正在设置防火墙,你可能已经看到了这个
40:02 command is intended to work 命令旨在工作,
40:04 because this little pound symbol 因为这个小英镑符号
40:05 indicates run this as root this is 表示以 root 身份运行,这是
40:08 something that is very rarely explained 很少解释的事情,
40:09 but that is what the pound symbol 但这就是英镑符号的意思,
means
40:11 you'll see on my prompt there's a dollar 你会在我的提示中看到一个美元
40:12 symbol instead and the dollar indicates 符号,而美元表示
40:15 you are not running as root so the 你不是 以 root 身份运行,所以
40:17 question is how do I get around this 问题是我如何
40:18 well I could switch into a root terminal 很好地解决这个问题我可以切换到 root 终端
40:22 so one way to do this is to run sudo su 所以一种方法是运行 sudo su
40:24 sudo su is saying run the following sudo su 说运行以下

about:blank 31/37
2023/4/19 11:14 For print

40:27 command s root and su is a 命令 s root 和 su 是一个复杂的


complicated
40:32 command that effectively gets you a 命令,有效地 给你一个
40:34 shell as the super user so if I do this 超级用户的 shell 所以如果我输入这种
40:37 type of password then now you'll see 类型的密码那么现在你会看到
40:40 that the username at the beginning 开始时的用户名
40:42 changed from jon to root and the 从 jon 变成了 root 并且提示
prompt
40:44 changed from a dollar to a pound if I 从一美元变成了一磅如果我
40:47 now I come in to that file if I do echo 现在进入 那个文件如果我回显
40:49 500 to brightness my screen got a little 500 到亮度我的屏幕变暗了一点
40:52 dimmer but you can't see it you just 但是你看不到它你只
40:54 have to trust me and now I didn't get an 需要相信我现在我没有收到
40:57 error and this is because the shell is 错误这是因为 shell
40:58 now running as root it is not running as 现在以 root 身份运行它是 不是以
41:01 Jon and the root user is allowed to Jon 身份运行,root 用户被允许打开
open
41:04 this file but given our knowledge that 这个文件,但鉴于我们知道
41:07 we have of the terminal now there's 我们拥有终端,现在
41:09 actually a way for us to do this without 实际上我们有一种方法可以做到这一点,
41:11 having to drop to a root shell and that 而不必进入 root shell,
41:13 is as follows that's I guess restore it 我猜如下 将它恢复
41:19 to 1060 so do you see why this is 到 1060 那么你明白为什么这
41:22 different here I'm telling my shell to 在这里不同吗 我告诉我的 shell
41:26 run the echo 1060 command which is 运行 echo 1060 命令这将回
gonna
41:29 echo 1060 and I'm telling it to run the 显 1060 我告诉它运行
41:31 sudo tee brightness command and I'm sudo tee brightness 命令并且我
41:33 telling you to send the output of echo 告诉你 将 echo 的输出发送
41:35 into sudo tee in order to understand 到 sudo tee 为了理解这一点
this
41:39 you need to know what the tee 你需要知道 tee 命令做什么
command does
41:40 the tee command takes its input and -
writes
41:43 it to a file but also to standard out so -
41:47 tee is a convenient way if you have say -
a
41:49 log file that you want to like send to a 您想要发送到
41:52 file to store for later but you also 文件以供以后存储的日志文件,但您也
about:blank 32/37
2023/4/19 11:14 For print

41:54 want to see it to yourself then you can 想自己查看它然后您可以


41:56 pipe it through tee give it the name of a 通过 tee 将其通过管道传递给它一个文件的
名称
41:58 file and it will write whatever its ,它会将其输入的任何内容写入
41:59 input is both to that file and to your 该文件 在你的
42:01 screen and here I'm taking advantage 屏幕上,我正在利用
of
42:04 that program I'm saying run tee as 那个程序,我说的是将 tee 作为路由运行,
route
42:07 and have tee right into the brightness 并将 tee 直接放入亮度
42:09 file and so in this case the tee program 文件中,所以在这种情况下,
42:12 which is what is opening the brightness 打开亮度
42:14 file is running as root and so it is 文件的 tee 程序以 root 身份运行 因此,
42:16 allowed to do -
42:17 if I run this it will now again you 如果我运行它,它是允许的
42:20 can't see but the brightness and I've -
42:21 been turned on by a laptop and I don't -
42:23 get any errors and I never had to drop -
42:25 into a root shell and run commands shell 并在那里运行命令,
there
42:27 which can often be somewhat 如果
dangerous if
42:30 you want to explore this filesystem a 您想更多地探索这个文件系统,这通常会有
些危险这里
42:32 little bit more there's a lot of 有很多
42:33 interesting stuff in here if you just 有趣的东西如果您只是
42:35 sort of start browsing around you can 开始四处浏览,您会
42:39 find all sorts of fun things so for 发现各种有趣的东西,
42:41 example we noticed that there was a 例如我们 注意到这里有一个有趣的
fun
42:42 brightness command here I wonder 亮度命令 我想知道
what
42:45 other kinds of brightness I can set so I 我可以设置哪些其他类型的亮度以便我
42:48 can use the find command which we 可以使用 find 命令,我们还将
will
42:49 also talk about in a coming lecture I 在接下来的讲座中讨论我
42:51 wouldn't look on any file whose name 不会查看名称有点像的任何文件
42:56 it's a little like brightness in the -
42:58 current directory that's unhelpful maybe 当前目录中的亮度没有帮助也许
43:01 they're not files did I misspell 它们不是文件我拼错了

about:blank 33/37
2023/4/19 11:14 For print

43:05 brightness yeah why is it being 亮度是的为什么它很烦人


annoying
43:08 Oh apparently it does not want to 哦显然它不想
search
43:17 for brightness for me how well luckily 为我搜索亮度多么幸运
43:20 for you I know of one already handy 你我知道一个已经很方便有
that
43:23 there is a subdirectory called LEDs and 称为 LED 的子目录和
43:27 LEDs have brightness too what kind of LED 也有亮度 那里有什么样的
43:30 LEDs are there ooh lots of things for LED 哦,很多东西,
43:32 example the scroll lock led now most of 例如滚动锁 LED 现在你们大多数人
43:36 you probably don't know what the scroll 可能不知道滚动
43:38 lock LED is or much less what scroll 锁 LED 是什么,或者更不用说
43:40 lock is you might have seen a key on 您可能已经看到了什么滚动锁 键盘邻居上的
一个键
43:42 your keyboard neighbor named scroll 名为 scroll lock
lock
43:45 basically no one knows what it means 基本上没有人知道它意味着什么,
43:47 anymore no one really uses it for 没有人真正将它用于
43:49 anything it's mostly just a dead key and 任何事情它主要只是一个死键和
43:51 also a dead LED what if you wanted to 一个死 LED 如果你想
43:55 configure it so that every time you get 配置它,以便每次收到
43:57 email your scroll lock LED lights up 电子邮件时你 scroll lock LED 亮起是
43:59 because there's no other reason why it 因为
44:00 would light up well if we seed you into 如果我们将您播种到
44:03 this particular directory that has a 这个具有
44:06 brightness place and it's set to zero 亮度位置的特定目录并且它设置为零,那么
没有其他原因为什么它会很好地亮起
44:08 well what happens if I write one into it 如果我将一个写入其中会发生什么
44:12 you probably should not just be writing 你可能不应该只是写 将
44:15 random numbers into random files in 随机数放入此目录中的随机文件中,
this
44:17 directory because you are affecting 因为您
your
44:18 kernel directly like look up what the 直接影响内核,例如查找
44:20 files do in this particular case I have 文件在这种特殊情况
44:22 warned safety goggles and I've done -
my
44:24 research so now you can't tell but on 下的作用
my

about:blank 34/37
2023/4/19 11:14 For print

44:28 keyboard the scroll lock LED is now lit scroll lock LED 现在亮了,
44:30 so now if I wrote a program that like 所以现在如果我写了一个程序来
44:33 did some checking of mail and stuff I 检查邮件和其他东西,我
44:35 could have it at the end run a program 可以在最后运行一个程序,将
44:37 that echoes one into this file and now I 一个回显到这个文件中,现在我
44:40 have a way for my led to my keyboard 有办法让我的 led 到我的键盘 为了
to
44:43 indicate when I've new email at this 表明此时我何时收到新电子邮件,
44:47 point you should know roughly your 您应该大致了解
way
44:49 around -
44:50 the terminal around the shell and and 终端周围的外壳,并且至少在理论上
44:54 know enough to accomplish these 知道足以完成这些基本
basic
44:56 tasks at least in theory now you 任务现在您
44:58 shouldn't need to use like 不需要像
45:01 point-and-click interfaces to find files 点击一样使用 接口来查找文件
45:02 anymore -
45:03 there's one remaining trick you might 你可能还需要一个技巧,
45:05 need and that is the ability to open a 那就是打开
45:07 file so far I've only really given you 文件的能力 到目前为止,我只真正给了你
45:10 ways to find files but one thing you 查找文件的方法,但你
45:13 should know about is missing semester 应该知道的一件事是缺少学期
45:17 xdg-open this will probably only work xdg-open 这可能会 仅适用
45:21 on Linux on Mac OS I think it's just 于 Mac OS 上的 Linux 我认为它只是在
45:23 called open on Windows who knows 知道 xdg-open 的 Windows 上称为 open
45:27 xdg-open you give the name of a file 你给出文件的名称并且
and
45:29 it will open it in the appropriate program 它会在适当的程序中打开它
45:31 so if you open if you do xdg-open an 所以如果你打开 xdg-open 一个
45:34 HTML file that will open your browser HTML 文件 将打开您的浏览器
45:36 and open that file and once you have 并打开该文件,一旦您拥有
45:39 that program in theory you should no 该程序,理论上您将
45:41 longer need to open like a Finder 不再需要像 Finder 窗口一样打开
window
45:42 ever again you might want to for other 您可能出于其他原因想要再次打开,
45:45 reasons but in theory you can 但理论上您可以
accomplish
45:46 at all using the tools that we've 使用我们提供的工具来完成
about:blank 35/37
2023/4/19 11:14 For print

45:48 learned today this might all seem 今天我们学到了这对


45:50 relatively basic for some of you but as 你们中的一些人来说似乎都是相对基础的,
但正如
45:53 I mentioned this is sort of the ramp-up 我提到的,这是
45:55 period of now we all know how the shell 现在我们都知道 shell 是如何
45:57 works and a lot of what we'll be doing 工作的,我们
45:59 in future lectures is using this 在未来的讲座中将做的很多事情都是使用 这

46:01 knowledge to do really interesting 知识可以使用 shell 做一些非常有趣的
46:03 things using the shell that sort of this 事情,比如
46:07 is learning the the interface that we're 学习我们将要
46:09 going to be using and so it's important 使用的界面,所以
46:10 we all know it we're gonna talk a lot 我们都知道这一点很重要,我们将
46:14 more in the next lecture about how to 在下一节课中详细讨论如何
46:16 automate tasks like this how to write 自动执行这样的任务 如何编写
46:18 scripts that run a bunch of programs for 脚本来为您运行一堆程序,
46:20 you and have to do things like 并且必须
46:22 conditionals and loops and stuff in your 在您的终端中执行诸如条件和循环之类的操

46:24 terminal and do things like run a 以及执行诸如运行
46:26 program until it fails which can be 程序直到失败的操作,这
46:29 handy in classes where you want to run 在您想要的类中很方便 运行
46:30 something until your test suite fails 一些东西直到你的测试套件失败,
46:31 for example so that's the topic for next 例如,这就是
46:35 week's lecture did you have a question 下周讲座的主题,你有什么问题吗?
46:38 it's what you've been demoing this 你一直在演示这个
46:39 assist directory that presumably will 辅助目录,大概
46:42 only work if you're running that is a 只有在你运行时才会工作,这是一个
46:49 good question I don't know whether the 很好的问题,我不知道' 不知道
46:52 windows subsystem for Linux will Linux 的 Windows 子系统是否会暴露
expose
46:55 the sis file system if it does it sis 文件系统,如果它暴露的话,它
46:57 probably only exposes a very small 可能只会暴露极少数
46:59 number of things it might because there 的东西,因为
47:03 are I don't know check it out 我不知道检查它,
47:08 one thing you'll see is the lecture 你会看到的一件事是讲义
47:10 notes for this lecture are already 这个讲座已经

about:blank 36/37
2023/4/19 11:14 For print

47:11 online and at the very bottom of the 在线,在文件的最底部


47:14 file there are a bunch of exercises 有一堆练习,其中一些
some
47:16 of them are relatively easy some of 相对容易一些,有些则
them
47:18 are a little bit harder and what we 有点难,我们
47:20 encourage you to do is to take a stab at 鼓励你做的是尝试
47:22 going through them if you know this 通过它们 如果你已经知道这些
47:24 stuff already it should go really 东西,它应该很快就会过去,
47:25 quickly if you don't it might teach you 如果你不这样做,它可能会教给你
47:27 a bunch of things that you might not 很多你可能没有
47:29 realize you didn't know and for the 意识到你不知道的东西,并且在
47:31 office hours that we're gonna do right 我们将在
47:33 after this lecture we will happily help 本次讲座后立即进行的办公时间内,我们 会
很乐意帮助
47:35 you get through all of those or if there 你完成所有这些,或者如果
47:36 are other commands and you learn in 还有其他命令,你会在这个过程中学习
the
47:38 process you want to know how to use 你想知道如何更
more
47:39 efficiently and then in next lecture 有效地使用,然后在明天的下一堂课中
47:42 which is tomorrow will basically be 基本上会
47:44 assuming that you know the kind of 假设你知道那种东西
stuff
47:46 that the exercise is going to teach you 这个练习会告诉你网站
47:48 there's also a an email address on the 上还有一个电子邮件地址,
47:51 website where you can send us -
questions
47:53 if you think of something like after the 如果你想到什么,比如在
47:56 office hours are finished are there any 办公时间结束后,你可以向我们发送问题,

47:58 questions before we end today no no 我们今天结束之前有任何问题吗?不,
all
48:05 right well we will have office hours on 好的,我们会有 办公时间在
48:07 the ninth floor of the gates building of gates building of
48:09 building 32 in like five minutes building 32 五分钟后
48:12 sweet see you there sweet see you there

about:blank 37/37

You might also like