mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
71be828daf
128
published/20200622 7 open source alternatives to VS Code.md
Normal file
128
published/20200622 7 open source alternatives to VS Code.md
Normal file
@ -0,0 +1,128 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (nophDog)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12382-1.html)
|
||||
[#]: subject: (7 open source alternatives to VS Code)
|
||||
[#]: via: (https://opensource.com/article/20/6/open-source-alternatives-vs-code)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
VS Code 的 7 个开源替代品
|
||||
======
|
||||
|
||||
> 为了避免使用微软版本的 VS Code,我们需要另行选择一个开源的代码编辑器。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202007/05/112348n834svpa48v08vsa.png)
|
||||
|
||||
Visual Studio Code,也叫 VS Code,是一个跨平台代码编辑器,通用于 Linux、Windows 以及 macOS。它既能编辑简单文本,也能像集成开发环境(IDE)一样管理整个代码库。它可以通过插件进行扩展,并且已经被证明是一个可靠的文本编辑器,很轻松地就击败了非开源的强大竞品编辑器。
|
||||
|
||||
微软以开源的方式发布了 VS Code,但是你从微软下载的版本其实并不是开源的。然而,你仍有办法以开源的方式使用 VS Code,或者直接选择其它的开源替代品。
|
||||
|
||||
### 以开源的方式构建 VS Code
|
||||
|
||||
你可以在 [GitHub][2] 获得 VS Code 的源代码。然而当你 [从微软][3] 下载 VS Code 时,你会发现它是基于 [微软软件许可证][4] 授权的。这并不是一个开源许可证。其区别在于构建过程。
|
||||
|
||||
Chris Dias 是微软 VS Code 项目开发者之一,他对 VS Code [作了一个对比][5],就像 Chrome 浏览器和其开源的“上游”项目 [Chromium][6] 一样。VS Code 确实是基于开源代码库构建的。微软官方发布的版本带有一些与微软相关的功能,包括一项商标、一个插件库、一个 C# 调试器以及遥测。但如果你克隆仓库然后自行编译,这些东西都不会被加入,所以你会得到一个名为 Code - OSS 的“干净”版本(OSS 代表开源软件)。
|
||||
|
||||
实际上,VS Code 与 Code - OSS 之间的差异很小。最值得注意的是,VS Code 包含遥测功能,它会记录使用数据。微软不可能监控你的一举一动,而且目前越来越多软件都在收集使用数据。是否在乎 VS Code 的遥测功能,完全取决于你自己。如果你不希望它追踪你的使用情况,这里有一些很棒的 VS Code(开源)替代品。
|
||||
|
||||
### VSCodium
|
||||
|
||||
![Code OSS screenshot][7]
|
||||
|
||||
最简单的替代方案就是构建不带微软附属功能的 VS Code 版本。[VSCodium][9] 项目提供了可下载的 Code-OSS 可执行文件,它基于 VS Code 代码库编译,没有配置微软的 `product.json` 中的改变。VSCodium 的开发者还竭尽全力禁用了所有难以寻找的遥测选项,除非你自行编译,否则这已经是你能找到的最干净的 VS Code 版本了。
|
||||
|
||||
VSCodium 提醒说,VS Code 悄悄地包含了一些专有工具,这些工具无法与开源版本一起提供。这包括一个 C# 调试器和部分插件。如果你需要它们,可以在 [文档中] 找到解决办法。假如你依赖 VS Code 中某些特定的功能,你应该验证它在 VSCodium 中是否可以发挥功用。
|
||||
|
||||
此外,你还应该验证是否已禁用所有的遥测功能。
|
||||
|
||||
### Code - OSS
|
||||
|
||||
如果不想用 VSCodium 的版本,你可以自己 [从头编译 VS Code][12],得到一样的版本。可执行文件叫做 `Code - OSS`,而不是 `VSCode`,适用于 VSCodium 的许可证限制也适用于你的构建,而工作方式也是一样。
|
||||
|
||||
如果通过编译源码构建应用,首次启动时你要确保 [所有遥测都已经被禁用]。
|
||||
|
||||
### Atom
|
||||
|
||||
![Atom screenshot][13]
|
||||
|
||||
[Atom][14] 是一个类似于 IDE 的文本编辑器,当微软收购 Github 的同时也收购了它。和 VS Code 一样,你可以使用插件,扩展 Atom 编辑器,此外,你还能通过自己的工具和主题实现定制。它开源且与 Github 集成。简而言之,只要你能找到你想用的插件,或者你愿意自己动手写,那么 Atom 几乎可以满足你的一切需求。
|
||||
|
||||
跟 VS Code 一样,Atom 也 [默认包含遥测][15]。你可以禁用这个功能,而且跟 VS Code 不同的是,使用插件不受任何限制,所以不必再因为隐私改变你的工作流。对写代码的人来说,毫无疑问 Atom 是很有用的工具,而对于 [使用电脑的任何人][16],它同样会是一个很赞的编辑器。如果你需要一个顺手的通用文本编辑器,请试试 Atom。
|
||||
|
||||
### GNOME Builder
|
||||
|
||||
![GNOME Builder screenshot][17]
|
||||
|
||||
为 GNOME 桌面而开发的 IDE,[GNOME Builder][18] 是一个 Linux 平台的代码编辑器,专门用于构建 GNOME 应用。如果你为 Linux 构建应用程序,希望轻松解决兼容性问题,那么 Builder 就是最简单的选择。从 [Flathub.org][19] 安装 Builder;当你开启一个新项目,如果没有安装 GNOME SDK,它会提醒你。这意味着当维护你的应用时,你不必刻意关注 GNOME 的状态,因为 Builder 在替你做这件事。
|
||||
|
||||
然而,Builder 不仅能构建 GNOME 程序。它还支持各种各样的编程语言,包括 Python、Rust、C/C++、Java、Go、JavaScript、TypeScript、VB.NET、Markdown 和几种标记语言等等。它对部分语言有全面的支持,包括自动补全以及弹出式函数定义,但是其它语言仅仅含有一些比较方便的功能,例如语法高亮跟自动匹配括号。不管你是不是一个专门的程序员,或者你只想要一个给力的 HTML 和 CSS 编辑器,这个 IDE 都能让你舒心使用。
|
||||
|
||||
### Geany
|
||||
|
||||
![Geany screenshot][20]
|
||||
|
||||
[Geany][21] 是一个强大、稳定而轻量级的编辑器,它有很多有用的特性,能帮你写 Bash、Python、Lua、XML、HTML、LaTex,当然远不止这些。对 50 种各种编程及脚本语言、标记语言和各种文件类型(比如 .diff 和 .po),Geany 都有很好的支持。退一万步讲,Geany 还有括号匹配和语法高亮 —— 通常来说,它包含更多功能。
|
||||
|
||||
Geany 是一个小型编辑器,但是通过插件,你可以为它添加特性,例如项目视图面板、文件系统树、调试、终端等,直到它看起来像一个 IDE。当然,萝卜白菜各有所爱,你也可以尽量使它保持简洁易用。如果因为电脑 CPU 或者内存的限制而无法使用 VS Code,那么很明显 Geany 可以作为你的选择。它只占用少量内存,而且启动迅速。即便跟运行在终端里的 Vim 相比,Geany 稍显笨重,但就算在树莓派,它也能做到快速、灵活。
|
||||
|
||||
### Brackets
|
||||
|
||||
![Brackets screenshot][22]
|
||||
|
||||
[Brackets][23] 是一款面向网页开发者的文本编辑器和 IDE。对于 HTML、CSS、JavaScript、PHP 甚至 Python,它都有很强大的支持。而且跟 VS Code 一样,它也有一个很丰富的插件生态,所以你可以最大限度地扩展它,以适应你所有编程语言的工作。
|
||||
|
||||
有的插件用于辅助解析语言、运行脚本,甚至编译执行代码。Brackets 有一个传统的界面,不管你是否熟悉 IDE 或者像记事本一样简单的文本编辑器,都能驾轻就熟。如果稍微花点时间,添加几个相关插件,然后熟悉它们,你会发现 Brackets 真的是一个很精妙、很有用的编辑器,不管你输入什么,它都能通过自动补全、提示帮你避免低级错误。假如你是程序员,它能帮你加快测验和调试周期。
|
||||
|
||||
### Che
|
||||
|
||||
![Che screenshot][24]
|
||||
|
||||
如果你喜欢新技术,那你应当尝试 [Che][25] 编辑器。这是一个基于云的 IDE,所以它默认以软件即服务(SaaS)的形式运行,但它是完全开源的,如果你有 Kubernetes 实例,那就可以运行为*你自己的* SaaS。
|
||||
|
||||
Che 不仅是一个在线 IDE,而且是一个为云开发而构建的 IDE。在 Che 的概念里,用户无需查看本地文件系统。由于它在云端工作,所以你也可以这么做。事实上,如果你有一台 Git 服务器,那就可以直接把它当作你的文件系统,在它的仓库中完成你的项目。当然,你也可以下载所有文件做本地备份。
|
||||
|
||||
但 Che 的主要特点,也是云开发者最为兴奋的一点,它是一个功能全面、带有 Kubernetes 感知功能的开源 IDE。如果你正在为云构建应用、网站或容器(或三者的组合),那么 Che 是一个你需要尝试的编辑器。
|
||||
|
||||
### 那么你的选择是?
|
||||
|
||||
你有没有在使用这些 VS Code 替代品中的某一个呢?想不想挑一个试试呢?欢迎在评论中分享你的见解。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[nophDog](https://github.com/nophDog)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/laptop_screen_desk_work_chat_text.png?itok=UXqIDRDD (Person using a laptop)
|
||||
[2]: https://github.com/microsoft/vscode
|
||||
[3]: https://code.visualstudio.com/
|
||||
[4]: https://code.visualstudio.com/license
|
||||
[5]: https://github.com/Microsoft/vscode/issues/60#issuecomment-161792005
|
||||
[6]: https://www.chromium.org/
|
||||
[7]: https://opensource.com/sites/default/files/uploads/code-oss.png (Code OSS screenshot)
|
||||
[8]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[9]: https://vscodium.com/
|
||||
[10]: https://github.com/VSCodium/vscodium/blob/master/DOCS.md
|
||||
[11]: https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting
|
||||
[12]: https://github.com/Microsoft/vscode/wiki/How-to-Contribute#build-and-run
|
||||
[13]: https://opensource.com/sites/default/files/uploads/atom.jpg (Atom screenshot)
|
||||
[14]: http://atom.io
|
||||
[15]: https://discuss.atom.io/t/how-do-i-disable-the-metrics-or-tracking/24520
|
||||
[16]: https://opensource.com/article/19/4/write-git
|
||||
[17]: https://opensource.com/sites/default/files/uploads/builder.png (GNOME Builder screenshot)
|
||||
[18]: https://wiki.gnome.org/Apps/Builder
|
||||
[19]: https://flathub.org/apps/details/org.gnome.Builder
|
||||
[20]: https://opensource.com/sites/default/files/uploads/geany.png (Geany screenshot)
|
||||
[21]: https://www.geany.org/
|
||||
[22]: https://opensource.com/sites/default/files/uploads/brackets.jpg (Brackets screenshot)
|
||||
[23]: http://brackets.io/
|
||||
[24]: https://opensource.com/sites/default/files/uploads/che-cpp.jpg (Che screenshot)
|
||||
[25]: https://www.eclipse.org/che/extend/
|
@ -1,20 +1,21 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12381-1.html)
|
||||
[#]: subject: (Make Bash history more useful with these tips)
|
||||
[#]: via: (https://opensource.com/article/20/6/bash-history-control)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
这些技巧让 Bash history 更加有用
|
||||
这些技巧让 Bash 命令历史更加有用
|
||||
======
|
||||
告诉 Bash 你想要它记住什么,甚至删除不需要的记录重写历史。
|
||||
![A person programming][1]
|
||||
|
||||
> 告诉 Bash 你想要它记住什么,甚至删除不需要的记录重写历史。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202007/05/091205hkg0egl2gge2gx9z.jpg)
|
||||
|
||||
运行 [Bash][2] 的 Linux 终端有内置的历史记录,你可以用来跟踪最近的操作。要查看你的 Bash 会话的历史记录,请使用内置命令 `history`:
|
||||
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
foo
|
||||
@ -28,7 +29,6 @@ $ history
|
||||
|
||||
与大多数命令不一样,`history` 命令不是文件系统上的可执行文件,而是 Bash 的功能。你可以使用 `type` 命令来验证:
|
||||
|
||||
|
||||
```
|
||||
$ type history
|
||||
history is a shell builtin
|
||||
@ -36,23 +36,20 @@ history is a shell builtin
|
||||
|
||||
### 历史控制
|
||||
|
||||
shell 历史记录的行数上限由 `HISTSIZE` 变量定义。你可以在 .bashrc 文件中设置此变量。以下将你的历史记录设置为 3,000 行,之后将最早的行删除以为最新命令腾出空间,该命令位于列表的底部:
|
||||
|
||||
shell 历史记录的行数上限由 `HISTSIZE` 变量定义。你可以在 `.bashrc` 文件中设置此变量。以下将你的历史记录设置为 3,000 行,之后将最早的行删除以为最新命令腾出空间,该命令位于列表的底部:
|
||||
|
||||
```
|
||||
`export HISTSIZE=3000`
|
||||
export HISTSIZE=3000
|
||||
```
|
||||
|
||||
还有其他与历史相关的变量。 `HISTCONTROL` 变量控制哪些历史被记录。你可以在 `.bashrc` 中写入下面的行来强制 Bash 排除以空格开头的命令:
|
||||
|
||||
|
||||
```
|
||||
`export HISTCONTROL=$HISTCONTROL:ignorespace`
|
||||
export HISTCONTROL=$HISTCONTROL:ignorespace
|
||||
```
|
||||
|
||||
现在,如果你输入以空格开头的命令,那么它将不会记录在历史记录中:
|
||||
|
||||
|
||||
```
|
||||
$ echo "hello"
|
||||
$ mysql -u bogus -h badpassword123 mydatabase
|
||||
@ -65,14 +62,12 @@ $ history
|
||||
|
||||
你也可以避免重复的条目:
|
||||
|
||||
|
||||
```
|
||||
`export HISTCONTROL=$HISTCONTROL:ignoredups`
|
||||
export HISTCONTROL=$HISTCONTROL:ignoredups
|
||||
```
|
||||
|
||||
现在,如果你一个接着一个输入两个命令,历史记录中只会显示一个:
|
||||
|
||||
|
||||
```
|
||||
$ ls
|
||||
$ ls
|
||||
@ -82,18 +77,16 @@ $ history
|
||||
2 history
|
||||
```
|
||||
|
||||
如果你喜欢这两个忽略,那么可以使用 `ignoreboth`:
|
||||
|
||||
如果你喜欢这两个忽略功能,那么可以使用 `ignoreboth`:
|
||||
|
||||
```
|
||||
`export HISTCONTROL=$HISTCONTROL:ignoreboth`
|
||||
export HISTCONTROL=$HISTCONTROL:ignoreboth
|
||||
```
|
||||
|
||||
### 从历史记录中删除命令
|
||||
|
||||
有时你会犯一个错误,在 shell 中输入了一些敏感内容,或者你只是想清理历史记录,以便它更准确地表示让某件事正常工作所采取的步骤。如果要从 Bash 的历史记录中删除命令,请在要删除的项目的行号上使用 `-d` 选项:
|
||||
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
foo
|
||||
@ -111,8 +104,7 @@ $ history | tail
|
||||
538 history | tail
|
||||
```
|
||||
|
||||
要停止添加 `history` 条目,只要在 `HISTCONTROL` 环境变量中有 `ignorespace`,就可以在命令前添加`空格`:
|
||||
|
||||
要停止添加 `history` 条目,只要在 `HISTCONTROL` 环境变量中有 `ignorespace`,就可以在命令前添加空格:
|
||||
|
||||
```
|
||||
$ history | tail
|
||||
@ -123,8 +115,7 @@ $ history | tail
|
||||
535 echo "foo"
|
||||
```
|
||||
|
||||
你可以使用 -c 选项清除所有会话历史记录:
|
||||
|
||||
你可以使用 `-c` 选项清除所有会话历史记录:
|
||||
|
||||
```
|
||||
$ history -c
|
||||
@ -132,9 +123,9 @@ $ history
|
||||
$
|
||||
```
|
||||
|
||||
### history 命令教训
|
||||
### history 命令的经验
|
||||
|
||||
操纵历史通常没有听起来那么危险,尤其是当你有目标地管理它时。例如,如果你要记录一个复杂的问题,通常最好使用会话历史来记录命令,因为通过将命令插入历史记录,你能运行它们并从而测试过程。很多时候,不执行历史命令会导致忽略小的步骤或写错小细节。。
|
||||
操纵历史通常没有听起来那么危险,尤其是当你有目标地管理它时。例如,如果你要记录一个复杂的问题,通常最好使用会话历史来记录命令,因为通过将命令插入历史记录,你能运行它们并从而测试过程。很多时候,不执行历史命令会导致忽略小的步骤或写错小细节。
|
||||
|
||||
按需使用历史会话,并明智地控制历史记录。享受历史修改吧!
|
||||
|
||||
@ -145,7 +136,7 @@ via: https://opensource.com/article/20/6/bash-history-control
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -0,0 +1,51 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12384-1.html)
|
||||
[#]: subject: (An open source browser extension to zoom in on images)
|
||||
[#]: via: (https://opensource.com/article/20/6/hoverzoom)
|
||||
[#]: author: (Jeff Macharyas https://opensource.com/users/jeffmacharyas)
|
||||
|
||||
一个可放大图像的开源的浏览器扩展
|
||||
======
|
||||
|
||||
> 想细看网络图像并不总是那么简单,但是 Hover Zoom+ 让它像鼠标滑动一样容易。
|
||||
|
||||
![Digital images of a computer desktop][1]
|
||||
|
||||
你是否曾经在访问网站时希望查看更大的图像?我经常遇到这种情况,而要做到这点并不总是那么容易。
|
||||
|
||||
有时,我在源码中筛选,使用 `Ctrl + F` 搜索图像,复制图像源地址并将其粘贴到新窗口中,以便以全尺寸查看图像。或者,另一个选择是右键单击,复制图像地址,然后粘贴到新选项卡中。
|
||||
|
||||
![Example image source code ][2]
|
||||
|
||||
Hover Zoom+ 让这个过程更加简单。Hover Zoom+ 是一个简单 Chrome 扩展程序,在 MIT 许可证下发布,可在 Chrome 商店中找到,它的源码可在 [GitHub][3] 上获得。它也适用于 Firefox。
|
||||
|
||||
这个应用使得该过程更加容易。只需将鼠标悬停在图像上,你将看到一个弹出窗口来显示该图像的全部内容,它会匹配你的浏览器窗口,无论图像是否被裁剪(或者图像尺寸适当,它看上去会是一样的)。这可能很有趣,因为有时可能会裁剪原始图像,以适应空间或聚焦于图像的特定部分。但是,你无法右键单击并直接从弹出窗口中保存图像。
|
||||
|
||||
根据加州圣何塞的开发人员 Oleg Anashkin 的说法,“这是原始 HoverZoom 扩展的开源版本,现已被恶意软件所占领,并被从商店中删除。在此版本中,所有间谍软件均已删除,许多 bug 已被修复,并添加了新功能。它默认不会收集任何统计信息。”
|
||||
|
||||
我在 Windows 10 笔记本上的 Chrome 中安装了此扩展,然后试用了一下。安装扩展后,我将鼠标悬停在图像上,它在弹出窗口中显示了比实际更大的图像。
|
||||
|
||||
但是,Hover Zoom+ 不适用于所有网站或所有图像。它适用于 Facebook 和 Twitter,但不适用于这些网站上的赞助内容。用户可以轻松切换该应用以针对特定站点启用或禁用它。使用 Hover Zoom+ 可以很容易地看到 Instagram 上的这只可爱小猫而无需实际阅读帖子(方便!):
|
||||
|
||||
![Zoomed-in image of a kitten from Facebook][4]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/hoverzoom
|
||||
|
||||
作者:[Jeff Macharyas][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jeffmacharyas
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_browser_web_desktop.png?itok=Bw8ykZMA (Digital images of a computer desktop)
|
||||
[2]: https://opensource.com/sites/default/files/uploads/source.jpg (Example image source code)
|
||||
[3]: https://github.com/extesy/hoverzoom/
|
||||
[4]: https://opensource.com/sites/default/files/uploads/fb-cat.jpg (HoverZoom+ enlarged image)
|
@ -1,21 +1,22 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (nophDog)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12385-1.html)
|
||||
[#]: subject: (Read and write data from anywhere with redirection in the Linux terminal)
|
||||
[#]: via: (https://opensource.com/article/20/6/redirection-bash)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
通过重定向在 Linux 终端任意读写
|
||||
通过重定向在 Linux 终端任意读写数据
|
||||
======
|
||||
重定向是一种十分高效的数据流动方式,它能帮你减少很多鼠标和键盘上的操作。
|
||||
![Hands programming][1]
|
||||
|
||||
> 重定向是一种十分高效的数据流动方式,它能帮你减少很多鼠标和键盘上的操作。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202007/06/005419nh6mzxkmmmbsslbb.jpg)
|
||||
|
||||
对于任何编程或脚本语言,输入与输出重定向都是很自然的功能。严格来说,当你使用电脑时,数据自然而然地在发生着重定向。从 `stdin`(标准输入,通常是你的键盘或者鼠标)读取输入,输入则发往 `stdout`(标准输出,一段文本或者数据流),最后错误信息送至 `stderr`。如果你使用 [Bash][2] 或 [Zsh][3] 之类的 shell,那么理解这些数据流能够让你更好地控制信息流向。
|
||||
|
||||
标准输入,标准输出以及标准错误输出存在于 Linux 文件系统中。你可以在 `/dev` 查看:
|
||||
|
||||
标准输入、标准输出以及标准错误输出都存在于 Linux 文件系统中。你可以在 `/dev` 查看:
|
||||
|
||||
```
|
||||
$ ls /dev/std*
|
||||
@ -30,38 +31,34 @@ $ ls /dev/std*
|
||||
|
||||
将 [ls][4] 命令的输出写入一个文件:
|
||||
|
||||
|
||||
```
|
||||
`$ ls > list.txt`
|
||||
$ ls > list.txt
|
||||
```
|
||||
|
||||
你没法像平常那样看到 `ls` 的输出,因为它们并没有被发送到屏幕,而是被写入 `list.txt` 文件了,这个功能用处太多了,事实上,你甚至可以用它来将文件内容拷贝到另一个文件。不一定是文本文件,你也可以用将重定向用于二进制数据:
|
||||
|
||||
|
||||
```
|
||||
`$ cat image.png > picture.png`
|
||||
$ cat image.png > picture.png
|
||||
```
|
||||
|
||||
你可能会好奇为什么要这样做,有时候用来获取 [文件权限信息][5] 比较实用。
|
||||
(你可能会好奇为什么要这样做,有时候对于 [文件权限信息][5] 而间接有用。)
|
||||
|
||||
### 重定向输入
|
||||
|
||||
你也能将输入重定向“到”一个命令。可以说,它没有重定向输出那么有用,因为许多命令已经被硬编码,只从你的参数中接收输入。但是,如果某个命令需要一系列参数,而且你把这些参数写在文件里,想要快速“复制粘贴”到终端的时候(除非你并不想复制粘贴),它就帮得上忙了。
|
||||
|
||||
|
||||
```
|
||||
`$ sudo dnf install $(<package.list)`
|
||||
$ sudo dnf install $(<package.list)
|
||||
```
|
||||
|
||||
重定向输入得常规用法是 **here-document** (简写成 **here-doc**) 和 **here-string** 技巧。这种输入方法将一整块文本重定向至标准输入流,直到碰见一个特殊的 end-of-file 标记(许多人习惯用 `EOF`,实际上你可以使用任何字符串,只要它是唯一的)。试着把这些(在第二个 `EOF` 标记之前)敲进你的终端:
|
||||
|
||||
重定向输入得常规用法是<ruby>嵌入文档<rt>here-document</rt></ruby>(简写成 here-doc)和<ruby>嵌入字符串<rt>here-string</rt></ruby> 技巧。这种输入方法将一整块文本重定向至标准输入流,直到碰见一个特殊的文件结束标记(许多人习惯用 `EOF`,实际上你可以使用任何字符串,只要它是唯一的)。试着把这些(在第二个 `EOF` 标记之前)敲进你的终端:
|
||||
|
||||
```
|
||||
$ echo << EOF
|
||||
> foo
|
||||
> bar
|
||||
> baz
|
||||
> EOF
|
||||
$ echo << EOF
|
||||
> foo
|
||||
> bar
|
||||
> baz
|
||||
> EOF
|
||||
```
|
||||
|
||||
输出结果:
|
||||
@ -72,13 +69,12 @@ bar
|
||||
baz
|
||||
```
|
||||
|
||||
使用 [Bash][2] 编写脚本的人常常用这个技巧,将数行文本一次性写入文件或者打印到屏幕上。只要你别忘了末尾的 end-of-file 标记,这会是一个帮你避免大量繁琐 `echo` 或 `printf` 语句的好办法。
|
||||
|
||||
一句 **here-string** 类似于一段 **here-doc**,但是它只含有一个字符串(或者用引号包裹的几个字符串,同样会被当成一个字符串)
|
||||
使用 [Bash][2] 编写脚本的人常常用这个技巧,将数行文本一次性写入文件或者打印到屏幕上。只要你别忘了末尾的文件结束标记,这会是一个帮你避免大量繁琐 `echo` 或 `printf` 语句的好办法。
|
||||
|
||||
嵌入字符串类似于嵌入文档,但是它只含有一个字符串(或者用引号包裹的几个字符串,同样会被当成一个字符串)
|
||||
|
||||
```
|
||||
$ cat <<< "foo bar baz"
|
||||
$ cat <<< "foo bar baz"
|
||||
foo bar baz
|
||||
```
|
||||
|
||||
@ -87,16 +83,15 @@ foo bar baz
|
||||
错误信息流叫做 `stderr`,通过 `2>` 实现这个目的。下面这个命令把错误信息定向到 `output.log` 文件:
|
||||
|
||||
```
|
||||
`$ ls /nope 2> output.log`
|
||||
$ ls /nope 2> output.log
|
||||
```
|
||||
|
||||
### 将数据送往 /dev/null
|
||||
|
||||
既然标准输入、标准输出和错误输出都有自己的位置,那么 _nowhere_ 也应该在 Linux 文件系统占有一席之地。没错,它叫做 `null`,位于 `/dev`,频繁使用的人懒得说 `slash dev slash null`,于是索性叫它 "devnull"。
|
||||
既然标准输入、标准输出和错误输出都有自己的位置,那么“空空如也”也应该在 Linux 文件系统占有一席之地。没错,它叫做 `null`,位于 `/dev`,频繁使用的人懒得说 “slash dev slash null”,于是索性叫它 “devnull”。
|
||||
|
||||
通过重定向,你可以把数据发送到 `/dev/null`。比如,`find` 命令常常会输出很多具体信息,而且在搜索文件遇到权限冲突时,会事无巨细地报告:
|
||||
|
||||
|
||||
```
|
||||
$ find ~ -type f
|
||||
/home/seth/actual.file
|
||||
@ -110,7 +105,7 @@ find: `/home/seth/soggy': Permission denied
|
||||
|
||||
|
||||
```
|
||||
$ find ~ -type f 2> /dev/null
|
||||
$ find ~ -type f 2>; /dev/null
|
||||
/home/seth/actual.file
|
||||
/home/seth/zzz.file
|
||||
```
|
||||
@ -125,8 +120,8 @@ via: https://opensource.com/article/20/6/redirection-bash
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/nophDog)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
译者:[nophDog](https://github.com/nophDog)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,138 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (nophDog)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (7 open source alternatives to VS Code)
|
||||
[#]: via: (https://opensource.com/article/20/6/open-source-alternatives-vs-code)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
VS Code 的 7 个开源替代品
|
||||
======
|
||||
为了避免使用微软版本的 VS Code,我们需要另行选择一个开源的代码编辑器。
|
||||
![Person using a laptop][1]
|
||||
|
||||
Visual Studio Code,也叫 VS Code,是一个跨平台代码编辑器,通用于 Linux、Windows 以及 macOS。它既能编辑简单文本,也能像集成开发环境(IDE)一样管理整个代码库。基于插件,VS Code 有很强的扩展性,并且在市场上的地位足以证明,它的确是一个可靠的文本编辑器。
|
||||
|
||||
微软以开源的方式发布了 VS Code,但是你从微软那儿下载的版本其实并不开源。无论如何,你仍有办法以开源的方式使用 VS Code,或者直接选择其它的开源替代品。
|
||||
|
||||
### 以开源的方式构建 VS Code
|
||||
|
||||
你可以在 [GitHub](2) 获得 VS Code 的源代码。当你 [从微软][3] 那里下载 VS Code 后,你会发现它基于 [Microsoft Software License][4] 许可。这并不是一份开源许可。区别在于构建过程。
|
||||
|
||||
Chris Dias 是微软 VS Code 项目开发者之一,他在 VS Code 与 Chrome 浏览器和其开源的“上游”项目 [Chromium][6] 之间 [作了一个对比][5]。VS Code 确确实实是基于开源代码库构建的。微软官方发布的版本带有一些与微软相关的功能,包括一项商标、一个插件库,一个 C# 调试器以及遥测。但如果你克隆然后自行编译,这些东西都不会被加入,所以你得到了一个名为 Code 的“干净”版本 —— OSS(OSS 代表开源软件)。
|
||||
|
||||
实际上,VS Code 与 Code —— OSS 之间的差异很小。最值得注意的是,VS Code 包含遥测功能,它会记录软件数据。微软不可能监控你的一举一动,而且目前越来越多软件都在收集使用数据。在不在乎 VS Code 的遥测功能,完全取决于你自己。如果你不希望它追踪你的使用情况,这里有一些很棒的 VS Code (开源)替代品。
|
||||
|
||||
### VSCodium
|
||||
|
||||
![Code OSS screenshot][7]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
取代 VS Code 最简单的办法就是构建不带微软附属功能的版本。[VSCodium][9] 项目提供下载 Code 的二进制可执行文件 —— OSS,基于 VS Code 代码库编译,没有配置微软的 `product.json` 。VSCodium 的开发者还竭尽全力禁用了所有难以寻找的遥测选项,除非你自行编译,否则这已经是你能找到的最干净的 VS Code 版本。
|
||||
|
||||
VSCodium 提醒说,开源版本无法提供某些 VS Code 默认带有的专利工具。包括一个 C# 调试器和部分插件。如果你需要它们,可以在 [文档中] 找到解决办法,但是假如你依赖 VS Code 中某些特定的功能,请确保你同样能够在 VSCodium 中使用它们。
|
||||
|
||||
此外,你还得验证是否已禁用所有遥测功能。
|
||||
|
||||
### Code - OSS
|
||||
|
||||
如果不想用 VSCodium 的版本,你可以自己 [从头编译 VS Code][12],得到一样的版本。可执行文件叫做 `Code - OSS`,而不是 `VSCode`,
|
||||
|
||||
如果通过编译源码构建应用,你要确保第一次启动时 [所有遥测都已经被禁用]。
|
||||
|
||||
### Atom
|
||||
|
||||
![Atom screenshot][13]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
[Atom][14] 是一个类似于 IDE 的文本编辑器,当微软收购 Github 的同时也收购了它。和 VS Code 一样,你可以使用插件,扩展 Atom 编辑器,此外,你还能通过自己的工具和主题实现定制。它开源且与 Github 集成。简而言之,只要你能找到你想用的插件,或者你愿意自己动手写,那么 Atom 几乎可以满足你的一切需求。
|
||||
|
||||
跟 VS Code 一样,Atom 也 [默认包含遥测][15]。你可以禁用这个功能,而且跟 VS Code 不同的是,使用插件不受任何限制,所以不必再因为隐私改变你的工作流。对写代码的人来说,毫无疑问 Atom 是很有用的工具,而对于 [使用电脑的人][16],它同样会是一个很赞的编辑器。如果你需要一个顺手的通用编辑器,请试试 Atom。
|
||||
|
||||
### GNOME Builder
|
||||
|
||||
![GNOME Builder screenshot][17]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
为 GNOME 桌面开发的 IDE,[GNOME Builder][18] 是 Linux 平台的代码编辑器,专门用于构建 GNOME 应用。如果你为 Linux 构建应用程序,希望轻松解决兼容性问题,那么 Builder 就是最简单的选择。从 [Flathub.org][19] 安装 Builder;当你开启一个新项目,如果没有安装 GNOME SDK,它会提醒你。这意味着当维护你的应用时,你不必刻意关注 GNOME 的状态,因为 Builder 在替你做这件事。
|
||||
|
||||
然而,Builder 不仅能构建 GNOME 程序。它还支持各种各样的编程语言,包括 Python,Rust,C 和 C++,Java,Go,JavaScript,TypeScript,VB.NET,Markdown 和几种标记语言,甚至更多。它对部分语言有全面的支持,包括自动补全以及弹出式函数定义,但是其它语言仅仅含有一些比较方便的功能,例如语法高亮跟自动匹配括号。不管你是不是一个正经的程序员,或者你只想要一个给力的 HTML 和 CSS 编辑器,这个 IDE 都能让你舒心使用。
|
||||
|
||||
### Geany
|
||||
|
||||
![Geany screenshot][20]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
[Geany][21] 是一个强大、稳定却轻量的编辑器,它有很多有用的特性,能帮你写 Bash,Python,Lua,XML,HTML,LaTex,当然远不止这些。对 50 种不同的编程、脚本、标记语言和各种文件类型(比如 .diff 和 .po),Geany 都有很好的支持。退一万步讲,Geany 还有括号匹配和语法高亮 —— 通常来说,它包含更多功能。
|
||||
|
||||
Geany 是一个小型编辑器,但是通过插件,你可以为它添加特性,例如项目展示盘,文件系统树,调试,终端,等等,直到它看起来像一个 IDE。当然,萝卜白菜各有所爱,你也可以尽量使它保持简洁易用。如果因为电脑 CPU 或者内存的限制而无法使用 VS Code,那么很明显 Geany 可以作为你的选择。它只占用少量内存,而且启动迅速。即便跟运行在终端里的 Vim 相比,Geany 稍显笨重,但就算在树莓派,它也能做到快速、灵活。
|
||||
|
||||
### Brackets
|
||||
|
||||
![Brackets screenshot][22]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
[Brackets][23] 是面向网页开发者的文本编辑器和 IDE。对于 HTML,CSS,JavaScript,PHP 甚至 Python,它都有很强大的支持。而且跟 VS Code 一样,它也有一个很丰富的插件生态,所以你可以最大限度地扩展它,以适应你所有编程语言的工作。
|
||||
|
||||
有的插件用于辅助解析语言,运行脚本,甚至编译执行代码。Brackets 有一个通俗的传统界面,不管你是否熟悉 IDE 或者像记事本一样简单的文本编辑器,都能驾轻就熟。如果稍微花点时间,添加几个相关插件,然后熟悉它们,你会发现 Brackets 真的是一个很精妙、很有用的编辑器,不管你输入什么,它都能通过自动补全、提示帮你避免低级错误。假如你是程序员,它能帮你加快测验和调试周期。
|
||||
|
||||
### Che
|
||||
|
||||
![Che screenshot][24]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
如果你喜欢新技术,那你应当尝试 [Che][25] 编辑器。这是一个基于云的 IDE,所以它默认作为 Software as a Service(SaaS)运行,但它是完全开源的,如果你有 Kubernetes 实例,那就可以运行为_你自己的_ SaaS。
|
||||
|
||||
Che 不仅是一个线上 IDE,而且是一个为云开发而构建的 IDE。在 Che 的概念里,用户无需查看本地文件系统。由于它在云端工作,所以你也可以这么做。事实上,如果你有一台 Git 服务器,那就可以直接在它的仓库中把它当作你的文件系统,并完成你的项目。当然,你有权下载所有文件做本地备份。
|
||||
|
||||
但 Che 的主要特点,也是云开发者最为兴奋的一点,它是一个功能全面、带有 Kubernetes 感知功能的开源 IDE。
|
||||
|
||||
### 那么你的选择是?
|
||||
|
||||
你有没有在使用这些 VS Code 替代品中的某一个呢?想不想挑一个试试呢?欢迎在评论中分享你的见解。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/nophDog)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/laptop_screen_desk_work_chat_text.png?itok=UXqIDRDD (Person using a laptop)
|
||||
[2]: https://github.com/microsoft/vscode
|
||||
[3]: https://code.visualstudio.com/
|
||||
[4]: https://code.visualstudio.com/license
|
||||
[5]: https://github.com/Microsoft/vscode/issues/60#issuecomment-161792005
|
||||
[6]: https://www.chromium.org/
|
||||
[7]: https://opensource.com/sites/default/files/uploads/code-oss.png (Code OSS screenshot)
|
||||
[8]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[9]: https://vscodium.com/
|
||||
[10]: https://github.com/VSCodium/vscodium/blob/master/DOCS.md
|
||||
[11]: https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting
|
||||
[12]: https://github.com/Microsoft/vscode/wiki/How-to-Contribute#build-and-run
|
||||
[13]: https://opensource.com/sites/default/files/uploads/atom.jpg (Atom screenshot)
|
||||
[14]: http://atom.io
|
||||
[15]: https://discuss.atom.io/t/how-do-i-disable-the-metrics-or-tracking/24520
|
||||
[16]: https://opensource.com/article/19/4/write-git
|
||||
[17]: https://opensource.com/sites/default/files/uploads/builder.png (GNOME Builder screenshot)
|
||||
[18]: https://wiki.gnome.org/Apps/Builder
|
||||
[19]: https://flathub.org/apps/details/org.gnome.Builder
|
||||
[20]: https://opensource.com/sites/default/files/uploads/geany.png (Geany screenshot)
|
||||
[21]: https://www.geany.org/
|
||||
[22]: https://opensource.com/sites/default/files/uploads/brackets.jpg (Brackets screenshot)
|
||||
[23]: http://brackets.io/
|
||||
[24]: https://opensource.com/sites/default/files/uploads/che-cpp.jpg (Che screenshot)
|
||||
[25]: https://www.eclipse.org/che/extend/
|
@ -1,49 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (An open source browser extension to zoom in on images)
|
||||
[#]: via: (https://opensource.com/article/20/6/hoverzoom)
|
||||
[#]: author: (Jeff Macharyas https://opensource.com/users/jeffmacharyas)
|
||||
|
||||
可放大图像的开源浏览器扩展
|
||||
======
|
||||
仔细看网络图像并不总是那么简单,但是 Hover Zoom+ 让它像鼠标滑动一样容易。
|
||||
![Digital images of a computer desktop][1]
|
||||
|
||||
你是否曾经在访问网站时希望查看更大的图像?这无时无刻不在我身上发生,要做到这点并不总是那么容易。
|
||||
|
||||
有时,我在源码中筛选,使用 **Ctrl + F** 搜索图像,复制图像源地址并将其粘贴到新窗口中,以便以全尺寸查看图像。或者,另一个选择是右键单击,复制图像地址,然后粘贴到新选项卡中。
|
||||
|
||||
![Example image source code ][2]
|
||||
|
||||
Hover Zoom+ 让这个过程更加简单。Hover Zoom+ 是在 MIT 许可证下发行的,是可在 Chrome 商店中找到的简单 Chrome 扩展程序,它的源码可在 [GitHub][3] 上获得。它也可用于 Firefox。
|
||||
|
||||
这个应用使得该过程更加容易。通过简单地将鼠标悬停在图像上,你将看到一个弹出窗口来显示该图像的全部内容,它会匹配你的浏览器窗口,无论图像是否被裁剪(或者图像适应尺寸,它看上去将是相同的) )。这可能很有趣,因为有时可能会裁剪原始图像,以适应空间或聚焦于图像的特定部分。但是,你无法右键单击并直接从弹出窗口中保存图像。
|
||||
|
||||
根据加州圣何塞的开发人员 Oleg Anashkin 的说法,“这是原始 HoverZoom 扩展的开源版本,现已被恶意软件淹没,并从商店中删除。在此版本中,所有间谍软件均已删除,许多 bug 已被修复,并添加了新功能。它默认不会收集任何统计信息。”
|
||||
|
||||
我在 Windows 10 笔记本上的 Chrome 中安装了扩展,然后试用了一下。安装扩展后,我将鼠标悬停在图像上,它在弹出窗口中显示了比实际更大的图像。
|
||||
|
||||
但是,Hover Zoom+ 不适用于所有网站或所有图像。它适用于 Facebook 和 Twitter,但不适用于这些网站上的赞助内容。用户可以轻松切换该应用以针对特定站点启用或禁用它。使用 Hover Zoom+ 可以很容易地看到 Instagram 上的这只可爱小猫而无需实际阅读帖子(方便!):
|
||||
|
||||
![Zoomed-in image of a kitten from Facebook][4]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/hoverzoom
|
||||
|
||||
作者:[Jeff Macharyas][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jeffmacharyas
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_browser_web_desktop.png?itok=Bw8ykZMA (Digital images of a computer desktop)
|
||||
[2]: https://opensource.com/sites/default/files/uploads/source.jpg (Example image source code)
|
||||
[3]: https://github.com/extesy/hoverzoom/
|
||||
[4]: https://opensource.com/sites/default/files/uploads/fb-cat.jpg (HoverZoom+ enlarged image)
|
@ -7,16 +7,14 @@
|
||||
[#]: via: (https://www.networkworld.com/article/3564265/painless-file-extraction-on-linux.html)
|
||||
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
|
||||
|
||||
Painless file extraction on Linux
|
||||
Linux 上无痛文件解压
|
||||
======
|
||||
|
||||
Thinkstock
|
||||
从 Linux 系统的存档中解压文件要比拔牙要麻烦得多,但有时看起来更麻烦。在本文中,我们将探讨如何轻松地从几乎任何可能在 Linux 系统中使用的存档中解压文件。
|
||||
|
||||
Extracting files from archives in Linux systems is considerably less painful than tooth extraction, but sometimes seems more complicated. In this post, we will take a look at how you can easily extract files from just about any kind of archive you’re likely to run into on a Linux system.
|
||||
它们有很多格式,从 .gz 到 .tbz2,这些文件的命名方式有一些变化。当然,你可以记住所有可用于从存档中解压文件的命令以及它们的选项,但是你也可以将所有经验保存到脚本中,而不必担心细节。
|
||||
|
||||
There’s a pile of them – everything from .gz to .tbz2 files with some variations for how those files are named. Sure, you can memorize all of the various commands available for extracting files from archives along with the options they offer, but you can also just deposit all that know-how into a script and stop worrying about the details.
|
||||
|
||||
In this post, we assemble a series of extraction commands into a script that calls the proper command to extract the content of file archives depending on the archive file names. The script starts with some commands to verify that a file name has been provided as an argument or ask that the person running the script provide one.
|
||||
在本文中,我们将一系列解压命令组合成一个脚本,它会调用适当的命令根据文档名解压文件的内容。该脚本以一些命令开头来验证文件名是否已经提供作为参数,或要求运行脚本的人提供文件名。
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
@ -34,9 +32,9 @@ if [ ! -f "$filename" ]; then
|
||||
fi
|
||||
```
|
||||
|
||||
Got that? The script prompts for a file name if no arguments were offered and uses the argument provided if there is one. It then verifies that the file actually exists. If not, the script exits.
|
||||
了解了么?如果未提供任何参数,脚本将提示输入文件名,如果存在则使用它。然后,它验证文件是否实际存在。如果不是,那么脚本退出。
|
||||
|
||||
The next step is to use a bash case statement to call the appropriate extraction command for the archive depending on its name. For some of these file types (e.g., .bz2), other commands than tar would also work, but we only include one extraction command for each file naming convention. So, here’s the case statement with the various archive file names.
|
||||
下一步是使用 bash case 语句根据存档文件的名称为存档文件调用适当的解压命令。对于其中某些文件类型(例如 .bz2),也可以使用除 tar 之外的其他命令,但是对于每种文件命名约定,我们仅包含一个解压命令。因此,这是带有各种存档文件名的 case 语句。
|
||||
|
||||
```
|
||||
case $filename in
|
||||
@ -54,9 +52,9 @@ The next step is to use a bash case statement to call the appropriate extraction
|
||||
esac
|
||||
```
|
||||
|
||||
If the file provided to the script has a file extension that doesn’t match any of those known to the script, the “No extract option for $filename” message will be issued. If any archive types that you use are missing, just add them along with the required extraction commands.
|
||||
如果提供给脚本的文件扩展名与脚本已知的扩展名都不匹配,那么会发出 “No extract option for $filename” 的消息。如果缺少你使用的任何存档类型,只需将它们与所需的提取命令一起添加即可。
|
||||
|
||||
Add the bash header to the top of the script, make it executable and you should be ready to go.
|
||||
将 bash 头添加到脚本顶部,使其可执行,然后就可以开始了。
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
@ -88,7 +86,7 @@ case $filename in
|
||||
*)
|
||||
```
|
||||
|
||||
If you want the script to display the contents of the archive as they are being extracted, add the verbose option (-v) to each string of command arguments:
|
||||
如果你希望脚本在解压文件时显示内容,请将详细选项(-v)添加到每个命令参数字符串中:
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
@ -120,11 +118,11 @@ case $filename in
|
||||
esac
|
||||
```
|
||||
|
||||
### Wrap-up
|
||||
### 总结
|
||||
|
||||
While it’s certainly possible to create an alias for each extraction command you’re likely to use, it’s easier to let a script provide the command for each file type you encounter than having to stop and work out each of the commands and options yourself.
|
||||
虽然可以为每个可能用到的解压命令创建别名,但是让脚本为遇到的每种文件类型提供命令要比自己停下来编写每个命令和选项容易。
|
||||
|
||||
Join the Network World communities on [Facebook][1] and [LinkedIn][2] to comment on topics that are top of mind.
|
||||
加入 [Facebook][1] 和 [LinkedIn][2] 上的 Network World 社区,评论热门主题。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -132,7 +130,7 @@ via: https://www.networkworld.com/article/3564265/painless-file-extraction-on-li
|
||||
|
||||
作者:[Sandra Henry-Stocker][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/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user