mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-24 02:20:09 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
f50ac73a36
published
sources/tech
20180716 Users, Groups and Other Linux Beasts- Part 2.md20181206 Take a break at the Linux command line with Nyan Cat.md20181222 Watch YouTube videos at the Linux terminal.md20181224 An Introduction to Go.md20181224 Turn GNOME to Heaven With These 23 GNOME Extensions.md20181226 -Review- Polo File Manager in Linux.md
translated/tech
@ -1,4 +1,4 @@
|
||||
实验 5:文件系统、Spawn 和 Shell
|
||||
Caffeinated 6.828:实验 5:文件系统、Spawn 和 Shell
|
||||
======
|
||||
|
||||
### 简介
|
||||
@ -10,31 +10,31 @@
|
||||
使用 Git 去获取最新版的课程仓库,然后创建一个命名为 `lab5` 的本地分支,去跟踪远程的 `origin/lab5` 分支:
|
||||
|
||||
```
|
||||
athena% cd ~/6.828/lab
|
||||
athena% add git
|
||||
athena% git pull
|
||||
Already up-to-date.
|
||||
athena% git checkout -b lab5 origin/lab5
|
||||
Branch lab5 set up to track remote branch refs/remotes/origin/lab5.
|
||||
Switched to a new branch "lab5"
|
||||
athena% git merge lab4
|
||||
Merge made by recursive.
|
||||
.....
|
||||
athena%
|
||||
athena% cd ~/6.828/lab
|
||||
athena% add git
|
||||
athena% git pull
|
||||
Already up-to-date.
|
||||
athena% git checkout -b lab5 origin/lab5
|
||||
Branch lab5 set up to track remote branch refs/remotes/origin/lab5.
|
||||
Switched to a new branch "lab5"
|
||||
athena% git merge lab4
|
||||
Merge made by recursive.
|
||||
.....
|
||||
athena%
|
||||
```
|
||||
|
||||
在实验中这一部分的主要新组件是文件系统环境,它位于新的 `fs` 目录下。通过检查这个目录中的所有文件,我们来看一下新的文件都有什么。另外,在 `user` 和 `lib` 目录下还有一些文件系统相关的源文件。
|
||||
|
||||
fs/fs.c 维护文件系统在磁盘上结构的代码
|
||||
fs/bc.c 构建在我们的用户级页故障处理功能之上的一个简单的块缓存
|
||||
fs/ide.c 极简的基于 PIO(非中断驱动的)IDE 驱动程序代码
|
||||
fs/serv.c 使用文件系统 IPC 与客户端环境交互的文件系统服务器
|
||||
lib/fd.c 实现一个常见的类 UNIX 的文件描述符接口的代码
|
||||
lib/file.c 磁盘上文件类型的驱动,实现为一个文件系统 IPC 客户端
|
||||
lib/console.c 控制台输入/输出文件类型的驱动
|
||||
lib/spawn.c spawn 库调用的框架代码
|
||||
- `fs/fs.c` 维护文件系统在磁盘上结构的代码
|
||||
- `fs/bc.c` 构建在我们的用户级页故障处理功能之上的一个简单的块缓存
|
||||
- `fs/ide.c` 极简的基于 PIO(非中断驱动的)IDE 驱动程序代码
|
||||
- `fs/serv.c` 使用文件系统 IPC 与客户端环境交互的文件系统服务器
|
||||
- `lib/fd.c` 实现一个常见的类 UNIX 的文件描述符接口的代码
|
||||
- `lib/file.c` 磁盘上文件类型的驱动,实现为一个文件系统 IPC 客户端
|
||||
- `lib/console.c` 控制台输入/输出文件类型的驱动
|
||||
- `lib/spawn.c` spawn 库调用的框架代码
|
||||
|
||||
你应该再次去运行 `pingpong`、`primes`、和 `forktree`,测试实验 4 完成后合并到新的实验 5 中的代码能否正确运行。你还需要在 `kern/init.c` 中注释掉 `ENV_CREATE(fs_fs)` 行,因为 `fs/fs.c` 将尝试去做一些 I/O,而 JOS 到目前为止还不具备该功能。同样,在 `lib/exit.c` 中临时注释掉对 `close_all()` 的调用;这个函数将调用你在本实验后面部分去实现的子程序,如果现在去调用,它将导致 JOS 内核崩溃。如果你的实验 4 的代码没有任何 bug,将很完美地通过这个测试。在它们都能正常工作之前是不能继续后续实验的。在你开始做练习 1 时,不要忘记去取消这些行上的注释。
|
||||
你应该再次去运行 `pingpong`、`primes` 和 `forktree`,测试实验 4 完成后合并到新的实验 5 中的代码能否正确运行。你还需要在 `kern/init.c` 中注释掉 `ENV_CREATE(fs_fs)` 行,因为 `fs/fs.c` 将尝试去做一些 I/O,而 JOS 到目前为止还不具备该功能。同样,在 `lib/exit.c` 中临时注释掉对 `close_all()` 的调用;这个函数将调用你在本实验后面部分去实现的子程序,如果现在去调用,它将导致 JOS 内核崩溃。如果你的实验 4 的代码没有任何 bug,将很完美地通过这个测试。在它们都能正常工作之前是不能继续后续实验的。在你开始做练习 1 时,不要忘记去取消这些行上的注释。
|
||||
|
||||
如果它们不能正常工作,使用 `git diff lab4` 去重新评估所有的变更,确保你在实验 4(及以前)所写的代码在本实验中没有丢失。确保实验 4 仍然能正常工作。
|
||||
|
||||
@ -44,11 +44,11 @@ lib/spawn.c spawn 库调用的框架代码
|
||||
|
||||
### 文件系统的雏形
|
||||
|
||||
你将要使用的文件系统比起大多数“真正的”文件系统(包括 xv6 UNIX 的文件系统)要简单的多,但它也是很强大的,足够去提供基本的特性:创建、读取、写入、和删除组织在层次目录结构中的文件。
|
||||
你将要使用的文件系统比起大多数“真正的”文件系统(包括 xv6 UNIX 的文件系统)要简单的多,但它也是很强大的,足够去提供基本的特性:创建、读取、写入和删除组织在层次目录结构中的文件。
|
||||
|
||||
到目前为止,我们开发的是一个单用户操作系统,它提供足够的保护并能去捕获 bug,但它还不能在多个不可信用户之间提供保护。因此,我们的文件系统还不支持 UNIX 的所有者或权限的概念。我们的文件系统目前也不支持硬链接、时间戳、或像大多数 UNIX 文件系统实现的那些特殊的设备文件。
|
||||
|
||||
### 磁盘上文件系统结构
|
||||
### 磁盘上的文件系统结构
|
||||
|
||||
主流的 UNIX 文件系统将可用磁盘空间分为两种主要的区域类型:节点区域和数据区域。UNIX 文件系统在文件系统中为每个文件分配一个节点;一个文件的节点保存了这个文件重要的元数据,比如它的 `stat` 属性和指向数据块的指针。数据区域被分为更大的(一般是 8 KB 或更大)数据块,它在文件系统中存储文件数据和目录元数据。目录条目包含文件名字和指向到节点的指针;如果文件系统中的多个目录条目指向到那个文件的节点上,则称该文件是硬链接的。由于我们的文件系统不支持硬链接,所以我们不需要这种间接的级别,并且因此可以更方便简化:我们的文件系统将压根就不使用节点,而是简单地将文件的(或子目录的)所有元数据保存在描述那个文件的(唯一的)目录条目中。
|
||||
|
||||
@ -71,6 +71,7 @@ UNIX xv6 文件系统使用 512 字节大小的块,与它底层磁盘的扇区
|
||||
#### 文件元数据
|
||||
|
||||
![File structure][2]
|
||||
|
||||
元数据的布局是描述在我们的文件系统中的一个文件中,这个文件就是 `inc/fs.h` 中的 `struct File`。元数据包含文件的名字、大小、类型(普通文件还是目录)、指向构成这个文件的块的指针。正如前面所提到的,我们的文件系统中并没有节点,因此元数据是保存在磁盘上的一个目录条目中,而不是像大多数“真正的”文件系统那样保存在节点中。为简单起见,我们将使用 `File` 这一个结构去表示文件元数据,因为它要同时出现在磁盘上和内存中。
|
||||
|
||||
在 `struct File` 中的数组 `f_direct` 包含一个保存文件的前 10 个块(`NDIRECT`)的块编号的空间,我们称之为文件的直接块。对于最大 `10*4096 = 40KB` 的小文件,这意味着这个文件的所有块的块编号将全部直接保存在结构 `File` 中,但是,对于超过 40 KB 大小的文件,我们需要一个地方去保存文件剩余的块编号。所以我们分配一个额外的磁盘块,我们称之为文件的间接块,由它去保存最多 4096/4 = 1024 个额外的块编号。因此,我们的文件系统最多允许有 1034 个块,或者说不能超过 4MB 大小。为支持大文件,“真正的”文件系统一般都支持两个或三个间接块。
|
||||
@ -91,33 +92,28 @@ UNIX xv6 文件系统使用 512 字节大小的块,与它底层磁盘的扇区
|
||||
|
||||
只要我们依赖轮询、基于 “编程的 I/O”(PIO)的磁盘访问,并且不使用磁盘中断,那么在用户空间中实现磁盘访问还是很容易的。也可以去实现由中断驱动的设备驱动程序(比如像 L3 和 L4 内核就是这么做的),但这样做的话,内核必须接收设备中断并将它派发到相应的用户模式环境上,这样实现的难度会更大。
|
||||
|
||||
x86 处理器在 EFLAGS 寄存器中使用 IOPL 位去确定保护模式中的代码是否允许执行特定的设备 I/O 指令,比如 `IN` 和 `OUT` 指令。由于我们需要的所有 IDE 磁盘寄存器都位于 x86 的 I/O 空间中而不是映射在内存中,所以,为了允许文件系统去访问这些寄存器,我们需要做的唯一的事情便是授予文件系统环境“I/O 权限”。实际上,在 EFLAGS 寄存器的 IOPL 位上规定,内核使用一个简单的“要么全都能访问、要么全都不能访问”的方法来控制用户模式中的代码能否访问 I/O 空间。在我们的案例中,我们希望文件系统环境能够去访问 I/O 空间,但我们又希望任何其它的环境完全不能访问 I/O 空间。
|
||||
x86 处理器在 EFLAGS 寄存器中使用 IOPL 位去确定保护模式中的代码是否允许执行特定的设备 I/O 指令,比如 `IN` 和 `OUT` 指令。由于我们需要的所有 IDE 磁盘寄存器都位于 x86 的 I/O 空间中而不是映射在内存中,所以,为了允许文件系统去访问这些寄存器,我们需要做的唯一的事情便是授予文件系统环境“I/O 权限”。实际上,在 EFLAGS 寄存器的 IOPL 位上规定,内核使用一个简单的“要么全都能访问、要么全都不能访问”的方法来控制用户模式中的代码能否访问 I/O 空间。在我们的案例中,我们希望文件系统环境能够去访问 I/O 空间,但我们又希望任何其它的环境完全不能访问 I/O 空间。
|
||||
|
||||
```markdown
|
||||
练习 1、`i386_init` 通过将类型 `ENV_TYPE_FS` 传递给你的环境创建函数 `env_create` 来识别文件系统。修改 `env.c` 中的 `env_create` ,以便于它只授予文件系统环境 I/O 的权限,而不授予任何其它环境 I/O 的权限。
|
||||
> **练习 1**、`i386_init` 通过将类型 `ENV_TYPE_FS` 传递给你的环境创建函数 `env_create` 来识别文件系统。修改 `env.c` 中的 `env_create` ,以便于它只授予文件系统环境 I/O 的权限,而不授予任何其它环境 I/O 的权限。
|
||||
|
||||
确保你能启动这个文件系统环境,而不会产生一般保护故障。你应该要通过在 `make grade` 中的 "fs i/o" 测试。
|
||||
```
|
||||
> 确保你能启动这个文件系统环境,而不会产生一般保护故障。你应该要通过在 `make grade` 中的 "fs i/o" 测试。
|
||||
|
||||
```markdown
|
||||
问题
|
||||
|
||||
1、当你从一个环境切换到另一个环境时,你是否需要做一些操作来确保 I/O 权限设置能被保存和正确地恢复?为什么?
|
||||
```
|
||||
.
|
||||
|
||||
> **问题 1**、当你从一个环境切换到另一个环境时,你是否需要做一些操作来确保 I/O 权限设置能被保存和正确地恢复?为什么?
|
||||
|
||||
注意本实验中的 `GNUmakefile` 文件,它用于设置 QEMU 去使用文件 `obj/kern/kernel.img` 作为磁盘 0 的镜像(一般情况下表示 DOS 或 Windows 中的 “C 盘”),以及使用(新)文件 `obj/fs/fs.img` 作为磁盘 1 的镜像(”D 盘“)。在本实验中,我们的文件系统应该仅与磁盘 1 有交互;而磁盘 0 仅用于去引导内核。如果你想去恢复其中一个有某些错误的磁盘镜像,你可以通过输入如下的命令,去重置它们到最初的、”崭新的“版本:
|
||||
|
||||
```
|
||||
$ rm obj/kern/kernel.img obj/fs/fs.img
|
||||
$ make
|
||||
$ rm obj/kern/kernel.img obj/fs/fs.img
|
||||
$ make
|
||||
```
|
||||
|
||||
或者:
|
||||
|
||||
```
|
||||
$ make clean
|
||||
$ make
|
||||
$ make clean
|
||||
$ make
|
||||
```
|
||||
|
||||
小挑战!实现中断驱动的 IDE 磁盘访问,既可以使用也可以不使用 DMA 模式。由你来决定是否将设备驱动移植进内核中、还是与文件系统一样保留在用户空间中、甚至是将它移植到一个它自己的的单独的环境中(如果你真的想了解微内核的本质的话)。
|
||||
@ -132,45 +128,39 @@ x86 处理器在 EFLAGS 寄存器中使用 IOPL 位去确定保护模式中的
|
||||
|
||||
当然,将整个磁盘读入到内存中需要很长时间,因此,我们将它实现成”按需“分页的形式,那样我们只在磁盘映射区域中分配页,并且当在这个区域中产生页故障时,从磁盘读取相关的块去响应这个页故障。通过这种方式,我们能够假装将整个磁盘装进了内存中。
|
||||
|
||||
```markdown
|
||||
练习 2、在 `fs/bc.c` 中实现 `bc_pgfault` 和 `flush_block` 函数。`bc_pgfault` 函数是一个页故障服务程序,就像你在前一个实验中编写的写时复制 fork 一样,只不过它的任务是从磁盘中加载页去响应一个页故障。在你编写它时,记住: (1) `addr` 可能并不会做边界对齐,并且 (2) 在扇区中的 `ide_read` 操作并不是以块为单位的。
|
||||
> **练习 2**、在 `fs/bc.c` 中实现 `bc_pgfault` 和 `flush_block` 函数。`bc_pgfault` 函数是一个页故障服务程序,就像你在前一个实验中编写的写时复制 fork 一样,只不过它的任务是从磁盘中加载页去响应一个页故障。在你编写它时,记住: (1) `addr` 可能并不会做边界对齐,并且 (2) 在扇区中的 `ide_read` 操作并不是以块为单位的。
|
||||
|
||||
(如果需要的话)函数 `flush_block` 应该会将一个块写入到磁盘上。如果在块缓存中没有块(也就是说,页没有映射)或者它不是一个脏块,那么 `flush_block` 将什么都不做。我们将使用虚拟内存硬件去跟踪,磁盘块自最后一次从磁盘读取或写入到磁盘之后是否被修改过。查看一个块是否需要写入时,我们只需要去查看 `uvpt` 条目中的 `PTE_D` 的 ”dirty“ 位即可。(`PTE_D` 位由处理器设置,用于表示那个页被写入;具体细节可以查看 x386 参考手册的 [第 5 章][3] 的 5.2.4.3 节)块被写入到磁盘上之后,`flush_block` 函数将使用 `sys_page_map` 去清除 `PTE_D` 位。
|
||||
>(如果需要的话)函数 `flush_block` 应该会将一个块写入到磁盘上。如果在块缓存中没有块(也就是说,页没有映射)或者它不是一个脏块,那么 `flush_block` 将什么都不做。我们将使用虚拟内存硬件去跟踪,磁盘块自最后一次从磁盘读取或写入到磁盘之后是否被修改过。查看一个块是否需要写入时,我们只需要去查看 `uvpt` 条目中的 `PTE_D` 的 ”dirty“ 位即可。(`PTE_D` 位由处理器设置,用于表示那个页被写入;具体细节可以查看 x386 参考手册的 [第 5 章][3] 的 5.2.4.3 节)块被写入到磁盘上之后,`flush_block` 函数将使用 `sys_page_map` 去清除 `PTE_D` 位。
|
||||
|
||||
使用 `make grade` 去测试你的代码。你的代码应该能够通过 "check_bc"、"check_super"、和 "check_bitmap" 的测试。
|
||||
```
|
||||
> 使用 `make grade` 去测试你的代码。你的代码应该能够通过 "check_bc"、"check_super"、和 "check_bitmap" 的测试。
|
||||
|
||||
在 `fs/fs.c` 中的函数 `fs_init` 是块缓存使用的一个很好的示例。在初始化块缓存之后,它简单地在全局变量 `super` 中保存指针到磁盘映射区。在这之后,如果块在内存中,或我们的页故障服务程序按需将它们从磁盘上读入后,我们就能够简单地从 `super` 结构中读取块了。
|
||||
|
||||
```markdown
|
||||
小挑战!到现在为止,块缓存还没有清除策略。一旦某个块因为页故障被读入到缓存中之后,它将一直不会被清除,并且永远保留在内存中。给块缓存增加一个清除策略。在页表中使用 `PTE_A` 的 "accessed" 位来实现,任何环境访问一个页时,硬件就会设置这个位,你可以通过它来跟踪磁盘块的大致使用情况,而不需要修改访问磁盘映射区域的任何代码。使用脏块要小心。
|
||||
```
|
||||
.
|
||||
|
||||
> **小挑战!**到现在为止,块缓存还没有清除策略。一旦某个块因为页故障被读入到缓存中之后,它将一直不会被清除,并且永远保留在内存中。给块缓存增加一个清除策略。在页表中使用 `PTE_A` 的 "accessed" 位来实现,任何环境访问一个页时,硬件就会设置这个位,你可以通过它来跟踪磁盘块的大致使用情况,而不需要修改访问磁盘映射区域的任何代码。使用脏块要小心。
|
||||
|
||||
### 块位图
|
||||
|
||||
在 `fs_init` 设置了 `bitmap` 指针之后,我们可以认为 `bitmap` 是一个装满比特位的数组,磁盘上的每个块就是数组中的其中一个比特位。比如 `block_is_free`,它只是简单地在位图中检查给定的块是否被标记为空闲。
|
||||
|
||||
```markdown
|
||||
练习 3、使用 `free_block` 作为实现 `fs/fs.c` 中的 `alloc_block` 的一个模型,它将在位图中去查找一个空闲的磁盘块,并将它标记为已使用,然后返回块编号。当你分配一个块时,你应该立即使用 `flush_block` 将已改变的位图块刷新到磁盘上,以确保文件系统的一致性。
|
||||
> **练习 3**、使用 `free_block` 作为实现 `fs/fs.c` 中的 `alloc_block` 的一个模型,它将在位图中去查找一个空闲的磁盘块,并将它标记为已使用,然后返回块编号。当你分配一个块时,你应该立即使用 `flush_block` 将已改变的位图块刷新到磁盘上,以确保文件系统的一致性。
|
||||
|
||||
使用 `make grade` 去测试你的代码。现在,你的代码应该要通过 "alloc_block" 的测试。
|
||||
```
|
||||
> 使用 `make grade` 去测试你的代码。现在,你的代码应该要通过 "alloc_block" 的测试。
|
||||
|
||||
### 文件操作
|
||||
|
||||
在 `fs/fs.c` 中,我们提供一系列的函数去实现基本的功能,比如,你将需要去理解和管理结构 `File`、扫描和管理目录”文件“的条目、 以及从根目录开始遍历文件系统以解析一个绝对路径名。阅读 `fs/fs.c` 中的所有代码,并在你开始实验之前,确保你理解了每个函数的功能。
|
||||
|
||||
```markdown
|
||||
练习 4、实现 `file_block_walk` 和 `file_get_block`。`file_block_walk` 从一个文件中的块偏移量映射到 `struct File` 中那个块的指针上或间接块上,它非常类似于 `pgdir_walk` 在页表上所做的事。`file_get_block` 将更进一步,将去映射一个真实的磁盘块,如果需要的话,去分配一个新的磁盘块。
|
||||
> **练习 4**、实现 `file_block_walk` 和 `file_get_block`。`file_block_walk` 从一个文件中的块偏移量映射到 `struct File` 中那个块的指针上或间接块上,它非常类似于 `pgdir_walk` 在页表上所做的事。`file_get_block` 将更进一步,将去映射一个真实的磁盘块,如果需要的话,去分配一个新的磁盘块。
|
||||
|
||||
使用 `make grade` 去测试你的代码。你的代码应该要通过 "file_open"、"file_get_block"、以及 "file_flush/file_truncated/file rewrite"、和 "testfile" 的测试。
|
||||
```
|
||||
> 使用 `make grade` 去测试你的代码。你的代码应该要通过 "file_open"、"file_get_block"、以及 "file_flush/file_truncated/file rewrite"、和 "testfile" 的测试。
|
||||
|
||||
`file_block_walk` 和 `file_get_block` 是文件系统中的”劳动模范“。比如,`file_read` 和 `file_write` 或多或少都在 `file_get_block` 上做必需的登记工作,然后在分散的块和连续的缓存之间复制字节。
|
||||
|
||||
```
|
||||
小挑战!如果操作在中途实然被打断(比如,突然崩溃或重启),文件系统很可能会产生错误。实现软件更新或日志处理的方式让文件系统的”崩溃可靠性“更好,并且演示一下旧的文件系统可能会崩溃,而你的更新后的文件系统不会崩溃的情况。
|
||||
```
|
||||
.
|
||||
|
||||
> **小挑战!**如果操作在中途实然被打断(比如,突然崩溃或重启),文件系统很可能会产生错误。实现软件更新或日志处理的方式让文件系统的”崩溃可靠性“更好,并且演示一下旧的文件系统可能会崩溃,而你的更新后的文件系统不会崩溃的情况。
|
||||
|
||||
### 文件系统接口
|
||||
|
||||
@ -207,19 +197,17 @@ x86 处理器在 EFLAGS 寄存器中使用 IOPL 位去确定保护模式中的
|
||||
|
||||
服务器也通过 IPC 来发送响应。我们为函数的返回代码使用 32 位的数字。对于大多数 RPC,这已经涵盖了它们全部的返回代码。`FSREQ_READ` 和 `FSREQ_STAT` 也返回数据,它们只是被简单地写入到客户端发送它的请求时的页上。在 IPC 的响应中并不需要去发送这个页,因为这个页是文件系统服务器和客户端从一开始就共享的页。另外,在它的响应中,`FSREQ_OPEN` 与客户端共享一个新的 "Fd page”。我们将快捷地返回到文件描述符页上。
|
||||
|
||||
```markdown
|
||||
练习 5、实现 `fs/serv.c` 中的 `serve_read`。
|
||||
> **练习 5**、实现 `fs/serv.c` 中的 `serve_read`。
|
||||
|
||||
`serve_read` 的重任将由已经在 `fs/fs.c` 中实现的 `file_read` 来承担(它实际上不过是对 `file_get_block` 的一连串调用)。对于文件读取,`serve_read` 只能提供 RPC 接口。查看 `serve_set_size` 中的注释和代码,去大体上了解服务器函数的结构。
|
||||
> `serve_read` 的重任将由已经在 `fs/fs.c` 中实现的 `file_read` 来承担(它实际上不过是对 `file_get_block` 的一连串调用)。对于文件读取,`serve_read` 只能提供 RPC 接口。查看 `serve_set_size` 中的注释和代码,去大体上了解服务器函数的结构。
|
||||
|
||||
使用 `make grade` 去测试你的代码。你的代码通过 "serve_open/file_stat/file_close" 和 "file_read" 的测试后,你得分应该是 70(总分为 150)。
|
||||
```
|
||||
> 使用 `make grade` 去测试你的代码。你的代码通过 "serve_open/file_stat/file_close" 和 "file_read" 的测试后,你得分应该是 70(总分为 150)。
|
||||
|
||||
```markdown
|
||||
练习 6、实现 `fs/serv.c` 中的 `serve_write` 和 `lib/file.c` 中的 `devfile_write`。
|
||||
.
|
||||
|
||||
使用 `make grade` 去测试你的代码。你的代码通过 "file_write"、"file_read after file_write"、"open"、和 "large file" 的测试后,得分应该是 90(总分为150)。
|
||||
```
|
||||
> **练习 6**、实现 `fs/serv.c` 中的 `serve_write` 和 `lib/file.c` 中的 `devfile_write`。
|
||||
|
||||
> 使用 `make grade` 去测试你的代码。你的代码通过 "file_write"、"file_read after file_write"、"open"、和 "large file" 的测试后,得分应该是 90(总分为150)。
|
||||
|
||||
### 进程增殖
|
||||
|
||||
@ -227,21 +215,19 @@ x86 处理器在 EFLAGS 寄存器中使用 IOPL 位去确定保护模式中的
|
||||
|
||||
我们实现的是 `spawn`,而不是一个类 UNIX 的 `exec`,因为 `spawn` 是很容易从用户空间中、以”外内核式“ 实现的,它无需来自内核的特别帮助。为了在用户空间中实现 `exec`,想一想你应该做什么?确保你理解了它为什么很难。
|
||||
|
||||
```markdown
|
||||
练习 7、`spawn` 依赖新的系统调用 `sys_env_set_trapframe` 去初始化新创建的环境的状态。实现 `kern/syscall.c` 中的 `sys_env_set_trapframe`。(不要忘记在 `syscall()` 中派发新系统调用)
|
||||
> **练习 7**、`spawn` 依赖新的系统调用 `sys_env_set_trapframe` 去初始化新创建的环境的状态。实现 `kern/syscall.c` 中的 `sys_env_set_trapframe`。(不要忘记在 `syscall()` 中派发新系统调用)
|
||||
|
||||
运行来自 `kern/init.c` 中的 `user/spawnhello` 程序来测试你的代码`kern/init.c` ,它将尝试从文件系统中增殖 `/hello`。
|
||||
> 运行来自 `kern/init.c` 中的 `user/spawnhello` 程序来测试你的代码`kern/init.c` ,它将尝试从文件系统中增殖 `/hello`。
|
||||
|
||||
使用 `make grade` 去测试你的代码。
|
||||
```
|
||||
> 使用 `make grade` 去测试你的代码。
|
||||
|
||||
```markdown
|
||||
小挑战!实现 Unix 式的 `exec`。
|
||||
```
|
||||
.
|
||||
|
||||
```markdown
|
||||
小挑战!实现 `mmap` 式的文件内存映射,并如果可能的话,修改 `spawn` 从 ELF 中直接映射页。
|
||||
```
|
||||
> **小挑战!**实现 Unix 式的 `exec`。
|
||||
|
||||
.
|
||||
|
||||
> **小挑战!**实现 `mmap` 式的文件内存映射,并如果可能的话,修改 `spawn` 从 ELF 中直接映射页。
|
||||
|
||||
### 跨 fork 和 spawn 共享库状态
|
||||
|
||||
@ -255,11 +241,9 @@ UNIX 文件描述符是一个通称的概念,它还包括管道、控制台 I/
|
||||
|
||||
我们在 `inc/lib.h` 中定义了一个新的 `PTE_SHARE` 位,在 Intel 和 AMD 的手册中,这个位是被标记为”软件可使用的“的三个 PTE 位之一。我们将创建一个约定,如果一个页表条目中这个位被设置,那么在 `fork` 和 `spawn` 中应该直接从父环境中复制 PTE 到子环境中。注意它与标记为写时复制的差别:正如在第一段中所描述的,我们希望确保能共享页更新。
|
||||
|
||||
```markdown
|
||||
练习 8、修改 `lib/fork.c` 中的 `duppage`,以遵循最新约定。如果页表条目设置了 `PTE_SHARE` 位,仅直接复制映射。(你应该去使用 `PTE_SYSCALL`,而不是 `0xfff`,去从页表条目中掩掉有关的位。`0xfff` 仅选出可访问的位和脏位。)
|
||||
> **练习 8**、修改 `lib/fork.c` 中的 `duppage`,以遵循最新约定。如果页表条目设置了 `PTE_SHARE` 位,仅直接复制映射。(你应该去使用 `PTE_SYSCALL`,而不是 `0xfff`,去从页表条目中掩掉有关的位。`0xfff` 仅选出可访问的位和脏位。)
|
||||
|
||||
同样的,在 `lib/spawn.c` 中实现 `copy_shared_pages`。它应该循环遍历当前进程中所有的页表条目(就像 `fork` 那样),复制任何设置了 `PTE_SHARE` 位的页映射到子进程中。
|
||||
```
|
||||
> 同样的,在 `lib/spawn.c` 中实现 `copy_shared_pages`。它应该循环遍历当前进程中所有的页表条目(就像 `fork` 那样),复制任何设置了 `PTE_SHARE` 位的页映射到子进程中。
|
||||
|
||||
使用 `make run-testpteshare` 去检查你的代码行为是否正确。正确的情况下,你应该会看到像 "`fork handles PTE_SHARE right`" 和 "`spawn handles PTE_SHARE right`” 这样的输出行。
|
||||
|
||||
@ -269,9 +253,7 @@ UNIX 文件描述符是一个通称的概念,它还包括管道、控制台 I/
|
||||
|
||||
为了能让 shell 工作,我们需要一些方式去输入。QEMU 可以显示输出,我们将它的输出写入到 CGA 显示器上和串行端口上,但到目前为止,我们仅能够在内核监视器中接收输入。在 QEMU 中,我们从图形化窗口中的输入作为从键盘到 JOS 的输入,虽然键入到控制台的输入作为出现在串行端口上的字符的方式显现。在 `kern/console.c` 中已经包含了由我们自实验 1 以来的内核监视器所使用的键盘和串行端口的驱动程序,但现在你需要去把这些增加到系统中。
|
||||
|
||||
```markdown
|
||||
练习 9、在你的 `kern/trap.c` 中,调用 `kbd_intr` 去处理捕获 `IRQ_OFFSET+IRQ_KBD` 和 `serial_intr`,用它们去处理捕获 `IRQ_OFFSET+IRQ_SERIAL`。
|
||||
```
|
||||
> **练习 9**、在你的 `kern/trap.c` 中,调用 `kbd_intr` 去处理捕获 `IRQ_OFFSET+IRQ_KBD` 和 `serial_intr`,用它们去处理捕获 `IRQ_OFFSET+IRQ_SERIAL`。
|
||||
|
||||
在 `lib/console.c` 中,我们为你实现了文件的控制台输入/输出。`kbd_intr` 和 `serial_intr` 将使用从最新读取到的输入来填充缓冲区,而控制台文件类型去排空缓冲区(默认情况下,控制台文件类型为 stdin/stdout,除非用户重定向它们)。
|
||||
|
||||
@ -282,40 +264,38 @@ UNIX 文件描述符是一个通称的概念,它还包括管道、控制台 I/
|
||||
运行 `make run-icode` 或 `make run-icode-nox` 将运行你的内核并启动 `user/icode`。`icode` 又运行 `init`,它将设置控制台作为文件描述符 0 和 1(即:标准输入 stdin 和标准输出 stdout),然后增殖出环境 `sh`,就是 shell。之后你应该能够运行如下的命令了:
|
||||
|
||||
```
|
||||
echo hello world | cat
|
||||
cat lorem |cat
|
||||
cat lorem |num
|
||||
cat lorem |num |num |num |num |num
|
||||
lsfd
|
||||
echo hello world | cat
|
||||
cat lorem |cat
|
||||
cat lorem |num
|
||||
cat lorem |num |num |num |num |num
|
||||
lsfd
|
||||
```
|
||||
|
||||
注意用户库常规程序 `cprintf` 将直接输出到控制台,而不会使用文件描述符代码。这对调试非常有用,但是对管道连接其它程序却很不利。为将输出打印到特定的文件描述符(比如 1,它是标准输出 stdout),需要使用 `fprintf(1, "...", ...)`。`printf("...", ...)` 是将输出打印到文件描述符 1(标准输出 stdout) 的快捷方式。查看 `user/lsfd.c` 了解更多示例。
|
||||
|
||||
```markdown
|
||||
练习 10、
|
||||
这个 shell 不支持 I/O 重定向。如果能够运行 `run sh <script` 就更完美了,就不用将所有的命令手动去放入一个脚本中,就像上面那样。为 `<` 在 `user/sh.c` 中添加重定向的功能。
|
||||
> **练习 10**、这个 shell 不支持 I/O 重定向。如果能够运行 `run sh <script` 就更完美了,就不用将所有的命令手动去放入一个脚本中,就像上面那样。为 `<` 在 `user/sh.c` 中添加重定向的功能。
|
||||
|
||||
通过在你的 shell 中输入 `sh <script` 来测试你实现的重定向功能。
|
||||
> 通过在你的 shell 中输入 `sh <script` 来测试你实现的重定向功能。
|
||||
|
||||
运行 `make run-testshell` 去测试你的 shell。`testshell` 只是简单地给 shell ”喂“上面的命令(也可以在 `fs/testshell.sh` 中找到),然后检查它的输出是否与 `fs/testshell.key` 一样。
|
||||
```
|
||||
> 运行 `make run-testshell` 去测试你的 shell。`testshell` 只是简单地给 shell ”喂“上面的命令(也可以在 `fs/testshell.sh` 中找到),然后检查它的输出是否与 `fs/testshell.key` 一样。
|
||||
|
||||
```markdown
|
||||
小挑战!给你的 shell 添加更多的特性。最好包括以下的特性(其中一些可能会要求修改文件系统):
|
||||
.
|
||||
|
||||
* 后台命令 (`ls &`)
|
||||
* 一行中运行多个命令 (`ls; echo hi`)
|
||||
* 命令组 (`(ls; echo hi) | cat > out`)
|
||||
* 扩展环境变量 (`echo $hello`)
|
||||
* 引号 (`echo "a | b"`)
|
||||
* 命令行历史和/或编辑功能
|
||||
* tab 命令补全
|
||||
* 为命令行查找目录、cd 和路径
|
||||
* 文件创建
|
||||
* 用快捷键 `ctl-c` 去杀死一个运行中的环境
|
||||
|
||||
可做的事情还有很多,并不仅限于以上列表。
|
||||
```
|
||||
> **小挑战!**给你的 shell 添加更多的特性。最好包括以下的特性(其中一些可能会要求修改文件系统):
|
||||
|
||||
> * 后台命令 (`ls &`)
|
||||
> * 一行中运行多个命令 (`ls; echo hi`)
|
||||
> * 命令组 (`(ls; echo hi) | cat > out`)
|
||||
> * 扩展环境变量 (`echo $hello`)
|
||||
> * 引号 (`echo "a | b"`)
|
||||
> * 命令行历史和/或编辑功能
|
||||
> * tab 命令补全
|
||||
> * 为命令行查找目录、cd 和路径
|
||||
> * 文件创建
|
||||
> * 用快捷键 `ctl-c` 去杀死一个运行中的环境
|
||||
|
||||
> 可做的事情还有很多,并不仅限于以上列表。
|
||||
|
||||
到目前为止,你的代码应该要通过所有的测试。和以前一样,你可以使用 `make grade` 去评级你的提交,并且使用 `make handin` 上交你的实验。
|
||||
|
||||
@ -328,7 +308,7 @@ via: https://pdos.csail.mit.edu/6.828/2018/labs/lab5/
|
||||
作者:[csail.mit][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,111 +0,0 @@
|
||||
Translating by MjSeven
|
||||
Users, Groups and Other Linux Beasts: Part 2
|
||||
======
|
||||

|
||||
In this ongoing tour of Linux, we’ve looked at [how to manipulate folders/directories][1], and now we’re continuing our discussion of _permissions_ , _users_ and _groups_ , which are necessary to establish who can manipulate which files and directories. [Last time,][2] we showed how to create new users, and now we’re going to dive right back in:
|
||||
|
||||
You can create new groups and then add users to them at will with the `groupadd` command. For example, using:
|
||||
```
|
||||
sudo groupadd photos
|
||||
|
||||
```
|
||||
|
||||
will create the _photos_ group.
|
||||
|
||||
You’ll need to [create a directory][1] hanging off the root directory:
|
||||
```
|
||||
sudo mkdir /photos
|
||||
|
||||
```
|
||||
|
||||
If you run `ls -l /`, one of the lines will be:
|
||||
```
|
||||
drwxr-xr-x 1 root root 0 jun 26 21:14 photos
|
||||
|
||||
```
|
||||
|
||||
The first _root_ in the output is the user owner and the second _root_ is the group owner.
|
||||
|
||||
To transfer the ownership of the _/photos_ directory to the _photos_ group, use
|
||||
```
|
||||
chgrp photos /photos
|
||||
|
||||
```
|
||||
|
||||
The `chgrp` command typically takes two parameters, the first parameter is the group that will take ownership of the file or directory and the second is the file or directory you want to give over to the the group.
|
||||
|
||||
Next, run `ls -l /` and you'll see the line has changed to:
|
||||
```
|
||||
drwxr-xr-x 1 root photos 0 jun 26 21:14 photos
|
||||
|
||||
```
|
||||
|
||||
You have successfully transferred the ownership of your new directory over to the _photos_ group.
|
||||
|
||||
Then, add your own user and the _guest_ user to the _photos_ group:
|
||||
```
|
||||
sudo usermod <your username here> -a -G photos
|
||||
sudo usermod guest -a -G photos
|
||||
|
||||
```
|
||||
|
||||
You may have to log out and log back in to see the changes, but, when you do, running `groups` will show _photos_ as one of the groups you belong to.
|
||||
|
||||
A couple of things to point out about the `usermod` command shown above. First: Be careful not to use the `-g` option instead of `-G`. The `-g` option changes your primary group and could lock you out of your stuff if you use it by accident. `-G`, on the other hand, _adds_ you to the groups listed and doesn't mess with the primary group. If you want to add your user to more groups than one, list them one after another, separated by commas, no spaces, after `-G`:
|
||||
```
|
||||
sudo usermod <your username> -a -G photos,pizza,spaceforce
|
||||
|
||||
```
|
||||
|
||||
Second: Be careful not to forget the `-a` parameter. The `-a` parameter stands for _append_ and attaches the list of groups you pass to `-G` to the ones you already belong to. This means that, if you don't include `-a`, the list of groups you already belong to, will be overwritten, again locking you out from stuff you need.
|
||||
|
||||
Neither of these are catastrophic problems, but it will mean you will have to add your user back manually to all the groups you belonged to, which can be a pain, especially if you have lost access to the _sudo_ and _wheel_ group.
|
||||
|
||||
### Permits, Please!
|
||||
|
||||
There is still one more thing to do before you can copy images to the _/photos_ directory. Notice how, when you did `ls -l /` above, permissions for that folder came back as _drwxr-xr-x_.
|
||||
|
||||
If you read [the article I recommended at the beginning of this post][3], you'll know that the first _d_ indicates that the entry in the file system is a directory, and then you have three sets of three characters ( _rwx_ , _r-x_ , _r-x_ ) that indicate the permissions for the user owner ( _rwx_ ) of the directory, then the group owner ( _r-x_ ), and finally the rest of the users ( _r-x_ ). This means that the only person who has write permissions so far, that is, the only person who can copy or create files in the _/photos_ directory, is the _root_ user.
|
||||
|
||||
But [that article I mentioned also tells you how to change the permissions for a directory or file][3]:
|
||||
```
|
||||
sudo chmod g+w /photos
|
||||
|
||||
```
|
||||
|
||||
Running `ls -l /` after that will give you _/photos_ permissions as _drwxrwxr-x_ which is what you want: group members can now write into the directory.
|
||||
|
||||
Now you can try and copy an image or, indeed, any other file to the directory and it should go through without a problem:
|
||||
```
|
||||
cp image.jpg /photos
|
||||
|
||||
```
|
||||
|
||||
The _guest_ user will also be able to read and write from the directory. They will also be able to read and write to it, and even move or delete files created by other users within the shared directory.
|
||||
|
||||
### Conclusion
|
||||
|
||||
The permissions and privileges system in Linux has been honed over decades. inherited as it is from the old Unix systems of yore. As such, it works very well and is well thought out. Becoming familiar with it is essential for any Linux sysadmin. In fact, you can't do much admining at all unless you understand it. But, it's not that hard.
|
||||
|
||||
Next time, we'll be dive into files and see the different ways of creating, manipulating, and destroying them in creative ways. Always fun, that last one.
|
||||
|
||||
See you then!
|
||||
|
||||
Learn more about Linux through the free ["Introduction to Linux" ][4]course from The Linux Foundation and edX.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2
|
||||
|
||||
作者:[Paul Brown][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.linux.com/users/bro66
|
||||
[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux
|
||||
[2]:https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts
|
||||
[3]:https://www.linux.com/learn/understanding-linux-file-permissions
|
||||
[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux
|
@ -1,61 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (Take a break at the Linux command line with Nyan Cat)
|
||||
[#]: via: (https://opensource.com/article/18/12/linux-toy-nyancat)
|
||||
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
|
||||
[#]: url: ( )
|
||||
|
||||
Take a break at the Linux command line with Nyan Cat
|
||||
======
|
||||
Rainbows, Pop-Tarts, and cats in space: What more could you want at your terminal?
|
||||

|
||||
|
||||
We're now on day six of the Linux command-line toys advent calendar, where we explore some of the fun, entertaining, and in some cases, utterly useless toys available for your Linux terminal. All are available under an open source license.
|
||||
|
||||
Will they all be unique? Yes. Will they all be unique to you? I don't know, but, chances are you'll find at least one new toy to play with by the time our advent calendar is done.
|
||||
|
||||
Today's selection is a continuation on the [theme][1] we started yesterday: cats and rainbows. Wait, there's more cat-related rainbow fun to be had at the Linux command line? You bet there is.
|
||||
|
||||
So let's make a throwback all the way to 2011's [Nyan Cat][2] with a command-line toy call, not surprisingly, **nyancat**. Did you miss the cultural phenomenon that was Nyan Cat? Watch the embed below, I'll wait.
|
||||
|
||||
<https://www.youtube.com/embed/QH2-TGUlwu4>
|
||||
|
||||
Now, let's recreate that amazing experience in your terminal. **Nyancat** is packaged for many distributions (Arch, Debian, Gentoo, Ubuntu, etc.) but not for mine (Fedora), but compiling from source was simple. In fact, I grabbed the source, built it, and launched it in one line:
|
||||
|
||||
```
|
||||
git clone https://github.com/klange/nyancat.git && cd nyancat && make && cd src && ./nyancat
|
||||
```
|
||||
|
||||
This launched straight into a **nyancat** experience complete with a counter of how long I had been enjoying the **nyancat** magic for.
|
||||
|
||||

|
||||
|
||||
You can find the source for **nyancat** [on GitHub][3] under an [NCSA open source license][4].
|
||||
|
||||
The command-line version of Nyan Cat used to be [accessible by a public Telnet server][5] (or, for even more pun, with [netcat][6]) so that you didn't even have to install it, but sadly was shut down due to bandwidth limitations. Nevertheless, the [gallery][5] from the old Telnet server running Nyan Cat on a variety of old devices is well-worth checking out, and maybe you'd like to do the community a favor by launching your own public mirror and letting the author know so that they may share it with the public yet again?
|
||||
|
||||
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
|
||||
|
||||
Check out yesterday's toy, [Bring some color to your Linux terminal with lolcat][1], and check back tomorrow for another!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/12/linux-toy-nyancat
|
||||
|
||||
作者:[Jason Baker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jason-baker
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/article/18/12/linux-toy-lolcat
|
||||
[2]: https://en.wikipedia.org/wiki/Nyan_Cat
|
||||
[3]: https://github.com/klange/nyancat
|
||||
[4]: http://en.wikipedia.org/wiki/University_of_Illinois/NCSA_Open_Source_License
|
||||
[5]: http://nyancat.dakko.us/
|
||||
[6]: http://netcat.sourceforge.net/
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
278
sources/tech/20181224 An Introduction to Go.md
Normal file
278
sources/tech/20181224 An Introduction to Go.md
Normal file
@ -0,0 +1,278 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (An Introduction to Go)
|
||||
[#]: via: (https://blog.jak-linux.org/2018/12/24/introduction-to-go/)
|
||||
[#]: author: (Julian Andres Klode https://blog.jak-linux.org/)
|
||||
|
||||
An Introduction to Go
|
||||
======
|
||||
|
||||
(What follows is an excerpt from my master’s thesis, almost all of section 2.1, quickly introducing Go to people familiar with CS)
|
||||
|
||||
Go is an imperative programming language for concurrent programming created at and mainly developed by Google, initially mostly by Robert Griesemer, Rob Pike, and Ken Thompson. Design of the language started in 2007, and an initial version was released in 2009; with the first stable version, 1.0 released in 2012 .
|
||||
|
||||
Go has a C-like syntax (without a preprocessor), garbage collection, and, like its predecessors devloped at Bell Labs – Newsqueak (Rob Pike), Alef (Phil Winterbottom), and Inferno (Pike, Ritchie, et al.) – provides built-in support for concurrency using so-called goroutines and channels, a form of co-routines, based on the idea of Hoare’s ‘Communicating Sequential Processes’ .
|
||||
|
||||
Go programs are organised in packages. A package is essentially a directory containing Go files. All files in a package share the same namespace, and there are two visibilities for symbols in a package: Symbols starting with an upper case character are visible to other packages, others are private to the package:
|
||||
|
||||
```
|
||||
func PublicFunction() {
|
||||
fmt.Println("Hello world")
|
||||
}
|
||||
|
||||
func privateFunction() {
|
||||
fmt.Println("Hello package")
|
||||
}
|
||||
```
|
||||
|
||||
### Types
|
||||
|
||||
Go has a fairly simple type system: There is no subtyping (but there are conversions), no generics, no polymorphic functions, and there are only a few basic categories of types:
|
||||
|
||||
1. base types: `int`, `int64`, `int8`, `uint`, `float32`, `float64`, etc.
|
||||
|
||||
2. `struct`
|
||||
|
||||
3. `interface` \- a set of methods
|
||||
|
||||
4. `map[K, V]` \- a map from a key type to a value type
|
||||
|
||||
5. `[number]Type` \- an array of some element type
|
||||
|
||||
6. `[]Type` \- a slice (pointer to array with length and capability) of some type
|
||||
|
||||
7. `chan Type` \- a thread-safe queue
|
||||
|
||||
8. pointer `*T` to some other type
|
||||
|
||||
9. functions
|
||||
|
||||
10. named type - aliases for other types that may have associated methods:
|
||||
|
||||
```
|
||||
type T struct { foo int }
|
||||
type T *T
|
||||
type T OtherNamedType
|
||||
```
|
||||
|
||||
Named types are mostly distinct from their underlying types, so you cannot assign them to each other, but some operators like `+` do work on objects of named types with an underlying numerical type (so you could add two `T` in the example above).
|
||||
|
||||
|
||||
Maps, slices, and channels are reference-like types - they essentially are structs containing pointers. Other types are passed by value (copied), including arrays (which have a fixed length and are copied).
|
||||
|
||||
#### Conversions
|
||||
|
||||
Conversions are the similar to casts in C and other languages. They are written like this:
|
||||
|
||||
```
|
||||
TypeName(value)
|
||||
```
|
||||
|
||||
#### Constants
|
||||
|
||||
Go has “untyped” literals and constants.
|
||||
|
||||
```
|
||||
1 // untyped integer literal
|
||||
const foo = 1 // untyped integer constant
|
||||
const foo int = 1 // int constant
|
||||
```
|
||||
|
||||
Untyped values are classified into the following categories: `UntypedBool`, `UntypedInt`, `UntypedRune`, `UntypedFloat`, `UntypedComplex`, `UntypedString`, and `UntypedNil` (Go calls them basic kinds, other basic kinds are available for the concrete types like `uint8`). An untyped value can be assigned to a named type derived from a base type; for example:
|
||||
|
||||
```
|
||||
type someType int
|
||||
|
||||
const untyped = 2 // UntypedInt
|
||||
const bar someType = untyped // OK: untyped can be assigned to someType
|
||||
const typed int = 2 // int
|
||||
const bar2 someType = typed // error: int cannot be assigned to someType
|
||||
```
|
||||
|
||||
### Interfaces and ‘objects’
|
||||
|
||||
As mentioned before, interfaces are a set of methods. Go is not an object-oriented language per se, but it has some support for associating methods with named types: When declaring a function, a receiver can be provided - a receiver is an additional function argument that is passed before the function and involved in the function lookup, like this:
|
||||
|
||||
```
|
||||
type SomeType struct { ... }
|
||||
|
||||
func (s *SomeType) MyMethod() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var s SomeType
|
||||
s.MyMethod()
|
||||
}
|
||||
```
|
||||
|
||||
An object implements an interface if it implements all methods; for example, the following interface `MyMethoder` is implemented by `*SomeType` (note the pointer), and values of `*SomeType` can thus be used as values of `MyMethoder`. The most basic interface is `interface{}`, that is an interface with an empty method set - any object satisfies that interface.
|
||||
|
||||
```
|
||||
type MyMethoder interface {
|
||||
MyMethod()
|
||||
}
|
||||
```
|
||||
|
||||
There are some restrictions on valid receiver types; for example, while a named type could be a pointer (for example, `type MyIntPointer *int`), such a type is not a valid receiver type.
|
||||
|
||||
### Control flow
|
||||
|
||||
Go provides three primary statements for control flow: `if`, `switch`, and `for`. The statements are fairly similar to their equivalent in other C-like languages, with some exceptions:
|
||||
|
||||
* There are no parentheses around conditions, so it is `if a == b {}`, not `if (a == b) {}`. The braces are mandatory.
|
||||
|
||||
* All of them can have initialisers, like this
|
||||
|
||||
`if result, err := someFunction(); err == nil { // use result }`
|
||||
|
||||
* The `switch` statement can use arbitrary expressions in cases
|
||||
|
||||
* The `switch` statement can switch over nothing (equals switching over true)
|
||||
|
||||
* Cases do not fall through by default (no `break` needed), use `fallthrough` at the end of a block to fall through.
|
||||
|
||||
* The `for` loop can loop over ranges: `for key, val := range map { do something }`
|
||||
|
||||
|
||||
|
||||
|
||||
### Goroutines
|
||||
|
||||
The keyword `go` spawns a new goroutine, a concurrently executed function. It can be used with any function call, even a function literal:
|
||||
|
||||
```
|
||||
func main() {
|
||||
...
|
||||
go func() {
|
||||
...
|
||||
}()
|
||||
|
||||
go some_function(some_argument)
|
||||
}
|
||||
```
|
||||
|
||||
### Channels
|
||||
|
||||
Goroutines are often combined with channels to provide an extended form of Communicating Sequential Processes . A channel is a concurrent-safe queue, and can be buffered or unbuffered:
|
||||
|
||||
```
|
||||
var unbuffered = make(chan int) // sending blocks until value has been read
|
||||
var buffered = make(chan int, 5) // may have up to 5 unread values queued
|
||||
```
|
||||
|
||||
The `<-` operator is used to communicate with a single channel.
|
||||
|
||||
```
|
||||
valueReadFromChannel := <- channel
|
||||
otherChannel <- valueToSend
|
||||
```
|
||||
|
||||
The `select` statement allows communication with multiple channels:
|
||||
|
||||
```
|
||||
select {
|
||||
case incoming := <- inboundChannel:
|
||||
// A new message for me
|
||||
case outgoingChannel <- outgoing:
|
||||
// Could send a message, yay!
|
||||
}
|
||||
```
|
||||
|
||||
### The `defer` statement
|
||||
|
||||
Go provides a `defer` statement that allows a function call to be scheduled for execution when the function exits. It can be used for resource clean-up, for example:
|
||||
|
||||
```
|
||||
func myFunc(someFile io.ReadCloser) {
|
||||
defer someFile.close()
|
||||
/bin /boot /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var Do stuff with file */
|
||||
}
|
||||
```
|
||||
|
||||
It is of course possible to use function literals as the function to call, and any variables can be used as usual when writing the call.
|
||||
|
||||
### Error handling
|
||||
|
||||
Go does not provide exceptions or structured error handling. Instead, it handles errors by returning them in a second or later return value:
|
||||
|
||||
```
|
||||
func Read(p []byte) (n int, err error)
|
||||
|
||||
// Built-in type:
|
||||
type error interface {
|
||||
Error() string
|
||||
}
|
||||
```
|
||||
|
||||
Errors have to be checked in the code, or can be assigned to `_`:
|
||||
|
||||
```
|
||||
n0, _ := Read(Buffer) // ignore error
|
||||
n, err := Read(buffer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
```
|
||||
|
||||
There are two functions to quickly unwind and recover the call stack, though: `panic()` and `recover()`. When `panic()` is called, the call stack is unwound, and any deferred functions are run as usual. When a deferred function invokes `recover()`, the unwinding stops, and the value given to `panic()` is returned. If we are unwinding normally and not due to a panic, `recover()` simply returns `nil`. In the example below, a function is deferred and any `error` value that is given to `panic()` will be recovered and stored in an error return value. Libraries sometimes use that approach to make highly recursive code like parsers more readable, while still maintaining the usual error return value for public functions.
|
||||
|
||||
```
|
||||
func Function() (err error) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
switch s := s.(type) { // type switch
|
||||
case error:
|
||||
err = s // s has type error now
|
||||
default:
|
||||
panic(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Arrays and slices
|
||||
|
||||
As mentioned before, an array is a value type and a slice is a pointer into an array, created either by slicing an existing array or by using `make()` to create a slice, which will create an anonymous array to hold the elements.
|
||||
|
||||
```
|
||||
slice1 := make([]int, 2, 5) // 5 elements allocated, 2 initialized to 0
|
||||
slice2 := array[:] // sliced entire array
|
||||
slice3 := array[1:] // slice of array without first element
|
||||
```
|
||||
|
||||
There are some more possible combinations for the slicing operator than mentioned above, but this should give a good first impression.
|
||||
|
||||
A slice can be used as a dynamically growing array, using the `append()` function.
|
||||
|
||||
```
|
||||
slice = append(slice, value1, value2)
|
||||
slice = append(slice, arrayOrSlice...)
|
||||
```
|
||||
|
||||
Slices are also used internally to represent variable parameters in variable length functions.
|
||||
|
||||
### Maps
|
||||
|
||||
Maps are simple key-value stores and support indexing and assigning. They are not thread-safe.
|
||||
|
||||
```
|
||||
someValue := someMap[someKey]
|
||||
someValue, ok := someMap[someKey] // ok is false if key not in someMap
|
||||
someMap[someKey] = someValue
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://blog.jak-linux.org/2018/12/24/introduction-to-go/
|
||||
|
||||
作者:[Julian Andres Klode][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://blog.jak-linux.org/
|
||||
[b]: https://github.com/lujun9972
|
@ -0,0 +1,288 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Turn GNOME to Heaven With These 23 GNOME Extensions)
|
||||
[#]: via: (https://fosspost.org/tutorials/turn-gnome-to-heaven-with-these-23-gnome-extensions)
|
||||
[#]: author: (M.Hanny Sabbagh https://fosspost.org/author/mhsabbagh)
|
||||
|
||||
Turn GNOME to Heaven With These 23 GNOME Extensions
|
||||
======
|
||||
|
||||
GNOME Shell is one of the most used desktop interfaces on the Linux desktop. It’s part of the GNOME project and is considered to be the next generation of the old classic GNOME 2.x interface. GNOME Shell was first released in 2011 carrying a lot of features, including GNOME Shell extensions feature.
|
||||
|
||||
GNOME Extensions are simply extra functionality that you can add to your interface, they can be panel extensions, performance extensions, quick access extensions, productivity extensions or for any other type of usage. They are all free and open source of course; you can install them with a single click **from your web browser** actually.
|
||||
|
||||
### How To Install GNOME Extensions?
|
||||
|
||||
You main way to install GNOME extensions will be via the extensions.gnome.org website. It’s an official platform belonging to GNOME where developers publish their extensions easily so that users can install them in a single click.
|
||||
|
||||
In order to for this to work, you’ll need two things:
|
||||
|
||||
1. Browser Add-on: You’ll need to install a browser add-on that allows the website to communicate with your local GNOME desktop. You install it from [here for Firefox][1], or [here for Chrome][2] or [here for Opera][3].
|
||||
|
||||
2. Native Connector: You still need another part to allow your system to accept installing files locally from your web browser. To install this component, you must install the `chrome-gnome-shell` package. Do not be deceived! Although the package name is containing “chrome”, it also works on Firefox too. To install it on Debian/Ubuntu/Mint run the following command in terminal:
|
||||
|
||||
```
|
||||
sudo apt install chrome-gnome-shell
|
||||
```
|
||||
|
||||
For Fedora:
|
||||
|
||||
```
|
||||
sudo dnf install chrome-gnome-shell
|
||||
```
|
||||
|
||||
For Arch:
|
||||
|
||||
```
|
||||
sudo pacman -S chrome-gnome-shell
|
||||
```
|
||||
|
||||
After you have installed the two components above, you can easily install extensions from the GNOME extensions website.
|
||||
|
||||
### How to Configure GNOME Extensions Settings?
|
||||
|
||||
Many of these extensions do have a settings window that you can access to adjust the preferences of that extension. You must make sure that you have seen its options at least once so that you know what you can possibly do using that extension.
|
||||
|
||||
To do this, you can head to the [installed extensions page on the GNOME website][4], and you’ll see a small options button near every extension that offers one:
|
||||
|
||||
![Screenshot 2018 12 24 20 50 55 41][5]
|
||||
|
||||
Clicking it will display a window for you, from which you can see the possible settings:
|
||||
|
||||
![Screenshot 2018 12 24 20 51 29 43][6]
|
||||
|
||||
Read our article below for our list of recommended extension!
|
||||
|
||||
### General Extensions
|
||||
|
||||
#### 1\. User Themes
|
||||
|
||||
![Screenshot from 2018 12 23 12 30 20 45][7]
|
||||
|
||||
This is the first must-install extension on the GNOME Shell interface, it simply allows you to change the desktop theme to another one using the tweak tool. After installation run gnome-tweak-tool, and you’ll be able to change your desktop theme.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/19/user-themes/>
|
||||
|
||||
#### 2\. Dash to Panel
|
||||
|
||||
![Screenshot from 2018 12 24 21 16 11 47][8]
|
||||
|
||||
Converts the GNOME top bar into a taskbar with many added features, such as favorite icons, moving the clock to right, adding currently opened windows to the panel and many other features. (Make sure not to install this one with some other extensions below which do provide the same functionality).
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/1160/dash-to-panel/>
|
||||
|
||||
#### 3\. Desktop Icons
|
||||
|
||||
![gnome shell screenshot SSP3UZ 49][9]
|
||||
|
||||
Restores desktop icons back again to GNOME. Still in continues development.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/1465/desktop-icons/>
|
||||
|
||||
#### 4\. Dash to Dock
|
||||
|
||||
![Screenshot from 2018 12 24 21 50 07 51][10]
|
||||
|
||||
If you are a fan of the Unity interface, then this extension may help you. It simply adds a dock to the left/right side of the screen, which is very similar to Unity. You can customize that dock however you like.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/307/dash-to-dock/>
|
||||
|
||||
### Productivity Extensions
|
||||
|
||||
#### 5\. Todo.txt
|
||||
|
||||
![screenshot_570_5X5YkZb][11]
|
||||
|
||||
For users who like to maintain productivity, you can use this extension to add a simple To-Do list functionality to your desktop, it will use the [syntax][12] from todotxt.com, you can add unlimited to-dos, mark them as complete or remove them, change their position beside modifying or taking a backup of the todo.txt file manually.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/570/todotxt/>
|
||||
|
||||
#### 6\. Screenshot Tool
|
||||
|
||||
![Screenshot from 2018 12 24 21 04 14 54][13]
|
||||
|
||||
Easily take a screenshot of your desktop or a specific area, with the possibility of also auto-uploading it to imgur.com and auto-saving the link into the clipboard! Very useful extension.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/1112/screenshot-tool/>
|
||||
|
||||
#### 7\. OpenWeather
|
||||
|
||||
![screenshot_750][14]
|
||||
|
||||
If you would like to know the weather forecast everyday then this extension will be the right one for you, this extension will simply add an applet to the top panel allowing you to fetch the weather data from openweathermap.org or forecast.io, it supports all the countries and cities around the world. It also shows the wind and humidity.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/750/openweather/>
|
||||
|
||||
#### 8 & 9\. Search Providers Extensions
|
||||
|
||||
![Screenshot from 2018 12 24 21 29 41 57][15]
|
||||
|
||||
In GNOME, you can add what’s known as “search providers” to the shell, meaning that when you type something in the search box, you’ll be able to automatically search these websites (search providers) using the same text you entered, and see the results directly from your shell!
|
||||
|
||||
YouTube Search Provider: <https://extensions.gnome.org/extension/1457/youtube-search-provider/>
|
||||
|
||||
Wikipedia Search Provider: <https://extensions.gnome.org/extension/512/wikipedia-search-provider/>
|
||||
|
||||
### Workflow Extensions
|
||||
|
||||
#### 10\. No Title Bar
|
||||
|
||||
![Screenshot 20181224210737 59][16]
|
||||
|
||||
This extension simply removes the title bar from all the maximized windows, and moves it into the top GNOME Panel. In this way, you’ll be able to save a complete horizontal line on your screen, more space for your work!
|
||||
|
||||
Installation Link: <https://extensions.gnome.org/extension/1267/no-title-bar/>
|
||||
|
||||
#### 11\. Applications Menu
|
||||
|
||||
![Screenshot 2018 12 23 13 58 07 61][17]
|
||||
|
||||
This extension simply adds a classic menu to the “activities” menu on the corner. By using it, you will be able to browse the installed applications and categories without the need to use the dash or the search feature, which saves you time. (Check the “No hot corner” extension below to get a better usage).
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/6/applications-menu/>
|
||||
|
||||
#### 12\. Places Status Indicator
|
||||
|
||||
![screenshot_8_1][18]
|
||||
|
||||
This indicator will put itself near the left corner of the activities button, it allows you to access your home folder and sub-folders easily using a menu, you can also browse the available devices and networks using it.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/8/places-status-indicator/>
|
||||
|
||||
#### 13\. Window List
|
||||
|
||||
![Screenshot from 2016-08-12 08-05-48][19]
|
||||
|
||||
Officially supported by GNOME team, this extension adds a bottom panel to the desktop which allows you to navigate between the open windows easily, it also include a workspace indicator to switch between them.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/602/window-list/>
|
||||
|
||||
#### 14\. Frippery Panel Favorites
|
||||
|
||||
![screenshot_4][20]
|
||||
|
||||
This extensions adds your favorite applications and programs to the panel near the activities button, allowing you to access to it more quickly with just 1 click, you can add or remove applications from it just by modifying your applications in your favorites (the same applications in the left panel when you click the activities button will appear here).
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/4/panel-favorites/>
|
||||
|
||||
#### 15\. TopIcons
|
||||
|
||||
![Screenshot 20181224211009 66][21]
|
||||
|
||||
Those extensions restore the system tray back into the top GNOME panel. Very needed in cases of where applications are very much dependent on the tray icon.
|
||||
|
||||
For GNOME 3.28, installation link: <https://extensions.gnome.org/extension/1031/topicons/>
|
||||
|
||||
For GNOME 3.30, installation link: <https://extensions.gnome.org/extension/1497/topicons-redux/>
|
||||
|
||||
#### 16\. Clipboard Indicator
|
||||
|
||||
![Screenshot 20181224214626 68][22]
|
||||
|
||||
A clipboard manager is simply an applications that manages all the copy & paste operations you do on your system and saves them into a history, so that you can access them later whenever you want.
|
||||
|
||||
This extension does exactly this, plus many other cool features that you can check.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/779/clipboard-indicator/>
|
||||
|
||||
### Other Extensions
|
||||
|
||||
#### 17\. Frippery Move Clock
|
||||
|
||||
![screenshot_2][23]
|
||||
|
||||
If you are from those people who like alignment a lot, and dividing the panels into 2 parts only, then you may like this extension, what it simply does is moving the clock from the middle of the GNOME Shell panel to the right near the other applets on the panel, which makes it more organized.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/2/move-clock/>
|
||||
|
||||
#### 18\. No Topleft Hot Corner
|
||||
|
||||
If you don’t like opening the dash whenever you move the mouse to the left corner, you can disable it easily using this extension. You can for sure click the activities button if you want to open the dash view (or via the Super key on the keyboard), but the hot corner will be disabled only.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/118/no-topleft-hot-corner/>
|
||||
|
||||
#### 19\. No Annoyance
|
||||
|
||||
Simply removes the “window is ready” notification each time a new window a opened.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/1236/noannoyance/>
|
||||
|
||||
#### 20\. EasyScreenCast
|
||||
|
||||
![Screenshot 20181224214219 71][24]
|
||||
|
||||
If you would like to quickly take a screencast for your desktop, then this extension may help you. By simply just choosing the type of recording you want, you’ll be able to take screencasts any time. You can also configure advanced options for the extension, such as the pipeline and many other things.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/690/easyscreencast/>
|
||||
|
||||
#### 21\. Removable drive Menu
|
||||
|
||||
![Screenshot 20181224214131 73][25]
|
||||
|
||||
Adds an icon to the top bar which shows you a list of your currently removable drives.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/7/removable-drive-menu/>
|
||||
|
||||
#### 22\. BottomPanel
|
||||
|
||||
![Screenshot 20181224214419 75][26]
|
||||
|
||||
As its title says.. It simply moves the top GNOME bar into the bottom of the screen.
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/949/bottompanel/>
|
||||
|
||||
#### 23\. Unite
|
||||
|
||||
If you would like one extension only to do most of the above tasks, then Unite extension can help you. It adds panel favorites, removes title bar, moves the clock, allows you to change the location of the panel.. And many other features. All using this extension alone!
|
||||
|
||||
Installation link: <https://extensions.gnome.org/extension/1287/unite/>
|
||||
|
||||
### Conclusion
|
||||
|
||||
This was our list for some great GNOME Shell extensions to try out. Of course, you don’t (and shouldn’t!) install all of these, but just what you need for your own usage. As you can see, you can convert GNOME into any form you would like, but be careful for RAM usage (because if you use more extensions, the shell will consume very much resources).
|
||||
|
||||
What other GNOME Shell extensions do you use? What do you think of this list?
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fosspost.org/tutorials/turn-gnome-to-heaven-with-these-23-gnome-extensions
|
||||
|
||||
作者:[M.Hanny Sabbagh][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fosspost.org/author/mhsabbagh
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://addons.mozilla.org/en/firefox/addon/gnome-shell-integration/
|
||||
[2]: https://chrome.google.com/webstore/detail/gnome-shell-integration/gphhapmejobijbbhgpjhcjognlahblep
|
||||
[3]: https://addons.opera.com/en/extensions/details/gnome-shell-integration/
|
||||
[4]: https://extensions.gnome.org/local/
|
||||
[5]: https://i1.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot_2018-12-24_20-50-55.png?resize=850%2C359&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 42)
|
||||
[6]: https://i1.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot_2018-12-24_20-51-29.png?resize=850%2C462&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 44)
|
||||
[7]: https://i2.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-from-2018-12-23-12-30-20.png?resize=850%2C478&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 46)
|
||||
[8]: https://i0.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-from-2018-12-24-21-16-11.png?resize=850%2C478&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 48)
|
||||
[9]: https://i2.wp.com/fosspost.org/wp-content/uploads/2018/12/gnome-shell-screenshot-SSP3UZ.png?resize=850%2C492&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 50)
|
||||
[10]: https://i1.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-from-2018-12-24-21-50-07.png?resize=850%2C478&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 52)
|
||||
[11]: https://i0.wp.com/fosspost.org/wp-content/uploads/2016/08/screenshot_570_5X5YkZb.png?resize=478%2C474&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 53)
|
||||
[12]: https://github.com/ginatrapani/todo.txt-cli/wiki/The-Todo.txt-Format
|
||||
[13]: https://i1.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-from-2018-12-24-21-04-14.png?resize=715%2C245&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 55)
|
||||
[14]: https://i2.wp.com/fosspost.org/wp-content/uploads/2016/08/screenshot_750.jpg?resize=648%2C276&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 56)
|
||||
[15]: https://i2.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-from-2018-12-24-21-29-41.png?resize=850%2C478&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 58)
|
||||
[16]: https://i0.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-20181224210737-380x95.png?resize=380%2C95&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 60)
|
||||
[17]: https://i0.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot_2018-12-23_13-58-07.png?resize=524%2C443&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 62)
|
||||
[18]: https://i0.wp.com/fosspost.org/wp-content/uploads/2016/08/screenshot_8_1.png?resize=247%2C620&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 63)
|
||||
[19]: https://i1.wp.com/fosspost.org/wp-content/uploads/2016/08/Screenshot-from-2016-08-12-08-05-48.png?resize=850%2C478&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 64)
|
||||
[20]: https://i0.wp.com/fosspost.org/wp-content/uploads/2016/08/screenshot_4.png?resize=414%2C39&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 65)
|
||||
[21]: https://i0.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-20181224211009-631x133.png?resize=631%2C133&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 67)
|
||||
[22]: https://i1.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-20181224214626-520x443.png?resize=520%2C443&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 69)
|
||||
[23]: https://i0.wp.com/fosspost.org/wp-content/uploads/2016/08/screenshot_2.png?resize=388%2C26&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 70)
|
||||
[24]: https://i2.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-20181224214219-327x328.png?resize=327%2C328&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 72)
|
||||
[25]: https://i1.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-20181224214131-366x199.png?resize=366%2C199&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 74)
|
||||
[26]: https://i2.wp.com/fosspost.org/wp-content/uploads/2018/12/Screenshot-20181224214419-830x143.png?resize=830%2C143&ssl=1 (Turn GNOME to Heaven With These 23 GNOME Extensions 76)
|
139
sources/tech/20181226 -Review- Polo File Manager in Linux.md
Normal file
139
sources/tech/20181226 -Review- Polo File Manager in Linux.md
Normal file
@ -0,0 +1,139 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: ([Review] Polo File Manager in Linux)
|
||||
[#]: via: (https://itsfoss.com/polo-file-manager/)
|
||||
[#]: author: (John Paul https://itsfoss.com/author/john/)
|
||||
|
||||
[Review] Polo File Manager in Linux
|
||||
======
|
||||
|
||||
We are all familiar with file managers. It’s that piece of software that allows you to access your directories, files in a GUI.
|
||||
|
||||
Most of us use the default file manager included with our desktop of choice. The creator of [Polo][1] hopes to get you to use his file manager by adding extra features but hides the good ones behind a paywall.
|
||||
|
||||
![][2]Polo file manager
|
||||
|
||||
### What is Polo file manager?
|
||||
|
||||
According to its [website][1], Polo is an “advanced file manager for Linux written in [Vala][3])”. Further down the page, Polo is referred to as a “modern, light-weight file manager for Linux with support for multiple panes and tabs; support for archives, and much more.”
|
||||
|
||||
It is from the same developer (Tony George) that has given us some of the most popular applications for desktop Linux. [Timeshift backup][4] tool, [Conky Manager][5], [Aptik backup tool][6]s for applications etc. Polo is the latest offering from Tony.
|
||||
|
||||
Note that Polo is still in the beta stage of development which means the first stable version of the software is not out yet.
|
||||
|
||||
### Features of Polo file manager
|
||||
|
||||
![Polo File Manager in Ubuntu Linux][7]Polo File Manager in Ubuntu Linux
|
||||
|
||||
It’s true that Polo has a bunch of neat features that most file managers don’t have. However, the really neat features are only available if you donate more than $10 to the project or sign up for the creator’s Patreon. I will be separating the free features from the features that require the “donation plugin”.
|
||||
|
||||
![Cloud storage support in Polo file manager][8]Support cloud storage
|
||||
|
||||
#### Free Features
|
||||
|
||||
* Multiple Panes – Single-pane, dual-pane (vertical or horizontal split) and quad-pane layouts.
|
||||
* Multiple Views – List view, Icon view, Tiled view, and Media view
|
||||
* Device Manager – Devices popup displays the list of connected devices with options to mount and unmount
|
||||
* Archive Support – Support for browsing archives as normal folders. Supports creation of archives in multiple formats with advanced compression settings.
|
||||
* Checksum & Hashing – Generate and compare MD5, SHA1, SHA2-256 ad SHA2-512 checksums
|
||||
* Built-in [Fish shell][9]
|
||||
* Support for [cloud storage][10], such as Dropbox, Google Drive, Amazon Drive, Amazon S3, Backblaze B2, Hubi, Microsoft OneDrive, OpenStack Swift, and Yandex Disk
|
||||
* Compare files
|
||||
* Analyses disk usage
|
||||
* KVM support
|
||||
* Connect to FTP, SFTP, SSH and Samba servers
|
||||
|
||||
|
||||
|
||||
![Dual pane view of Polo file manager][11]Polo in dual pane view
|
||||
|
||||
#### Donation/Paywall Features
|
||||
|
||||
* Write ISO to USB Device
|
||||
* Image optimization and adjustment tools
|
||||
* Optimize PNG
|
||||
* Reduce JPEG Quality
|
||||
* Remove Color
|
||||
* Reduce Color
|
||||
* Boost Color
|
||||
* Set as Wallpaper
|
||||
* Rotate
|
||||
* Resize
|
||||
* Convert to PNG, JPEG, TIFF, BMP, ICO and more
|
||||
* PDF tools
|
||||
* Split
|
||||
* Merge
|
||||
* Add and Remove Password
|
||||
* Reduce File Size
|
||||
* Uncompress
|
||||
* Remove Colors
|
||||
* Rotate
|
||||
* Optimize
|
||||
* Video Download via [youtube-dl][12]
|
||||
|
||||
|
||||
|
||||
### Installing Polo
|
||||
|
||||
Let’s see how to install Polo file manager on various Linux distributions.
|
||||
|
||||
#### 1\. Ubuntu based distributions
|
||||
|
||||
For all Ubuntu based systems (Ubuntu, Linux Mint, Elementary OS, etc), you can install Polo via the [official PPA][13]. Not sure what a PPA is? [Read about PPA here][14].
|
||||
|
||||
`sudo apt-add-repository -y ppa:teejee2008/ppa`
|
||||
`sudo apt-get update`
|
||||
`sudo apt-get install polo-file-manager`
|
||||
|
||||
#### 2\. Arch based distributions
|
||||
|
||||
For all Arch-based systems (Arch, Manjaro, ArchLabs, etc), you can install Polo from the [Arch User Repository][15].
|
||||
|
||||
#### 3\. Other Distros
|
||||
|
||||
For all other distros, you can download and use the [.RUN installer][16] to setup Polo.
|
||||
|
||||
### Thoughts on Polo
|
||||
|
||||
I’ve installed tons of different distros and never had a problem with the default file manager. (I’ve probably used Thunar and Caja the most.) The free version of Polo doesn’t contain any features that would make me switch. As for the paid features, I already use a number of applications that accomplish the same things.
|
||||
|
||||
One final note: the paid version of Polo is supposed to help fund development of the project. However, [according to GitHub][17], the last commit on Polo was three months ago. That’s quite a big interval of inactivity for a software that is still in the beta stages of development.
|
||||
|
||||
Have you ever used [Polo][1]? If not, what is your favorite Linux file manager? Let us know in the comments below.
|
||||
|
||||
If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit][18].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/polo-file-manager/
|
||||
|
||||
作者:[John Paul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/john/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://teejee2008.github.io/polo/
|
||||
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/polo.jpg?fit=800%2C500&ssl=1
|
||||
[3]: https://en.wikipedia.org/wiki/Vala_(programming_language
|
||||
[4]: https://itsfoss.com/backup-restore-linux-timeshift/
|
||||
[5]: https://itsfoss.com/conky-gui-ubuntu-1304/
|
||||
[6]: https://github.com/teejee2008/aptik
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/polo-file-manager-in-ubuntu.jpeg?resize=800%2C450&ssl=1
|
||||
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/polo-coud-options.jpg?fit=800%2C795&ssl=1
|
||||
[9]: https://fishshell.com/
|
||||
[10]: https://itsfoss.com/cloud-services-linux/
|
||||
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/polo-dual-pane.jpg?fit=800%2C520&ssl=1
|
||||
[12]: https://itsfoss.com/download-youtube-linux/
|
||||
[13]: https://launchpad.net/~teejee2008/+archive/ubuntu/ppa
|
||||
[14]: https://itsfoss.com/ppa-guide/
|
||||
[15]: https://aur.archlinux.org/packages/polo
|
||||
[16]: https://github.com/teejee2008/polo/releases
|
||||
[17]: https://github.com/teejee2008/polo
|
||||
[18]: http://reddit.com/r/linuxusersgroup
|
@ -0,0 +1,105 @@
|
||||
用户、组及其他 Linux 特性:第二部分
|
||||
======
|
||||
|
||||

|
||||
|
||||
在正在进行的 Linux 之旅中,我们了解了[如何操作文件夹或目录][1],现在我们继续讨论 _权限_,_用户_ 和 _组_,这对于确定谁可以操作哪些文件和目录是必要的。[上次][2],我们展示了如何创建新用户,现在我们将重新来一遍:
|
||||
|
||||
你可以使用 `groupadd` 命令创建新组,然后随意添加用户。例如,使用:
|
||||
```
|
||||
sudo groupadd photos
|
||||
```
|
||||
|
||||
这将会创建 _photos_ 组。
|
||||
|
||||
你需要在根目录下[创建一个目录][1]:
|
||||
```
|
||||
sudo mkdir /photos
|
||||
```
|
||||
|
||||
如果你运行 `ls -l /`,结果中会有如下这一行:
|
||||
```
|
||||
drwxr-xr-x 1 root root 0 jun 26 21:14 photos
|
||||
```
|
||||
|
||||
输出中的第一个 _root_ 是所属的用户,第二个 _root_ 是所属的组。
|
||||
|
||||
要将 _/photos_ 目录的所有权转移到 _photos_ 组,使用:
|
||||
```
|
||||
chgrp photos /photos
|
||||
```
|
||||
|
||||
`chgrp` 命令通常采用两个参数,第一个参数是将要获得文件或目录所有权的组,第二个参数是希望交给组的文件或目录。
|
||||
|
||||
接着,运行 `ls -l /`,你会发现刚才那一行变了:
|
||||
```
|
||||
drwxr-xr-x 1 root photos 0 jun 26 21:14 photos
|
||||
```
|
||||
|
||||
你已成功将新目录的所有权转移到了 _photos_ 组。
|
||||
|
||||
然后,将你自己的用户和 _guest_ 用户添加到 _photos_ 组:
|
||||
```
|
||||
sudo usermod <你的用户名> -a -G photos
|
||||
sudo usermod guest -a -G photos
|
||||
```
|
||||
|
||||
你可能必须注销并重新登录才能看到更改,但是当你这样做时,运行 `groups` 会将 _photos_ 显示为你所属的组之一。
|
||||
|
||||
(to 校正:这里的 primary group 翻译成什么更好点呢)
|
||||
关于上面提到的 `usermod` 命令,需要指明几点。第一:注意要使用 `-G` 选项而不是 `-g` 选项。`-g` 选项更改你的主要组,如果你意外地使用它,它可能会锁定你的一些东西。另一方面,`-G` 将你 _添加(add)_ 到列出的组中,并没有干扰主要组。如果要将用户添加到多个组中,在 `-G` 之后逐个列出他们,用逗号分隔,不要有空格:
|
||||
```
|
||||
sudo usermod <your username> -a -G photos,pizza,spaceforce
|
||||
```
|
||||
|
||||
第二点:小心点不要忘记 `-a` 参数。`-a` 参数代表 _追加(append)_,将你传递给 `-G` 的组列表附加到你已经属于的组。这意味着,如果你不包含 `-a`,那么你之前所属的组列表将被覆盖,再次将你从你需要的东西中锁定。(to 校正:最后这句话什么意思呢)
|
||||
|
||||
这些都不是灾难性问题,但这意味着你必须手动将用户添加回你所属的所有组,这可能是个麻烦,特别是如果你失去了对 _sudo_ 和 _wheel_ 组的访问权限。
|
||||
|
||||
### 权限
|
||||
|
||||
在将图像复制到 _/photos_ 目录之前,还要做一件事情。注意,当你执行上面的 `ls -l /` 时,该文件夹的权限将以 _drwxr-xr-x_ 形式返回。
|
||||
|
||||
如果你阅读[我在本文开头推荐的文章][3],你将知道第一个 _d_ 表示文件系统中的条目是一个目录,接着你有三组三个字符 (_rwx_, _r-x_, _r-x_),它们表示目录的所属用户 (_rwx_) 的权限,然后是所属组 (_r-x_)的权限,最后是其他用户 (_r-x_) 的权限。这意味着到目前为止唯一具有写权限的人,即能够在 _/photos_ 目录中复制或创建文件的唯一人员是 _root_ 用户。
|
||||
|
||||
但是[我提到的那篇文章也告诉你如何更改目录或文件的权限][3]:
|
||||
```
|
||||
sudo chmod g+w /photos
|
||||
```
|
||||
|
||||
运行 `ls -l /`,你会看到 _/photos_ 权限变为了 _drwxrwxr-x_。这就是你希望的:组成员现在可以对目录进行写操作了。
|
||||
|
||||
现在你可以尝试将图像或任何其他文件复制到目录中,它应该没有问题:
|
||||
```
|
||||
cp image.jpg /photos
|
||||
```
|
||||
|
||||
_guest_ 用户也可以从目录中读取和写入。他们也可以读取和写入,甚至移动或删除共享目录中其他用户创建的文件。(to 校正:这里 guest 可以从目录中读取和写入吗?guest 不应该是 r-x 权限吗?)
|
||||
|
||||
### 总结
|
||||
|
||||
Linux 中的权限和特权系统已经磨练了几十年,它继承自昔日的旧 Unix 系统。就其本身而言,它工作的非常好,而且经过了深思熟虑。熟悉它对于任何 Linux 系统管理员都是必不可少的。事实上,除非你理解它,否则你根本就无法做很多事情。但是,这并不难。
|
||||
|
||||
下一次,我们将深入研究文件,并以一个创新的方式查看创建,操作和销毁文件的不同方法。最后一个总是很有趣。
|
||||
|
||||
回头见!
|
||||
|
||||
通过 Linux 基金会和 edX 的免费[" Linux 简介"][4]课程了解有关 Linux 的更多信息。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linux.com/blog/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts-part-2
|
||||
|
||||
作者:[Paul Brown][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.linux.com/users/bro66
|
||||
[1]:https://www.linux.com/blog/learn/2018/5/manipulating-directories-linux
|
||||
[2]:https://www.linux.com/learn/intro-to-linux/2018/7/users-groups-and-other-linux-beasts
|
||||
[3]:https://www.linux.com/learn/understanding-linux-file-permissions
|
||||
[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux
|
@ -0,0 +1,62 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (zhs852)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (Take a break at the Linux command line with Nyan Cat)
|
||||
[#]: via: (https://opensource.com/article/18/12/linux-toy-nyancat)
|
||||
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
|
||||
[#]: url: ( )
|
||||
|
||||
在 Linux 命令行中观看 Nyan Cat 来稍适休息
|
||||
======
|
||||
> 你甚至可以在终端里欣赏彩虹猫。
|
||||
|
||||

|
||||
|
||||
今天是《Linux 命令行小玩具介绍》的第六天。在本系列文章中,我们将会探索一些娱乐用途(甚至有时完全没用)的 Linux 命令行小玩具。所有我们介绍的小玩具都是开源的。
|
||||
|
||||
也许你会问,他们都很独特吗?是的。不过,他们对你是否独特,我就不知道了。但是,我们相信你应该能在这系列文章结束之前找到至少一个好玩的玩具。
|
||||
|
||||
从[昨天的选题][1]继续:我们谈到了猫和彩虹。不过,在 Linux 命令行下有更有趣的彩虹和猫结合的程序吗?答案是肯定的。
|
||||
|
||||
我们不妨看看之前可以在命令行中使用 Nyan Cat 的方式吧。意料之中,2011 年发布的 [Nyan Cat][2] 可以用 **nyancat** 呈现在终端中。你想念这只曾火遍网络的 Nyan Cat 吗?看看下面这个视频记录吧,我会等你看完的。
|
||||
|
||||
<https://www.youtube.com/embed/QH2-TGUlwu4>
|
||||
|
||||
现在,让我们在终端中重新感受这个令人惊奇的体验吧。**Nyancat** 包正在很多地方被分发(比如 Arch、Debian、Gentoo、Ubuntu 等等…),不过我的系统(Fedora)没有,但是我们仍然可以很轻松地从源码编译它。事实上,我们只需要一行命令就能做完所有工作:
|
||||
|
||||
```
|
||||
git clone https://github.com/klange/nyancat.git && cd nyancat && make && cd src && ./nyancat
|
||||
```
|
||||
|
||||
这直接为我带来了一个 Nyan Cat 体验,甚至还有个计时器来显示我享受 “Nyan Cat 魔法”的时间。
|
||||
|
||||

|
||||
|
||||
你可以在 [GitHub][3] 上找到 **nyancat** 的源码,它正以 [NCSA 许可证][4] 开源。
|
||||
|
||||
命令行版本的 Nyan Cat 可在[这个公共 Telnet 服务器上访问][5](或者 [netcat][6] 也行),所以理论上来说你不必安装它。不过不幸的是,由于带宽限制,该服务器目前已经被关闭了。尽管如此,在各种老设备上连接老 Telnet 服务器上运行 Nyan Cat 的[照片][5]还是值得一看的,说不准你还会萌生搭建一个能让大家连接的公共服务器的想法呢(如果你真的搭建了,请务必告知作者,万一他们可能会向公众分享呢?)。
|
||||
|
||||
你想让我介绍一下你最喜爱的命令行玩具吗?请在原文下留言,作者会考虑介绍的。
|
||||
|
||||
瞧瞧我们昨天介绍的小玩意:[用 lolcat 为你的 Linux 终端增添些许色彩][1]。明天再来看我们的下一篇文章吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/12/linux-toy-nyancat
|
||||
|
||||
作者:[Jason Baker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[zhs852](https://github.com/zhs852)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jason-baker
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/article/18/12/linux-toy-lolcat
|
||||
[2]: https://en.wikipedia.org/wiki/Nyan_Cat
|
||||
[3]: https://github.com/klange/nyancat
|
||||
[4]: http://en.wikipedia.org/wiki/University_of_Illinois/NCSA_Open_Source_License
|
||||
[5]: http://nyancat.dakko.us/
|
||||
[6]: http://netcat.sourceforge.net/
|
@ -7,22 +7,22 @@
|
||||
[#]: via: (https://www.2daygeek.com/how-to-install-rust-programming-language-in-linux/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
|
||||
How To Install Rust Programming Language In Linux
|
||||
如何在 Linux 中安装 Rust 编程语言
|
||||
======
|
||||
|
||||
Rust is often called rust-lang.
|
||||
Rust 通常被称为 rust-lang。
|
||||
|
||||
Rust is a general-purpose, multi-paradigm, modern, cross-platform, and open source systems programming language sponsored by Mozilla Research.
|
||||
Rust 是一个由 Mozilla Research 赞助的通用、多范式、现代、跨平台和开源系统编程语言。
|
||||
|
||||
It was designed to be achieve a goals such as safety, speed, and concurrency.
|
||||
它旨在实现安全性、速度和并发性等目标。
|
||||
|
||||
Rust is syntactically similar to C++,[14] but its designers intend it to provide better memory safety while still maintaining performance.
|
||||
Rust 在语法上与 C++ 相似,但它的设计者希望它在保持性能的同时提供更好的内存安全性。
|
||||
|
||||
Rust is currently used in many organization such as Firefox, Chef, Dropbox, Oracle, GNOME, etc,.
|
||||
Rust 目前在许多组织中使用,例如 Firefox、Chef、Dropbox、Oracle、GNOME 等。
|
||||
|
||||
### How to Install Runs Language in Linux?
|
||||
### 如何在 Linux 中安装 Rust 语言?
|
||||
|
||||
There are many ways we can install Rust but below is the officially recommended way to install it.
|
||||
我们可以通过多种方式安装 Rust,但以下是官方推荐的安装方式。
|
||||
|
||||
```
|
||||
$ curl https://sh.rustup.rs -sSf | sh
|
||||
@ -85,22 +85,22 @@ environment variable. Next time you log in this will be done automatically.
|
||||
To configure your current shell run source $HOME/.cargo/env
|
||||
```
|
||||
|
||||
Run the following command to configure your current shell.
|
||||
运行以下命令配置当前 shell。
|
||||
|
||||
```
|
||||
$ source $HOME/.cargo/env
|
||||
```
|
||||
|
||||
Run the following command to verify the installed Rust version.
|
||||
运行以下命令验证已安装的 Rust 版本。
|
||||
|
||||
```
|
||||
$ rustc --version
|
||||
rustc 1.31.0 (abe02cefd 2018-12-04)
|
||||
```
|
||||
|
||||
### How To Test Rust programming language?
|
||||
### 如何测试 Rust 编程语言?
|
||||
|
||||
Once you installed Rust follow the below steps to check whether Rust programe language is working fine or not.
|
||||
安装 Rust 后,请按照以下步骤检查 Rust 语言是否正常工作。
|
||||
|
||||
```
|
||||
$ mkdir ~/projects
|
||||
@ -109,7 +109,7 @@ $ mkdir hello_world
|
||||
$ cd hello_world
|
||||
```
|
||||
|
||||
Create a file and add the below code and save the file. Make sure, Rust files always end in a .rs extension.
|
||||
创建一个文件并添加以下代码并保存。确保 Rust 文件始终以 .rs 扩展名结尾。
|
||||
|
||||
```
|
||||
$ vi 2g.rs
|
||||
@ -119,13 +119,13 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
Run the following command to compile the rust code.
|
||||
运行以下命令编译 rust 代码。
|
||||
|
||||
```
|
||||
$ rustc 2g.rs
|
||||
```
|
||||
|
||||
The above command will create a executable Rust program file in the same directory.
|
||||
上面的命令将在同一目录中创建一个可执行的 Rust 程序。
|
||||
|
||||
```
|
||||
$ ls -lh
|
||||
@ -134,16 +134,16 @@ total 3.9M
|
||||
-rw-r--r-- 1 daygeek daygeek 86 Dec 14 11:09 2g.rs
|
||||
```
|
||||
|
||||
Run the Rust executable file to get the output.
|
||||
运行 Rust 可执行文件得到输出。
|
||||
|
||||
```
|
||||
$ ./2g
|
||||
Hello, It's 2DayGeek.com - Best Linux Practical Blog!
|
||||
```
|
||||
|
||||
Yup! that’s working fine.
|
||||
好了!正常工作了。
|
||||
|
||||
To update Rust to latest version.
|
||||
将 Rust 更新到最新版本。
|
||||
|
||||
```
|
||||
$ rustup update
|
||||
@ -153,13 +153,13 @@ info: checking for self-updates
|
||||
stable-x86_64-unknown-linux-gnu unchanged - rustc 1.31.0 (abe02cefd 2018-12-04)
|
||||
```
|
||||
|
||||
Run the following command to remove the Rust package from your system.
|
||||
运行以下命令从系统中删除 Rust 包。
|
||||
|
||||
```
|
||||
$ rustup self uninstall
|
||||
```
|
||||
|
||||
Once you uninstalled the Rust package, remove the Rust project directory.
|
||||
卸载 Rust 包后,删除 Rust 项目目录。
|
||||
|
||||
```
|
||||
$ rm -fr ~/projects
|
||||
@ -170,10 +170,10 @@ via: https://www.2daygeek.com/how-to-install-rust-programming-language-in-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
||||
[b]: https://github.com/lujun9972
|
Loading…
Reference in New Issue
Block a user