Lecture1 - The Shell
Lecture1 - The Shell
about:blank 1/37
2023/4/19 11:14 For print
about:blank 4/37
2023/4/19 11:14 For print
about:blank 6/37
2023/4/19 11:14 For print
about:blank 7/37
2023/4/19 11:14 For print
about:blank 8/37
2023/4/19 11:14 For print
about:blank 9/37
2023/4/19 11:14 For print
about:blank 10/37
2023/4/19 11:14 For print
about:blank 11/37
2023/4/19 11:14 For print
about:blank 18/37
2023/4/19 11:14 For print
about:blank 19/37
2023/4/19 11:14 For print
about:blank 20/37
2023/4/19 11:14 For print
about:blank 21/37
2023/4/19 11:14 For print
about:blank 23/37
2023/4/19 11:14 For print
about:blank 24/37
2023/4/19 11:14 For print
about:blank 25/37
2023/4/19 11:14 For print
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
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
about:blank 33/37
2023/4/19 11:14 For print
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
about:blank 36/37
2023/4/19 11:14 For print
about:blank 37/37