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
e77d1b8757
328
published/20190724 Master the Linux -ls- command.md
Normal file
328
published/20190724 Master the Linux -ls- command.md
Normal file
@ -0,0 +1,328 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-11159-1.html)
|
||||
[#]: subject: (Master the Linux 'ls' command)
|
||||
[#]: via: (https://opensource.com/article/19/7/master-ls-command)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
精通 Linux 的 ls 命令
|
||||
======
|
||||
|
||||
> Linux 的 ls 命令拥有数量惊人的选项,可以提供有关文件的重要信息。
|
||||
|
||||

|
||||
|
||||
`ls` 命令可以列出一个 [POSIX][2] 系统上的文件。这是一个简单的命令,但它经常被低估,不是它能做什么(因为它确实只做了一件事),而是你该如何优化对它的使用。
|
||||
|
||||
要知道在最重要的 10 个终端命令中,这个简单的 `ls` 命令可以排进前三,因为 `ls` 不会*只是*列出文件,它还会告诉你有关它们的重要信息。它会告诉你诸如拥有文件或目录的人、每个文件修改的时间、甚至是什么类型的文件。它的附带功能能让你了解你在哪里、附近有些什么,以及你可以用它们做什么。
|
||||
|
||||
如果你对 `ls` 的体验仅限于你的发行版在 `.bashrc` 中的别名,那么你可能错失了它。
|
||||
|
||||
### GNU 还是 BSD?
|
||||
|
||||
在了解 `ls` 的隐藏能力之前,你必须确定你正在运行哪个 `ls` 命令。有两个最流行的版本:包含在 GNU coreutils 包中的 GNU 版本,以及 BSD 版本。如果你正在运行 Linux,那么你很可能已经安装了 GNU 版本的 `ls`(LCTT 译注:几乎可以完全确定)。如果你正在运行 BSD 或 MacOS,那么你有的是 BSD 版本。本文会介绍它们的不同之处。
|
||||
|
||||
你可以使用 `--version` 选项找出你计算机上的版本:
|
||||
|
||||
```
|
||||
$ ls --version
|
||||
```
|
||||
|
||||
如果它返回有关 GNU coreutils 的信息,那么你拥有的是 GNU 版本。如果它返回一个错误,你可能正在运行的是 BSD 版本(运行 `man ls | head` 以确定)。
|
||||
|
||||
你还应该调查你的发行版可能具有哪些预设选项。终端命令的自定义通常放在 `$HOME/.bashrc` 或 `$HOME/.bash_aliases` 或 `$HOME/.profile` 中,它们是通过将 `ls` 别名化为更复杂的 `ls` 命令来完成的。例如:
|
||||
|
||||
```
|
||||
alias ls='ls --color'
|
||||
```
|
||||
|
||||
发行版提供的预设非常有用,但它们确实很难分辨出哪些是 `ls` 本身的特性,哪些是它的附加选项提供的。你要是想要运行 `ls` 命令本身而不是它的别名,你可以用反斜杠“转义”命令:
|
||||
|
||||
```
|
||||
$ \ls
|
||||
```
|
||||
|
||||
### 分类
|
||||
|
||||
单独运行 `ls` 会以适合你终端的列数列出文件:
|
||||
|
||||
```
|
||||
$ ls ~/example
|
||||
bunko jdk-10.0.2
|
||||
chapterize otf2ttf.ff
|
||||
despacer overtar.sh
|
||||
estimate.sh pandoc-2.7.1
|
||||
fop-2.3 safe_yaml
|
||||
games tt
|
||||
```
|
||||
|
||||
这是有用的信息,但所有这些文件看起来基本相同,没有方便的图标来快速表示出哪个是目录、文本文件或图像等等。
|
||||
|
||||
使用 `-F`(或 GNU 上的长选项 `--classify`)以在每个条目之后显示标识文件类型的指示符:
|
||||
|
||||
```
|
||||
$ ls ~/example
|
||||
bunko jdk-10.0.2/
|
||||
chapterize* otf2ttf.ff*
|
||||
despacer* overtar.sh*
|
||||
estimate.sh pandoc@
|
||||
fop-2.3/ pandoc-2.7.1/
|
||||
games/ tt*
|
||||
```
|
||||
|
||||
使用此选项,终端中列出的项目使用简写符号来按文件类型分类:
|
||||
|
||||
* 斜杠(`/`)表示目录(或“文件夹”)。
|
||||
* 星号(`*`)表示可执行文件。这包括二进制文件(编译代码)以及脚本(具有[可执行权限][3]的文本文件)。
|
||||
* 符号(`@`)表示符号链接(或“别名”)。
|
||||
* 等号(`=`)表示套接字。
|
||||
* 在 BSD 上,百分号(`%`)表示<ruby>涂改<rt>whiteout</rt></ruby>(某些文件系统上的文件删除方法)。
|
||||
* 在 GNU 上,尖括号(`>`)表示<ruby>门<rt>door</rt></ruby>([Illumos][4] 和 Solaris上的进程间通信)。
|
||||
* 竖线(`|`)表示 [FIFO][5] 管道。
|
||||
|
||||
这个选项的一个更简单的版本是 `-p`,它只区分文件和目录。
|
||||
|
||||
(LCTT 译注:在支持彩色的终端上,使用 `--color` 选项可以以不同的颜色来区分文件类型,但要注意如果将输出导入到管道中,则颜色消失。)
|
||||
|
||||
### 长列表
|
||||
|
||||
从 `ls` 获取“长列表”的做法是如此常见,以至于许多发行版将 `ll` 别名为 `ls -l`。长列表提供了许多重要的文件属性,例如权限、拥有每个文件的用户、文件所属的组、文件大小(以字节为单位)以及文件上次更改的日期:
|
||||
|
||||
```
|
||||
$ ls -l
|
||||
-rwxrwx---. 1 seth users 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth users 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth users 20697793 Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth users 6210 May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth users 177 Nov 12 2018 html4mutt.sh
|
||||
[...]
|
||||
```
|
||||
|
||||
如果你不想以字节为单位,请添加 `-h` 标志(或 GNU 中的 `--human`)以将文件大小转换为更加人性化的表示方法:
|
||||
|
||||
```
|
||||
$ ls --human
|
||||
-rwxrwx---. 1 seth users 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth seth 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth users 20M Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth seth 6.1K May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth users 177 Nov 12 2018 html4mutt.sh
|
||||
```
|
||||
|
||||
要看到更少的信息,你可以带有 `-o` 选项只显示所有者的列,或带有 `-g` 选项只显示所属组的列:
|
||||
|
||||
```
|
||||
$ ls -o
|
||||
-rwxrwx---. 1 seth 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth 20M Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth 6.1K May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth 177 Nov 12 2018 html4mutt.sh
|
||||
```
|
||||
|
||||
也可以将两个选项组合使用以显示两者。
|
||||
|
||||
### 时间和日期格式
|
||||
|
||||
`ls` 的长列表格式通常如下所示:
|
||||
|
||||
```
|
||||
-rwxrwx---. 1 seth users 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth users 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth users 20697793 Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth users 6210 May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth users 177 Nov 12 2018 html4mutt.sh
|
||||
```
|
||||
|
||||
月份的名字不便于排序,无论是通过计算还是识别(取决于你的大脑是否倾向于喜欢字符串或整数)。你可以使用 `--time-style` 选项和格式名称更改时间戳的格式。可用格式为:
|
||||
|
||||
* `full-iso`:ISO 完整格式(1970-01-01 21:12:00)
|
||||
* `long-iso`:ISO 长格式(1970-01-01 21:12)
|
||||
* `iso`:iso 格式(01-01 21:12)
|
||||
* `locale`:本地化格式(使用你的区域设置)
|
||||
* `posix-STYLE`:POSIX 风格(用区域设置定义替换 `STYLE`)
|
||||
|
||||
你还可以使用 `date` 命令的正式表示法创建自定义样式。
|
||||
|
||||
### 按时间排序
|
||||
|
||||
通常,`ls` 命令按字母顺序排序。你可以使用 `-t` 选项根据文件的最近更改的时间(最新的文件最先列出)进行排序。
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
$ touch foo bar baz
|
||||
$ ls
|
||||
bar baz foo
|
||||
$ touch foo
|
||||
$ ls -t
|
||||
foo bar baz
|
||||
```
|
||||
|
||||
### 列出方式
|
||||
|
||||
`ls` 的标准输出平衡了可读性和空间效率,但有时你需要按照特定方式排列的文件列表。
|
||||
|
||||
要以逗号分隔文件列表,请使用 `-m`:
|
||||
|
||||
```
|
||||
ls -m ~/example
|
||||
bar, baz, foo
|
||||
```
|
||||
|
||||
要强制每行一个文件,请使用 `-1` 选项(这是数字 1,而不是小写的 L):
|
||||
|
||||
```
|
||||
$ ls -1 ~/bin/
|
||||
bar
|
||||
baz
|
||||
foo
|
||||
```
|
||||
|
||||
要按文件扩展名而不是文件名对条目进行排序,请使用 `-X`(这是大写 X):
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar.xfc baz.txt foo.asc
|
||||
$ ls -X
|
||||
foo.asc baz.txt bar.xfc
|
||||
```
|
||||
|
||||
### 隐藏杂项
|
||||
|
||||
在某些 `ls` 列表中有一些你可能不关心的条目。例如,元字符 `.` 和 `..` 分别代表“本目录”和“父目录”。如果你熟悉在终端中如何切换目录,你可能已经知道每个目录都将自己称为 `.`,并将其父目录称为 `..`,因此当你使用 `-a` 选项显示隐藏文件时并不需要它经常提醒你。
|
||||
|
||||
要显示几乎所有隐藏文件(`.` 和 `..` 除外),请使用 `-A` 选项:
|
||||
|
||||
```
|
||||
$ ls -a
|
||||
.
|
||||
..
|
||||
.android
|
||||
.atom
|
||||
.bash_aliases
|
||||
[...]
|
||||
$ ls -A
|
||||
.android
|
||||
.atom
|
||||
.bash_aliases
|
||||
[...]
|
||||
```
|
||||
|
||||
有许多优秀的 Unix 工具有保存备份文件的传统,它们会在保存文件的名称后附加一些特殊字符作为备份文件。例如,在 Vim 中,备份会以在文件名后附加 `~` 字符的文件名保存。
|
||||
|
||||
这些类型的备份文件已经多次使我免于愚蠢的错误,但是经过多年享受它们提供的安全感后,我觉得不需要用视觉证据来证明它们存在。我相信 Linux 应用程序可以生成备份文件(如果它们声称这样做的话),我很乐意相信它们存在 —— 而不用必须看到它们。
|
||||
|
||||
要隐藏备份文件,请使用 `-B` 或 `--ignore-backups` 隐藏常用备份格式(此选项在 BSD 的 `ls` 中不可用):
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar.xfc baz.txt foo.asc~ foo.asc
|
||||
$ ls -B
|
||||
bar.xfc baz.txt foo.asc
|
||||
```
|
||||
|
||||
当然,备份文件仍然存在;它只是过滤掉了,你不必看到它。
|
||||
|
||||
除非另有配置,GNU Emacs 在文件名的开头和结尾添加哈希字符(`#`)来保存备份文件(`#file#`)。其他应用程序可能使用不同的样式。使用什么模式并不重要,因为你可以使用 `--hide` 选项创建自己的排除项:
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar.xfc baz.txt #foo.asc# foo.asc
|
||||
$ ls --hide="#*#"
|
||||
bar.xfc baz.txt foo.asc
|
||||
```
|
||||
|
||||
### 递归地列出目录
|
||||
|
||||
除非你在指定目录上运行 `ls`,否则子目录的内容不会与 `ls` 命令一起列出:
|
||||
|
||||
```
|
||||
$ ls -F
|
||||
example/ quux* xyz.txt
|
||||
$ ls -R
|
||||
quux xyz.txt
|
||||
|
||||
./example:
|
||||
bar.xfc baz.txt #foo.asc# foo.asc
|
||||
```
|
||||
|
||||
### 使用别名使其永久化
|
||||
|
||||
`ls` 命令可能是 shell 会话期间最常使用的命令。这是你的眼睛和耳朵,为你提供上下文信息和确认命令的结果。虽然有很多选项很有用,但 `ls` 之美的一部分就是简洁:两个字符和回车键,你就知道你到底在哪里以及附近有什么。如果你不得不停下思考(更不用说输入)几个不同的选项,它会变得不那么方便,所以通常情况下,即使最有用的选项也不会用了。
|
||||
|
||||
解决方案是为你的 `ls` 命令添加别名,以便在使用它时,你可以获得最关心的信息。
|
||||
|
||||
要在 Bash shell 中为命令创建别名,请在主目录中创建名为 `.bash_aliases` 的文件(必须在开头包含 `.`)。 在此文件中,列出要创建的别名,然后是要为其创建别名的命令。例如:
|
||||
|
||||
```
|
||||
alias ls='ls -A -F -B --human --color'
|
||||
```
|
||||
|
||||
这一行导致你的 Bash shell 将 `ls` 命令解释为 `ls -A -F -B --human --color`。
|
||||
|
||||
你不必仅限于重新定义现有命令,还可以创建自己的别名:
|
||||
|
||||
```
|
||||
alias ll='ls -l'
|
||||
alias la='ls -A'
|
||||
alias lh='ls -h'
|
||||
```
|
||||
|
||||
要使别名起作用,shell 必须知道 `.bash_aliases` 配置文件存在。在编辑器中打开 `.bashrc` 文件(如果它不存在则创建它),并包含以下代码块:
|
||||
|
||||
```
|
||||
if [ -e $HOME/.bash_aliases ]; then
|
||||
source $HOME/.bash_aliases
|
||||
fi
|
||||
```
|
||||
|
||||
每次加载 `.bashrc`(这是一个新的 Bash shell 启动的时候),Bash 会将 `.bash_aliases` 加载到你的环境中。你可以关闭并重新启动 Bash 会话,或者直接强制它执行此操作:
|
||||
|
||||
```
|
||||
$ source ~/.bashrc
|
||||
```
|
||||
|
||||
如果你忘了你是否有别名命令,`which` 命令可以告诉你:
|
||||
|
||||
```
|
||||
$ which ls
|
||||
alias ls='ls -A -F -B --human --color'
|
||||
/usr/bin/ls
|
||||
```
|
||||
|
||||
如果你将 `ls` 命令别名为带有选项的 `ls` 命令,则可以通过将反斜杠前缀到 `ls` 前来覆盖你的别名。例如,在示例别名中,使用 `-B` 选项隐藏备份文件,这意味着无法使用 `ls` 命令显示备份文件。 可以覆盖该别名以查看备份文件:
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar baz foo
|
||||
$ \ls
|
||||
bar baz baz~ foo
|
||||
```
|
||||
|
||||
### 做一件事,把它做好
|
||||
|
||||
`ls` 命令有很多选项,其中许多是特定用途的或高度依赖于你所使用的终端。在 GNU 系统上查看 `info ls`,或在 GNU 或 BSD 系统上查看 `man ls` 以了解更多选项。
|
||||
|
||||
你可能会觉得奇怪的是,一个以每个工具“做一件事,把它做好”的前提而闻名的系统会让其最常见的命令背负 50 个选项。但是 `ls` 只做一件事:它列出文件,而这 50 个选项允许你控制接收列表的方式,`ls` 的这项工作做得非常、*非常*好。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/7/master-ls-command
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/sethhttps://opensource.com/users/sambocettahttps://opensource.com/users/scottnesbitthttps://opensource.com/users/sethhttps://opensource.com/users/marcobravohttps://opensource.com/users/sethhttps://opensource.com/users/don-watkinshttps://opensource.com/users/sethhttps://opensource.com/users/jamesfhttps://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/yearbook-haff-rx-linux-file-lead_0.png?itok=-i0NNfDC (Hand putting a Linux file folder into a drawer)
|
||||
[2]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
||||
[3]: https://opensource.com/article/19/6/understanding-linux-permissions
|
||||
[4]: https://www.illumos.org/
|
||||
[5]: https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,119 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Convert Markdown files to word processor docs using pandoc)
|
||||
[#]: via: (https://opensource.com/article/19/5/convert-markdown-to-word-pandoc)
|
||||
[#]: author: (Scott Nesbitt https://opensource.com/users/scottnesbitt/users/jason-van-gumster/users/kikofernandez)
|
||||
|
||||
Convert Markdown files to word processor docs using pandoc
|
||||
======
|
||||
Living that plaintext life? Here's how to create the word processor
|
||||
documents people ask for without having to work in a word processor
|
||||
yourself.
|
||||
![][1]
|
||||
|
||||
If you live your life in [plaintext][2], there invariably comes a time when someone asks for a word processor document. I run into this issue frequently, especially at the Day JobTM. Although I've introduced one of the development teams I work with to a [Docs Like Code][3] workflow for writing and reviewing release notes, there are a small number of people who have no interest in GitHub or working with [Markdown][4]. They prefer documents formatted for a certain proprietary application.
|
||||
|
||||
The good news is that you're not stuck copying and pasting unformatted text into a word processor document. Using **[pandoc][5]** , you can quickly give people what they want. Let's take a look at how to convert a document from Markdown to a word processor format in [Linux][6] using **pandoc.**
|
||||
|
||||
Note that **pandoc** is also available for a wide variety of operating systems, ranging from two flavors of BSD ([NetBSD][7] and [FreeBSD][8]) to Chrome OS, MacOS, and Windows.
|
||||
|
||||
### Converting basics
|
||||
|
||||
To begin, [install **pandoc**][9] on your computer. Then, crack open a console terminal window and navigate to the directory containing the file that you want to convert.
|
||||
|
||||
Type this command to create an ODT file (which you can open with a word processor like [LibreOffice Writer][10] or [AbiWord][11]):
|
||||
|
||||
**pandoc -t odt filename.md -o filename.odt**
|
||||
|
||||
Remember to replace **filename** with the file's actual name. And if you need to create a file for that other word processor (you know the one I mean), replace **odt** on the command line with **docx**. Here's what this article looks like when converted to an ODT file:
|
||||
|
||||
![Basic conversion results with pandoc.][12]
|
||||
|
||||
These results are serviceable, but a bit bland. Let's look at how to add a bit more style to the converted documents.
|
||||
|
||||
### Converting with style
|
||||
|
||||
**pandoc** has a nifty feature enabling you to specify a style template when converting a marked-up plaintext file to a word processor format. In this file, you can edit a small number of styles in the document, including those that control the look of paragraphs, headings, captions, titles and subtitles, a basic table, and hyperlinks.
|
||||
|
||||
Let's look at the possibilities.
|
||||
|
||||
#### Creating a template
|
||||
|
||||
In order to style your documents, you can't just use _any_ template. You need to generate what **pandoc** calls a _reference_ template, which is the template it uses when converting text files to word processor documents. To create this file, type the following in a terminal window:
|
||||
|
||||
**pandoc -o custom-reference.odt --print-default-data-file reference.odt**
|
||||
|
||||
This command creates a file called **custom-reference.odt**. If you're using that other word processor, change the references to **odt** on the command line to **docx**.
|
||||
|
||||
Open the template file in LibreOffice Writer, and then press **F11** to open LibreOffice Writer's **Styles** pane. Although the [pandoc manual][13] advises against making other changes to the file, I change the page size and add headers and footers when necessary.
|
||||
|
||||
#### Using the template
|
||||
|
||||
So, how do you use that template you just created? There are two ways to do this.
|
||||
|
||||
The easiest way is to drop the template in your **/home** directory's **.pandoc** folder—you might have to create the folder first if it doesn't exist. When it's time to convert a document, **pandoc** uses this template file. See the next section on how to choose from multiple templates if you need more than one.
|
||||
|
||||
The other way to use your template is to type this set of conversion options at the command line:
|
||||
|
||||
**pandoc -t odt file-name.md --reference-doc=path-to-your-file/reference.odt -o file-name.odt**
|
||||
|
||||
If you're wondering what a converted file looks like with a customized template, here's an example:
|
||||
|
||||
![A document converted using a pandoc style template.][14]
|
||||
|
||||
#### Choosing from multiple templates
|
||||
|
||||
Many people only need one **pandoc** template. Some people, however, need more than one.
|
||||
|
||||
At my day job, for example, I use several templates—one with a DRAFT watermark, one with a watermark stating FOR INTERNAL USE, and one for a document's final versions. Each type of document needs a different template.
|
||||
|
||||
If you have similar needs, start the same way you do for a single template, by creating the file **custom-reference.odt**. Rename the resulting file—for example, to **custom-reference-draft.odt** —then open it in LibreOffice Writer and modify the styles. Repeat this process for each template you need.
|
||||
|
||||
Next, copy the files into your **/home** directory. You can even put them in the **.pandoc** folder if you want to.
|
||||
|
||||
To select a specific template at conversion time, you'll need to run this command in a terminal:
|
||||
|
||||
**pandoc -t odt file-name.md --reference-doc=path-to-your-file/custom-template.odt -o file-name.odt**
|
||||
|
||||
Change **custom-template.odt** to your template file's name.
|
||||
|
||||
### Wrapping up
|
||||
|
||||
To avoid having to remember a set of options I don't regularly use, I cobbled together some simple, very lame one-line scripts that encapsulate the options for each template. For example, I run the script **todraft.sh** to create a word processor document using the template with a DRAFT watermark. You might want to do the same.
|
||||
|
||||
Here's an example of a script using the template containing a DRAFT watermark:
|
||||
|
||||
`pandoc -t odt $1.md -o $1.odt --reference-doc=~/Documents/pandoc-templates/custom-reference-draft.odt`
|
||||
|
||||
Using **pandoc** is a great way to provide documents in the format that people ask for, without having to give up the command line life. This tool doesn't just work with Markdown, either. What I've discussed in this article also allows you to create and convert documents between a wide variety of markup languages. See the **pandoc** site linked earlier for more details.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/5/convert-markdown-to-word-pandoc
|
||||
|
||||
作者:[Scott Nesbitt][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/scottnesbitt/users/jason-van-gumster/users/kikofernandez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_keyboard_laptop_development_code_woman.png?itok=vbYz6jjb
|
||||
[2]: https://plaintextproject.online/
|
||||
[3]: https://www.docslikecode.com/
|
||||
[4]: https://en.wikipedia.org/wiki/Markdown
|
||||
[5]: https://pandoc.org/
|
||||
[6]: /resources/linux
|
||||
[7]: https://www.netbsd.org/
|
||||
[8]: https://www.freebsd.org/
|
||||
[9]: https://pandoc.org/installing.html
|
||||
[10]: https://www.libreoffice.org/discover/writer/
|
||||
[11]: https://www.abisource.com/
|
||||
[12]: https://opensource.com/sites/default/files/uploads/pandoc-wp-basic-conversion_600_0.png (Basic conversion results with pandoc.)
|
||||
[13]: https://pandoc.org/MANUAL.html
|
||||
[14]: https://opensource.com/sites/default/files/uploads/pandoc-wp-conversion-with-tpl_600.png (A document converted using a pandoc style template.)
|
@ -1,117 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to enable DNS-over-HTTPS (DoH) in Firefox)
|
||||
[#]: via: (https://www.zdnet.com/article/how-to-enable-dns-over-https-doh-in-firefox/)
|
||||
[#]: author: (Catalin Cimpanu https://www.zdnet.com/meet-the-team/us/catalin.cimpanu/)
|
||||
|
||||
How to enable DNS-over-HTTPS (DoH) in Firefox
|
||||
======
|
||||
|
||||
The DNS-over-HTTPS (DoH) protocol is currently the talk of the town, and the Firefox browser is the only one to support it.
|
||||
|
||||
However, the feature is not enabled by default for Firefox users, who will have to go through many hoops and modify multiple settings before they can get the DoH up and running.
|
||||
|
||||
But before we go into a step-by-step tutorial on how someone can enable DoH support in Firefox, let's describe what it does first.
|
||||
|
||||
### How DNS-over-HTTPS works
|
||||
|
||||
The DNS-over-HTTPS protocol works by taking a domain name that a user has typed in their browser and sending a query to a DNS server to learn the numerical IP address of the web server that hosts that specific site.
|
||||
|
||||
This is how normal DNS works, too. However, DoH takes the DNS query and sends it to a DoH-compatible DNS server (resolver) via an encrypted HTTPS connection on port 443, rather than plaintext on port 53.
|
||||
|
||||
This way, DoH hides DNS queries inside regular HTTPS traffic, so third-party observers won't be able to sniff traffic and tell what DNS queries users have run and infer what websites they are about to access.
|
||||
|
||||
Further, a secondary feature of DNS-over-HTTPS is that the protocol works at the app level. Apps can come with internally hardcoded lists of DoH-compatible DNS resolvers where they can send DoH queries.
|
||||
|
||||
This mode of operation bypasses the default DNS settings that exist at the OS level, which, in most cases are the ones set by local internet service providers (ISPs).
|
||||
|
||||
This also means that apps that support DoH can effectively bypass local ISPs traffic filters and access content that may be blocked by a local telco or local government -- and a reason why DoH is currently hailed as a boon for users' privacy and security.
|
||||
|
||||
This is one of the reasons that DoH has gained quite the popularity in less than two years after it launched, and a reason why a group of [UK ISPs nominated Mozilla for the award of 2019 Internet Vilain][1] for its plans to support the DoH protocol, which they said would thwart their efforts in filtering bad traffic.
|
||||
|
||||
As a response, and due to the complex situation in the UK where the government blocks access to copyright-infringing content, and where ISPs voluntarily block access to child abuse website, [Mozilla has decided not to enable this feature by default for British users][2].
|
||||
|
||||
The below step-by-step guide will show Firefox users in the UK and Firefox users all over the world how to enable the feature right now, and not wait until Mozilla enables it later down the road -- if it will ever do. There are two methods of enabling DoH support in Firefox.
|
||||
|
||||
### Method 1 - via the Firefox settings
|
||||
|
||||
**Step 1:** Go to the Firefox menu, choose **Tools** , and then **Preferences**. Optionally type **about:preferences** in the URL bar and press enter. This will open the Firefox prerences section.
|
||||
|
||||
**Step 2:** In the **General** section, scroll down to the **Network Settings** panel, and press the **Settings** button.
|
||||
|
||||
![DoH section in Firefox settings][3]
|
||||
|
||||
Image: ZDNet
|
||||
|
||||
**Step 3:** In the popup, scroll down and select " **Enable DNS over HTTPS** ," then configure your desired DoH resolver. You can use the built in Cloudflare resolver (a company with which Mozilla has [reached an agreement][4] to log less data about Firefox users), or use one of your choice, [from this list][4].
|
||||
|
||||
![DoH section in Firefox settings][5]![DoH section in Firefox settings][6]
|
||||
|
||||
Image: ZDNet
|
||||
|
||||
### Method 2 - via about:config
|
||||
|
||||
**Step 1:** Type **about:config** in the URL bar and press Enter to access Firefox's hidden configuration panel. Here users will need to enable and modify three settings.
|
||||
|
||||
**Step 2:** The first setting is **network.trr.mode**. This turns on DoH support. This setting supports four values:
|
||||
|
||||
* 0 - Default value in standard Firefox installations (currently is 5, which means DoH is disabled)
|
||||
* 1 - DoH is enabled, but Firefox picks if it uses DoH or regular DNS based on which returns faster query responses
|
||||
* 2 - DoH is enabled, and regular DNS works as a backup
|
||||
* 3 - DoH is enabled, and regular DNS is disabled
|
||||
* 5 - DoH is disabled
|
||||
|
||||
|
||||
|
||||
A value of 2 works best.
|
||||
|
||||
![DoH in Firefox][5]![DoH in Firefox][7]
|
||||
|
||||
Image: ZDNet
|
||||
|
||||
**Step 3:** The second setting that needs to be modified is **network.trr.uri**. This is the URL of the DoH-compatible DNS server where Firefox will send DoH DNS queries. By default, Firefox uses Cloudflare's DoH service located at <https://mozilla.cloudflare-dns.com/dns-query>. However, users can use their own DoH server URL. They can select one from the many available servers, [from this list, here][8]. The reason why Mozilla uses Cloudflare in Firefox is because the companies [reached an agreement][4] following which Cloudflare would collect very little data on DoH queries coming from Firefox users.
|
||||
|
||||
![DoH in Firefox][5]![DoH in Firefox][9]
|
||||
|
||||
Image: ZDNet
|
||||
|
||||
**Step 4:** The third setting is optional and you can skip this one. But if things don't work, you can use this one as a backup for Step 3. The option is called **network.trr.bootstrapAddress** and is an input field where users can enter the numerical IP address of the DoH-compatible DNS resolver they entered in Step 3. For Cloudflare, that would be 1.1.1.1. For Google's service, that would be 8.8.8.8. If you used another DoH resolver's URL, you'll need to track down that server's IP and enter it here, if ever necesarry.
|
||||
|
||||
![DoH in Firefox][5]![DoH in Firefox][10]
|
||||
|
||||
Image: ZDNet
|
||||
|
||||
Normally, the URL entered in Step 3 should be enough, though.
|
||||
|
||||
Settings should apply right away, but in case they don't work, give Firefox a restart.
|
||||
|
||||
Article source: [Mozilla Wiki][11]
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.zdnet.com/article/how-to-enable-dns-over-https-doh-in-firefox/
|
||||
|
||||
作者:[Catalin Cimpanu][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://www.zdnet.com/meet-the-team/us/catalin.cimpanu/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.zdnet.com/article/uk-isp-group-names-mozilla-internet-villain-for-supporting-dns-over-https/
|
||||
[2]: https://www.zdnet.com/article/mozilla-no-plans-to-enable-dns-over-https-by-default-in-the-uk/
|
||||
[3]: https://zdnet1.cbsistatic.com/hub/i/2019/07/07/df30c7b0-3a20-4de7-8640-3dea6d249a49/121bd379b6232e1e2a97c35ea8c7764e/doh-settings-1.png
|
||||
[4]: https://developers.cloudflare.com/1.1.1.1/commitment-to-privacy/privacy-policy/firefox/
|
||||
[5]:
|
||||
[6]: https://zdnet3.cbsistatic.com/hub/i/2019/07/07/8608af28-2a28-4ff1-952b-9b6d2deb1ea6/b1fc322caaa2c955b1a2fb285daf0e42/doh-settings-2.png
|
||||
[7]: https://zdnet1.cbsistatic.com/hub/i/2019/07/06/0232b3a7-82c6-4a6f-90c1-faf0c090254c/6db9b36509021c460fcc7fe825bb74c5/doh-1.png
|
||||
[8]: https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers
|
||||
[9]: https://zdnet2.cbsistatic.com/hub/i/2019/07/06/4dd1d5c1-6fa7-4f5b-b7cd-b544748edfed/baa7a70ac084861d94a744a57a3147ad/doh-2.png
|
||||
[10]: https://zdnet1.cbsistatic.com/hub/i/2019/07/06/8ec20a28-673c-4a17-8195-16579398e90a/538fe8420f9b24724aeb4a6c8d4f0f0f/doh-3.png
|
||||
[11]: https://wiki.mozilla.org/Trusted_Recursive_Resolver
|
@ -1,352 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Master the Linux 'ls' command)
|
||||
[#]: via: (https://opensource.com/article/19/7/master-ls-command)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/sethhttps://opensource.com/users/sambocettahttps://opensource.com/users/scottnesbitthttps://opensource.com/users/sethhttps://opensource.com/users/marcobravohttps://opensource.com/users/sethhttps://opensource.com/users/don-watkinshttps://opensource.com/users/sethhttps://opensource.com/users/jamesfhttps://opensource.com/users/seth)
|
||||
|
||||
Master the Linux 'ls' command
|
||||
======
|
||||
Linux's 'ls' command has a staggering number of options that can provide
|
||||
important information about your files.
|
||||
![Hand putting a Linux file folder into a drawer][1]
|
||||
|
||||
The **ls** command lists files on a [POSIX][2] system. It's a simple command, often underestimated, not in what it can do (because it really does only one thing), but in how you can optimize your use of it.
|
||||
|
||||
Of the 10 most essential terminal commands to know, the humble **ls** command is in the top three, because **ls** doesn't _just_ list files, it tells you important information about them. It tells you things like who owns a file or directory, when each file was lost or modified, and even what kind of file it is. And then there's its incidental function of giving you a sense of where you are, what nearby objects are lying around, and what you can do with them.
|
||||
|
||||
If your experience with **ls** is limited to whatever your distribution aliases it to in **.bashrc**, then you're probably missing out.
|
||||
|
||||
### GNU or BSD?
|
||||
|
||||
Before looking at the hidden powers of **ls**, you must determine which **ls** command you're running. The two most popular versions are the GNU version, included in the GNU **coreutils** package, and the BSD version. If you're running Linux, then you probably have **ls** installed. If you're running BSD or MacOS, then you have the BSD version. There are differences, for which this article accounts.
|
||||
|
||||
You can find out which version is on your computer with the **\--version** option:
|
||||
|
||||
|
||||
```
|
||||
`$ ls --version`
|
||||
```
|
||||
|
||||
If this returns information about GNU coreutils, then you have the GNU version. If it returns an error, you're probably running the BSD version (run **man ls | head** to be sure).
|
||||
|
||||
You should also investigate what presets your distribution may have in place. Customizations to terminal commands are frequently placed in **$HOME/.bashrc** or **$HOME/.bash_aliases** or **$HOME/.profile**, and they're accomplished by aliasing **ls** to a more complex **ls** command. For example:
|
||||
|
||||
|
||||
```
|
||||
`alias ls='ls --color'`
|
||||
```
|
||||
|
||||
The presets provided by distributions are very helpful, but they do make it difficult to discern what **ls** does on its own and what its additional options provide. Should you ever want to run **ls** and not the alias, you can "escape" the command with a backslash:
|
||||
|
||||
|
||||
```
|
||||
`$ \ls`
|
||||
```
|
||||
|
||||
### Classify
|
||||
|
||||
Run on its own, **ls** simply lists files in as many columns as can fit into your terminal:
|
||||
|
||||
|
||||
```
|
||||
$ ls ~/example
|
||||
bunko jdk-10.0.2
|
||||
chapterize otf2ttf.ff
|
||||
despacer overtar.sh
|
||||
estimate.sh pandoc-2.7.1
|
||||
fop-2.3 safe_yaml
|
||||
games tt
|
||||
```
|
||||
|
||||
It's useful information, but all of those files look basically the same without the convenience of icons to quickly convey which is a directory, or a text file, or an image, and so on.
|
||||
|
||||
Use the **-F** (or **\--classify** on GNU) to show indicators after each entry that identify the kind of file it is:
|
||||
|
||||
|
||||
```
|
||||
$ ls ~/example
|
||||
bunko jdk-10.0.2/
|
||||
chapterize* otf2ttf.ff*
|
||||
despacer* overtar.sh*
|
||||
estimate.sh pandoc@
|
||||
fop-2.3/ pandoc-2.7.1/
|
||||
games/ tt*
|
||||
```
|
||||
|
||||
With this option, items listed in your terminal are classified by file type using this shorthand:
|
||||
|
||||
* A slash (**/**) denotes a directory (or "folder").
|
||||
* An asterisk (*****) denotes an executable file. This includes a binary file (compiled code) as well as scripts (text files that have [executable permission][3]).
|
||||
* An at sign (**@**) denotes a symbolic link (or "alias").
|
||||
* An equals sign (**=**) denotes a socket.
|
||||
* On BSD, a percent sign (**%**) denotes a whiteout (a method of file removal on certain file systems).
|
||||
* On GNU, an angle bracket (**>**) denotes a door (inter-process communication on [Illumos][4] and Solaris).
|
||||
* A vertical bar (**|**) denotes a [FIFO][5].
|
||||
|
||||
|
||||
|
||||
A simpler version of this option is **-p**, which only differentiates a file from a directory.
|
||||
|
||||
### Long list
|
||||
|
||||
Getting a "long list" from **ls** is so common that many distributions alias **ll** to **ls -l**. The long list form provides many important file attributes, such as permissions, the user who owns each file, the group to which the file belongs, the file size in bytes, and the date the file was last changed:
|
||||
|
||||
|
||||
```
|
||||
$ ls -l
|
||||
-rwxrwx---. 1 seth users 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth users 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth users 20697793 Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth users 6210 May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth users 177 Nov 12 2018 html4mutt.sh
|
||||
[...]
|
||||
```
|
||||
|
||||
If you don't think in bytes, add the **-h** flag (or **\--human** in GNU) to translate file sizes to more human-friendly notation:
|
||||
|
||||
|
||||
```
|
||||
$ ls --human
|
||||
-rwxrwx---. 1 seth users 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth seth 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth users 20M Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth seth 6.1K May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth users 177 Nov 12 2018 html4mutt.sh
|
||||
```
|
||||
|
||||
You can see just a little less information by showing only the owner column with **-o** or only the group column with **-g**:
|
||||
|
||||
|
||||
```
|
||||
$ ls -o
|
||||
-rwxrwx---. 1 seth 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth 20M Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth 6.1K May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth 177 Nov 12 2018 html4mutt.sh
|
||||
```
|
||||
|
||||
Combine both options to show neither.
|
||||
|
||||
### Time and date format
|
||||
|
||||
The long list format of **ls** usually looks like this:
|
||||
|
||||
|
||||
```
|
||||
-rwxrwx---. 1 seth users 455 Mar 2 2017 estimate.sh
|
||||
-rwxrwxr-x. 1 seth users 662 Apr 29 22:27 factorial
|
||||
-rwxrwx---. 1 seth users 20697793 Jun 29 2018 fop-2.3-bin.tar.gz
|
||||
-rwxrwxr-x. 1 seth users 6210 May 22 10:22 geteltorito
|
||||
-rwxrwx---. 1 seth users 177 Nov 12 2018 html4mutt.sh
|
||||
```
|
||||
|
||||
The names of months aren't easy to sort, both computationally or (depending on whether your brain tends to prefer strings or integers) by recognition. You can change the format of the time stamp with the **\--time-style** option plus the name of a format. Available formats are:
|
||||
|
||||
* full-iso (1970-01-01 21:12:00)
|
||||
* long-iso (1970-01-01 21:12)
|
||||
* iso (01-01 21:12)
|
||||
* locale (uses your locale settings)
|
||||
* posix-STYLE (replace STYLE with a locale definition)
|
||||
|
||||
|
||||
|
||||
You can also create a custom style using the formal notation of the **date** command.
|
||||
|
||||
### Sort by time
|
||||
|
||||
Usually, the **ls** command sorts alphabetically. You can make it sort according to which file was most recently changed (the newest is listed first) with the **-t** option.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
```
|
||||
$ touch foo bar baz
|
||||
$ ls
|
||||
bar baz foo
|
||||
$ touch foo
|
||||
$ ls -t
|
||||
foo bar baz
|
||||
```
|
||||
|
||||
### List type
|
||||
|
||||
The standard output of **ls** balances readability with space efficiency, but sometimes you want your file list in a specific arrangement.
|
||||
|
||||
For a comma-separated list of files, use **-m**:
|
||||
|
||||
|
||||
```
|
||||
ls -m ~/example
|
||||
bar, baz, foo
|
||||
```
|
||||
|
||||
To force one file per line, use the **-1** option (that's the number one, not a lowercase L):
|
||||
|
||||
|
||||
```
|
||||
$ ls -1 ~/bin/
|
||||
bar
|
||||
baz
|
||||
foo
|
||||
```
|
||||
|
||||
To sort entries by file extension rather than the filename, use **-X** (that's a capital X):
|
||||
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar.xfc baz.txt foo.asc
|
||||
$ ls -X
|
||||
foo.asc baz.txt bar.xfc
|
||||
```
|
||||
|
||||
### Hide the clutter
|
||||
|
||||
There are a few entries in some **ls** listings that you may not care about. For instance, the metacharacters **.** and **..** represent "here" and "back one level," respectively. If you're familiar with navigating in a terminal, you probably already know that each directory refers to itself as **.** and to its parent as **..**, so you don't need to be constantly reminded of it when you use the **-a** option to show hidden files.
|
||||
|
||||
To show almost all hidden files (the **.** and **..** excluded), use the **-A** option:
|
||||
|
||||
|
||||
```
|
||||
$ ls -a
|
||||
.
|
||||
..
|
||||
.android
|
||||
.atom
|
||||
.bash_aliases
|
||||
[...]
|
||||
$ ls -A
|
||||
.android
|
||||
.atom
|
||||
.bash_aliases
|
||||
[...]
|
||||
```
|
||||
|
||||
With many good Unix tools, there's a tradition of saving backup files by appending some special character to the name of the file being saved. For instance, in Vim, backups get saved with the **~** character appended to the name.
|
||||
|
||||
These kinds of backup files have saved me from stupid mistakes on several occasions, but after years of enjoying the sense of security they provide, I don't feel the need to have visual evidence that they exist. I trust Linux applications to generate backup files (if they claim to do so), and I'm happy to take it on faith that they exist.
|
||||
|
||||
To hide backup files from view, use **-B** or **\--ignore-backups** to conceal common backup formats (this option is not available in BSD **ls**):
|
||||
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar.xfc baz.txt foo.asc~ foo.asc
|
||||
$ ls -B
|
||||
bar.xfc baz.txt foo.asc
|
||||
```
|
||||
|
||||
Of course, the backup file still exists; it's just filtered out so that you don't have to look at it.
|
||||
|
||||
GNU Emacs saves backup files (unless otherwise configured) with a hash character (**#**) at the start and end of the file name (**#file#**). Other applications may use a different style. It doesn't matter what pattern is used, because you can create your own exclusions with the **\--hide** option:
|
||||
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar.xfc baz.txt #foo.asc# foo.asc
|
||||
$ ls --hide="#*#"
|
||||
bar.xfc baz.txt foo.asc
|
||||
```
|
||||
|
||||
### List directories with recursion
|
||||
|
||||
The contents of directories are not listed with the **ls** command unless you run **ls** on that directory specifically:
|
||||
|
||||
|
||||
```
|
||||
$ ls -F
|
||||
example/ quux* xyz.txt
|
||||
$ ls -R
|
||||
quux xyz.txt
|
||||
|
||||
./example:
|
||||
bar.xfc baz.txt #foo.asc# foo.asc
|
||||
```
|
||||
|
||||
### Make it permanent with an alias
|
||||
|
||||
The **ls** command is probably the command used most often during any given shell session. It's your eyes and ears, providing you with context and confirming the results of commands. While it's useful to have lots of options, part of the beauty of **ls** is its brevity: two characters and the Return key, and you know exactly where you are and what's nearby. If you have to stop to think about (much less type) several different options, it becomes less convenient, so typically even the most useful options are left off.
|
||||
|
||||
The solution is to alias your **ls** command so that when you use it, you get the information you care about the most.
|
||||
|
||||
To create an alias for a command in the Bash shell, create a file in your home directory called **.bash_aliases** (you must include the dot at the beginning). In this file, list the command you want to create an alias for and then the alias you want to create. For example:
|
||||
|
||||
|
||||
```
|
||||
`alias ls='ls -A -F -B --human --color'`
|
||||
```
|
||||
|
||||
This line causes your Bash shell to interpret the **ls** command as **ls -A -F -B --human --color**.
|
||||
|
||||
You aren't limited to redefining existing commands. You can create your own aliases:
|
||||
|
||||
|
||||
```
|
||||
alias ll='ls -l'
|
||||
alias la='ls -A'
|
||||
alias lh='ls -h'
|
||||
```
|
||||
|
||||
For aliases to work, your shell must know that the **.bash_aliases** configuration file exists. Open the **.bashrc** file in an editor (or create it, if it doesn't exist), and include this block of code:
|
||||
|
||||
|
||||
```
|
||||
if [ -e $HOME/.bash_aliases ]; then
|
||||
source $HOME/.bash_aliases
|
||||
fi
|
||||
```
|
||||
|
||||
Each time **.bashrc** is loaded (which is any time a new Bash shell is launched), Bash will load **.bash_aliases** into your environment. You can close and relaunch your Bash session or just force it to do that now:
|
||||
|
||||
|
||||
```
|
||||
`$ source ~/.bashrc`
|
||||
```
|
||||
|
||||
If you forget whether you have aliased a command, the **which** command tells you:
|
||||
|
||||
|
||||
```
|
||||
$ which ls
|
||||
alias ls='ls -A -F -B --human --color'
|
||||
/usr/bin/ls
|
||||
```
|
||||
|
||||
If you've aliased the **ls** command to itself with options, you can override your own alias at any time by prefacing **ls** with a backslash. For instance, in the example alias, backup files are hidden using the **-B** option, which means there's no way to back up files with the **ls** command. Override the alias to see the backup files:
|
||||
|
||||
|
||||
```
|
||||
$ ls
|
||||
bar baz foo
|
||||
$ \ls
|
||||
bar baz baz~ foo
|
||||
```
|
||||
|
||||
### Do one thing and do it well
|
||||
|
||||
The **ls** command has a staggering number of options, many of which are niche or highly dependent upon the terminal you use. Take a look at **info ls** on GNU systems or **man ls** on GNU or BSD systems for more options.
|
||||
|
||||
You might find it strange that a system famous for the premise that each tool "does one thing and does it well" would weigh down its most common command with 50 options. But **ls** does only one thing: it lists files. And with 50 options to allow you to control how you receive that list, **ls** does its one job very, _very_ well.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/7/master-ls-command
|
||||
|
||||
作者:[Seth Kenlon][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/sethhttps://opensource.com/users/sambocettahttps://opensource.com/users/scottnesbitthttps://opensource.com/users/sethhttps://opensource.com/users/marcobravohttps://opensource.com/users/sethhttps://opensource.com/users/don-watkinshttps://opensource.com/users/sethhttps://opensource.com/users/jamesfhttps://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/yearbook-haff-rx-linux-file-lead_0.png?itok=-i0NNfDC (Hand putting a Linux file folder into a drawer)
|
||||
[2]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
||||
[3]: https://opensource.com/article/19/6/understanding-linux-permissions
|
||||
[4]: https://www.illumos.org/
|
||||
[5]: https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)
|
@ -0,0 +1,129 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Convert Markdown files to word processor docs using pandoc)
|
||||
[#]: via: (https://opensource.com/article/19/5/convert-markdown-to-word-pandoc)
|
||||
[#]: author: (Scott Nesbitt https://opensource.com/users/scottnesbitt/users/jason-van-gumster/users/kikofernandez)
|
||||
|
||||
使用 pandoc 将 Markdown 转换为格式化文档
|
||||
======
|
||||
|
||||
> 生活在普通文本世界么?以下是无需使用文字处理器而创建别人要的格式化文档的方法。
|
||||
|
||||
![][1]
|
||||
|
||||
如果你生活在[普通文本][2]世界里,总会有人要求你提供格式化文档。我就经常遇到这个问题,特别是在 Day JobTM。虽然我已经给与我合作的开发团队之一介绍了用于撰写和审阅发行说明的 [Docs Like Code][3] 工作流程,但是还有少数人对 GitHub 和使用 [Markdown][4] 没有兴趣,他们更喜欢为特定的专有应用格式化的文档。
|
||||
|
||||
好消息是,你不会被卡在将未格式化的文本复制粘贴到文字处理器的问题当中。使用 [pandoc][5],你可以快速地给人们他们想要的东西。让我们看看如何使用 pandoc 将文档从 Markdown 转换为 Linux 中的文字处理器格式。
|
||||
|
||||
请注意,pandoc 也可用于从两种 BSD([NetBSD][7] 和 [FreeBSD][8])到 Chrome OS、MacOS 和 Windows 等的各种操作系统。
|
||||
|
||||
### 基本转换
|
||||
|
||||
首先,在你的计算机上[安装 pandoc][9]。然后,打开控制台终端窗口,并导航到包含要转换的文件的目录。
|
||||
|
||||
输入此命令以创建 ODT 文件(可以使用 [LibreOffice Writer][10] 或 [AbiWord][11] 等字处理器打开):
|
||||
|
||||
```
|
||||
pandoc -t odt filename.md -o filename.odt
|
||||
```
|
||||
|
||||
记得用实际文件名称替换 `filename`。如果你需要为其他文字处理器(你知道我的意思)创建一个文件,替换命令行的 `odt` 为 `docx`。以下是本文转换为 ODT 文件时的内容:
|
||||
|
||||
![Basic conversion results with pandoc.][12]
|
||||
|
||||
这些转换结果虽然可用,但有点乏味。让我们看看如何为转换后的文档添加更多样式。
|
||||
|
||||
### 带样式转换
|
||||
|
||||
`pandoc` 有一个漂亮的功能,使你可以在将带标记的纯文本文件转换为字处理器格式时指定样式模板。在此文件中,你可以编辑文档中的少量样式,包括控制段落、文章标题和副标题、段落标题、说明、基本的表格和超链接的样式。
|
||||
|
||||
让我们来看看能做什么。
|
||||
|
||||
#### 创建模板
|
||||
|
||||
要设置文档样式,你不能只是使用任何一个模板就行。你需要生成 pandoc 称之为引用模板的文件,这是将文本文件转换为文字处理器文档时使用的模板。要创建此文件,请在终端窗口中键入以下内容:
|
||||
|
||||
```
|
||||
pandoc -o custom-reference.odt --print-default-data-file reference.odt
|
||||
```
|
||||
|
||||
此命令创建一个名为 `custom-reference.odt` 的文件。如果你正在使用其他文字处理程序,请将命令行中的 “odt” 更改为 “docx”。
|
||||
|
||||
在 LibreOffice Writer 中打开模板文件,然后按 `F11` 打开 LibreOffice Writer 的 “样式” 窗格。虽然 [pandoc 手册][13]建议不要对该文件进行其他更改,但我会在必要时更改页面大小并添加页眉和页脚。
|
||||
|
||||
#### 使用模板
|
||||
|
||||
那么,你要如何使用刚刚创建的模板?有两种方法可以做到这一点。
|
||||
|
||||
最简单的方法是将模板放在家目录的 `.pandoc` 文件夹中,如果该文件夹不存在,则必须先创建该文件夹。当转换文档时,`pandoc` 会使用此模板文件。如果你需要多个模板,请参阅下一节了解如何从多个模板中进行选择。
|
||||
|
||||
使用模板的另一种方法是在命令行键入以下转换选项:
|
||||
|
||||
```
|
||||
pandoc -t odt file-name.md --reference-doc=path-to-your-file/reference.odt -o file-name.odt
|
||||
```
|
||||
|
||||
如果你想知道使用自定义模板转换后的文件是什么样的,这是一个示例:
|
||||
|
||||
![A document converted using a pandoc style template.][14]
|
||||
|
||||
#### 选择模板
|
||||
|
||||
很多人只需要一个 `pandoc` 模板,但是,有些人需要不止一个。
|
||||
|
||||
例如,在我的日常工作中,我使用了几个模板:一个带有 DRAFT 水印,一个带有表示内部使用的水印,另一个用于文档的最终版本。每种类型的文档都需要不同的模板。
|
||||
|
||||
如果你有类似的需求,可以像使用单个模板一样创建文件 `custom-reference.odt`,将生成的文件重命名为例如 `custom-reference-draft.odt` 这样的名字,然后在 LibreOffice Writer 中打开它并修改样式。对你需要的每个模板重复此过程。
|
||||
|
||||
接下来,将文件复制到家目录中。如果你愿意,你甚至可以将它们放在 `.pandoc` 文件夹中。
|
||||
|
||||
要在转换时选择特定模板,你需要在终端中运行此命令:
|
||||
|
||||
```
|
||||
pandoc -t odt file-name.md --reference-doc=path-to-your-file/custom-template.odt -o file-name.odt
|
||||
```
|
||||
|
||||
改变 `custom-template.odt` 为你的模板文件名。
|
||||
|
||||
### 结语
|
||||
|
||||
为了不用记住我不经常使用的一组选项,我拼凑了一些简单的、非常蹩脚的单行脚本,这些脚本封装了每个模板的选项。例如,我运行脚本 `todraft.sh` 以使用带有 DRAFT 水印的模板创建文字处理器文档。你可能也想要这样做。
|
||||
|
||||
以下是使用包含 DRAFT 水印的模板的脚本示例:
|
||||
|
||||
```
|
||||
pandoc -t odt $1.md -o $1.odt --reference-doc=~/Documents/pandoc-templates/custom-reference-draft.odt
|
||||
```
|
||||
|
||||
使用 pandoc 是一种不必放弃命令行生活而以人们要求的格式提供文档的好方法。此工具也不仅适用于 Markdown。我在本文中讨论的内容还可以让你在各种标记语言之间创建和转换文档。有关更多详细信息,请参阅前面链接的 [pandoc 官网][5]。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/5/convert-markdown-to-word-pandoc
|
||||
|
||||
作者:[Scott Nesbitt][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/scottnesbitt/users/jason-van-gumster/users/kikofernandez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_keyboard_laptop_development_code_woman.png?itok=vbYz6jjb
|
||||
[2]: https://plaintextproject.online/
|
||||
[3]: https://www.docslikecode.com/
|
||||
[4]: https://en.wikipedia.org/wiki/Markdown
|
||||
[5]: https://pandoc.org/
|
||||
[6]: /resources/linux
|
||||
[7]: https://www.netbsd.org/
|
||||
[8]: https://www.freebsd.org/
|
||||
[9]: https://pandoc.org/installing.html
|
||||
[10]: https://www.libreoffice.org/discover/writer/
|
||||
[11]: https://www.abisource.com/
|
||||
[12]: https://opensource.com/sites/default/files/uploads/pandoc-wp-basic-conversion_600_0.png (Basic conversion results with pandoc.)
|
||||
[13]: https://pandoc.org/MANUAL.html
|
||||
[14]: https://opensource.com/sites/default/files/uploads/pandoc-wp-conversion-with-tpl_600.png (A document converted using a pandoc style template.)
|
@ -0,0 +1,117 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to enable DNS-over-HTTPS (DoH) in Firefox)
|
||||
[#]: via: (https://www.zdnet.com/article/how-to-enable-dns-over-https-doh-in-firefox/)
|
||||
[#]: author: (Catalin Cimpanu https://www.zdnet.com/meet-the-team/us/catalin.cimpanu/)
|
||||
|
||||
如何在 Firefox 中启用 DNS-over-HTTPS(DoH)
|
||||
======
|
||||
|
||||
DNS-over-HTTPS(DoH)协议目前是谈论的焦点,Firefox 是唯一支持它的浏览器。
|
||||
|
||||
但是,Firefox 默认不启用此功能,用户必须经历许多步骤并修改多个设置才能启动并运行 DoH。
|
||||
|
||||
在开始如何在 Firefox 中启用 DoH 支持的分步教程之前,让我们先描述它的原理。
|
||||
|
||||
### DNS-over-HTTPS 的工作原理
|
||||
|
||||
DNS-over-HTTPS 协议通过获取用户在浏览器中输入的域名,并向 DNS 服务器发送查询,以了解托管该站点的 Web 服务器的 IP 地址。
|
||||
|
||||
这也是正常 DNS 的工作原理。但是,DoH 通过 443 端口的加密 HTTPS 连接接受 DNS 查询将其发送到兼容 DoH 的 DNS 服务器(解析器),而不是在 53 端口上发送纯文本。
|
||||
|
||||
这样,DoH 就会在常规 HTTPS 流量中隐藏 DNS 查询,因此第三方监听者将无法嗅探流量,并了解用户的 DNS 查询,从而推断他们将要访问的网站。
|
||||
|
||||
此外,DNS-over-HTTPS 的第二个特性是协议工作在应用层。应用可以带上内部硬编码的 DoH 兼容的 DNS 解析器列表,从而向它们发送 DoH 查询。
|
||||
|
||||
这种操作模式绕过了系统级别的默认 DNS 设置,在大多数情况下,这些设置是由本地 Internet 服务提供商(ISP)设置的。
|
||||
|
||||
这也意味着支持 DoH 的应用可以有效地绕过本地 ISP 流量过滤器并访问可能被本地电信公司或当地政府阻止的内容 - 这也是 DoH 目前被誉为用户隐私和安全的福音的原因。
|
||||
|
||||
这是 DoH 在推出后不到两年的时间里获得相当大的普及的原因之一,同时也是一群[英国 ISP 因为 Mozilla 计划支持 DoH 协议提名它获得 2019 年的“互联网小人” (Internet Villian)][1]的,ISP 认为 DoH 协议会阻碍他们过滤不良流量的努力。
|
||||
|
||||
作为回应,并且由于英国政府阻止访问侵犯版权内容的复杂情况,以及 ISP 自愿阻止访问虐待儿童网站的情况,[Mozilla 已决定不为英国用户默认启用此功能][2]。
|
||||
|
||||
下面的分步指南将向英国和世界各地的 Firefox 用户展示如何立即启用该功能,而不用等到 Mozilla 将来启用它,如果它会这么做的话。在 Firefox 中有两种启用 DoH 支持的方法。
|
||||
|
||||
### 方法 1:通过 Firefox 设置
|
||||
|
||||
**步骤 1:**进入 Firefox 菜单,选择**工具**,然后选择**首选项**。 可选在 URL 栏中输入 **about:preferences**,然后按下回车。这将打开 Firefox 首选项部分。
|
||||
|
||||
**步骤 2:**在**常规**中,向下滚动到**网络设置**,然后按**设置**按钮。
|
||||
|
||||
![DoH section in Firefox settings][3]
|
||||
|
||||
图片:ZDNet
|
||||
|
||||
**步骤3:**在弹出窗口中,向下滚动并选择“ **Enable DNS over HTTPS**”,然后配置你需要的 DoH 解析器。你可以使用内置的 Cloudflare 解析器(该公司与 Mozilla [达成协议][4],记录更少的 Firefox 用户数据),或者你可以在[这个列表][4]中选择一个。
|
||||
|
||||
![DoH section in Firefox settings][6]
|
||||
|
||||
图片:ZDNet
|
||||
|
||||
### 方法 2:通过 about:config
|
||||
|
||||
**步骤 1:**在 URL 栏中输入 **about:config**,然后按回车访问 Firefox 的隐藏配置面板。在这里,用户需要启用和修改三个设置。
|
||||
|
||||
**步骤 2:**第一个设置是 **network.trr.mode**。这打开了 DoH 支持。此设置支持四个值:
|
||||
|
||||
* 0 - 标准 Firefox 安装中的默认值(当前为 5,表示禁用 DoH)
|
||||
* 1 - 启用 DoH,但 Firefox 依据哪个请求更快返回选择使用 DoH 或者常规 DNS
|
||||
* 2 - 启用 DoH,常规 DNS 作为备用
|
||||
* 3 - 启用 DoH,并禁用常规 DNS
|
||||
* 5 - 禁用 DoH
|
||||
|
||||
|
||||
|
||||
值为 2 工作得最好
|
||||
|
||||
![DoH in Firefox][7]
|
||||
|
||||
图片:ZDNet
|
||||
|
||||
**步骤3:**需要修改的第二个设置是 **network.trr.uri**。这是与 DoH 兼容的 DNS 服务器的 URL,Firefox 将向它发送 DoH DNS 查询。默认情况下,Firefox 使用 Cloudflare 的 DoH服务,地址是:<https://mozilla.cloudflare-dns.com/dns-query>。但是,用户可以使用自己的 DoH 服务器 URL。他们可以从[这个列表][8]中选择其中一个可用的。Mozilla 在 Firefox 中使用 Cloudflare 的原因是因为与这家公司[达成了协议][4],之后 Cloudflare 将收集来自 Firefox 用户的 DoH 查询的非常少的数据。
|
||||
|
||||
[DoH in Firefox][9]
|
||||
|
||||
图片:ZDNet
|
||||
|
||||
**步骤4:**第三个设置是可选的,你可以跳过此设置。 但是如果设置不起作用,你可以使用此作为步骤 3 的备用。该选项名为 **network.trr.bootstrapAddress**,它是一个输入字段,用户可以输入步骤 3 中兼容 DoH 的 DNS 解析器的 IP 地址。对于 Cloudflare,它是 1.1.1.1。 对于 Google 服务,它是 8.8.8.8。 如果你使用了另一个 DoH 解析器的 URL,如果有必要的话,你需要追踪那台服务器的 IP 地址并输入。
|
||||
|
||||
![DoH in Firefox][10]
|
||||
|
||||
图片:ZDNet
|
||||
|
||||
通常,在步骤 3 中输入的 URL 应该足够了。
|
||||
|
||||
Settings should apply right away, but in case they don't work, give Firefox a restart.
|
||||
设置应该立即生效,但如果它们不起作用,请重新启动 Firefox。
|
||||
|
||||
文章来源:[Mozilla Wiki][11]
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.zdnet.com/article/how-to-enable-dns-over-https-doh-in-firefox/
|
||||
|
||||
作者:[Catalin Cimpanu][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://www.zdnet.com/meet-the-team/us/catalin.cimpanu/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.zdnet.com/article/uk-isp-group-names-mozilla-internet-villain-for-supporting-dns-over-https/
|
||||
[2]: https://www.zdnet.com/article/mozilla-no-plans-to-enable-dns-over-https-by-default-in-the-uk/
|
||||
[3]: https://zdnet1.cbsistatic.com/hub/i/2019/07/07/df30c7b0-3a20-4de7-8640-3dea6d249a49/121bd379b6232e1e2a97c35ea8c7764e/doh-settings-1.png
|
||||
[4]: https://developers.cloudflare.com/1.1.1.1/commitment-to-privacy/privacy-policy/firefox/
|
||||
[6]: https://zdnet3.cbsistatic.com/hub/i/2019/07/07/8608af28-2a28-4ff1-952b-9b6d2deb1ea6/b1fc322caaa2c955b1a2fb285daf0e42/doh-settings-2.png
|
||||
[7]: https://zdnet1.cbsistatic.com/hub/i/2019/07/06/0232b3a7-82c6-4a6f-90c1-faf0c090254c/6db9b36509021c460fcc7fe825bb74c5/doh-1.png
|
||||
[8]: https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers
|
||||
[9]: https://zdnet2.cbsistatic.com/hub/i/2019/07/06/4dd1d5c1-6fa7-4f5b-b7cd-b544748edfed/baa7a70ac084861d94a744a57a3147ad/doh-2.png
|
||||
[10]: https://zdnet1.cbsistatic.com/hub/i/2019/07/06/8ec20a28-673c-4a17-8195-16579398e90a/538fe8420f9b24724aeb4a6c8d4f0f0f/doh-3.png
|
||||
[11]: https://wiki.mozilla.org/Trusted_Recursive_Resolver
|
Loading…
Reference in New Issue
Block a user