Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-12-31 09:22:14 +08:00
commit 8739c794ba
8 changed files with 504 additions and 150 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12968-1.html)
[#]: subject: (Font Manager: A Simple Open-Source App for GTK+ Desktop)
[#]: via: (https://itsfoss.com/font-manager/)
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
@ -10,11 +10,13 @@
Font Manager一个简单的 GTK+ 桌面的开源应用
======
_**简介:一个非常简单的字体管理器应用,让你专注于调整 Linux 系统上的字体。**_
![](https://img.linux.net.cn/data/attachment/album/202012/30/065754mx4363qxabe8y9z0.jpg)
如果你是一个有经验的 Linux 用户,你可能会利用终端或 [tweak 工具][1]来管理你的 Linux 系统的字体。
> 一个非常简单的字体管理器应用,让你专注于调整 Linux 系统上的字体。
老实说,不管 GNOME tweak 工具有多有用,仅仅管理字体可能会让人有点受不了。因此,一个单独的应用可以很好地帮助你管理字体。
如果你是一个有经验的 Linux 用户,你可能会利用终端或 [调整工具][1]来管理你的 Linux 系统的字体。
老实说,不管 GNOME 调整工具有多有用,但是用来管理字体可能会不太够用。因此,一个单独的应用可以很好地帮助你管理字体。
### Font Manager一个帮助管理字体的开源应用
@ -22,7 +24,7 @@ _**简介:一个非常简单的字体管理器应用,让你专注于调整 L
Font Manager这就是应用的字面名称是一个专门帮助你管理字体的应用。
你可以获得字体家族的详细信息,可用的变体,以及根据字体的高度、宽度、间距等进行过滤和调整的功能。考虑到它是一个简单的应用,因此你找不到很多功能,但是我将在下面简要介绍一些功能。
你可以获得字体族的详细信息、可用的变体,以及根据字体的高度、宽度、间距等进行过滤和调整的功能。考虑到它是一个简单的应用,因此你找不到很多功能,但是我将在下面简要介绍一些功能。
### Font Manager 的功能
@ -30,19 +32,17 @@ Font Manager这就是应用的字面名称是一个专门帮助你管理
* 可以添加字体
* 可以删除字体
* 根据家族、供应商、间距、高度等因素轻松过滤字体
* 根据字体族、供应商、间距、高度等因素轻松筛选字体
* 调整字体的缩放系数
* 调整字体的抗锯齿(软度/锐度)
* 添加字体源,以便在安装前进行预览
* 提供快速管理的键盘快捷键
* 开箱即用的谷歌字体集成
* 获取关于家族字体中可用字符的详细信息、许可证、字体大小、供应商、文件类型、间距、宽度和样式
* 获取关于字体族中可用字符的详细信息、许可证、字体大小、供应商、文件类型、间距、宽度和样式
![][4]
总的来说,你可以轻松安装或删除字体。但是,当你管理字体时,你会得到相当多的好处,如上面的截图所示。
总的来说,你可以轻松安装或删除字体。但是,当你管理字体时,你会得到很多帮助,如上面的截图所示。
### 在 Linux 上安装 Font Manager
@ -56,7 +56,7 @@ sudo apt update
sudo apt install font-manager
```
如果你不喜欢 [PPAs][5](我更喜欢这样安装),你也可以在任何 Linux 发行版上安装一个[可用的 Flatpak 包][6]。
如果你不喜欢 [PPA][5](我更喜欢这样安装),你也可以在任何 Linux 发行版上安装一个[可用的 Flatpak 包][6]。
你只需要在你的 Linux 系统上启用 Flatpak然后在你的软件中心搜索它如果它支持 Flatpak 集成的话),或者直接输入下面的命令安装它:
@ -69,13 +69,13 @@ flatpak install flathub org.gnome.FontManager
更多的安装说明,你可以参考它的[官网][9]和 [GitHub 页面][10]。
[下载 Font Manager][9]
- [下载 Font Manager][9]
### 总结
Font Manager 是一个简单的解决方案,适用于任何基于 GTK+ 的桌面环境。主要用于 GNOME但你在其他桌面环境使用它。
你可以得到很多有用的信息,同时可以添加或删除字体,我想这显然是一个不折不扣的字体管理器。
你可以得到很多有用的信息,同时可以添加或删除字体,我想这显然是一个真正的字体管理器。
你对 Font Manager 有什么看法?在下面的评论中告诉我你的想法吧!
@ -86,7 +86,7 @@ via: https://itsfoss.com/font-manager/
作者:[Ankush Das][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/) 荣誉推出

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (zhangxiangping)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
@ -241,7 +241,7 @@ via: https://fedoramagazine.org/latex-typesetting-part-1/
作者:[Earl Ramirez][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[zhangxiangping](https://github.com/zxp93)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,131 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to use heredoc as a text editor)
[#]: via: (https://opensource.com/article/20/12/heredoc)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
How to use heredoc as a text editor
======
This obscure terminal feature provides a text editor in a pinch.
![woman on laptop sitting at the window][1]
Theres a somewhat obscure feature in Linux and Unix shells that allows you to open a sort of do-while loop for the [cat][2] command. Its called the _heredoc_, and it enables you to have, more or less, a text editor no matter what shell youre using. The syntax is:
```
`$ cat << EOF >> example.txt`
```
The string in the middle is, essentially, a conditional that stops the loop. That is, if you type alone on a line, the loop ends. During the loop, whatever you type into your terminal is piped into the destination file (in this case).
### Installing
As long as you have a terminal, you already have the ability to initiate a heredoc. Ive used this syntactical trick in [Bash][3], [tsch][4], and Korn shell.
### Using heredoc
To open a heredoc "session", you use the cat command with redirection that points first to cat with a terminating string (common convention is **EOF** for "End Of File", but it can actually be anything). After the terminating keyword, you redirect your output to a destination file. You're then able to type directly into your terminal, using most common shell keyboard shortcuts to navigate through your work. Your session ends when you type your designated terminating string on a line by itself. You know you're in a heredoc loop by the unique prompt (usually the **&gt;** character).
```
$ cat &lt;&lt; EOF &gt;&gt; example.txt
&gt; Everything you type here will be placed into example.txt when I type EOF on a line by itself. Until then, you can type...
&gt;
&gt; whatever...
&gt;
&gt; you want to type.
&gt;
&gt; EOF
$  
```
Everything you enter while your terminal is waiting for **EOF** is placed into the destination file. Prompt characters are omitted, and EOF itself is not part of the file.
```
Everything you type here will be placed into example.txt when I type EOF on a line by itself. Until then, you can type...
whatever...
you want to type.
```
Realistically, youre probably not going to use heredoc syntax as a substitute for a good text editor. It's a great quick hack to enter more than one line, but more than 10 lines or so starts to strain its usefulness. For instance, you cant go up to edit previous lines without triggering your shells [history][5] function. Depending on your shell and how it's configured, you may be able to go up, then down to recall your text, and then move back through your text with **Ctrl+B**. 
Most features of your shell work as expected, but theres probably no undo and very little error recovery.
And besides, even the most minimal of installs are likely to have at least [Vi][6] or [ed][7] installed.
And yet heredoc is still useful! It's more flexible than **echo**, and when youre working on a shell script, it's indispensable. For instance, imagine youre writing an installer script so you can automate the install of a set of custom applications. One of the applications isnt distributed with a `.dekstop` file, so it does not appear in your Application menu. To fix this, you decide to generate a `.desktop` file at install time.
Rather than writing a `.desktop` file and carrying it around as an external dependency for your install script, you could use heredoc in your install script itself:
```
#!/bin/sh
VERSION=${VERSION:-x.y.z}
PKGNAM=${VERSION:-example}
PKG="${PKGNAM}"-"${VERSION}"-`arch`.tgz
# download package
wget "${PKG}"
tar txvf "${PKG}"
# use here doc to create missing .desktop file
cat &lt;&lt; EOF &gt;&gt; $HOME/.local/share/applications/example.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name="${PKGNAM}"
Comment="${PKGNAM}"
Exec="${PKGNAM}" %F
EOF
# insert the rest of an install script...
```
You have automated text entry into a file, no text editor involved (except the one you use to write your script, obviously). Heres what the resulting `.desktop` file looks like:
```
[Desktop Entry]
Version=1.0
Type=Application
Name=example
Comment=example
Exec=example %F
```
As you can see, you can use variables within the heredoc, and theyre correctly resolved. The `EOF` string doesnt appear in the file; it only signals the end of the heredoc.
### Better than echo
The heredoc technique is generally considered easier than `echo` or [printf][8] because once youre "in" the document, youre free to do whatever you want. Its liberating in that sense, but its limited compared to a proper text editor.
Use heredoc for quick notes and for shell scripts, and never puzzle over how to dynamically generate configuration files again.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/heredoc
作者:[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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lenovo-thinkpad-laptop-window-focus.png?itok=g0xPm2kD (young woman working on a laptop)
[2]: https://opensource.com/article/19/2/getting-started-cat-command
[3]: https://opensource.com/article/20/4/bash-sysadmins-ebook
[4]: https://opensource.com/article/20/8/tcsh
[5]: https://opensource.com/article/20/6/bash-history-commands
[6]: https://opensource.com/article/19/3/getting-started-vim
[7]: https://opensource.com/article/20/12/gnu-ed
[8]: https://opensource.com/article/20/8/printf

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,150 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Choose between Btrfs and LVM-ext4)
[#]: via: (https://fedoramagazine.org/choose-between-btrfs-and-lvm-ext4/)
[#]: author: (Troy Curtis Jr https://fedoramagazine.org/author/troycurtisjr/)
Choose between Btrfs and LVM-ext4
======
![][1]
Photo by [Raul Petri][2] on [Unsplash][3]
[Fedora 33][4] introduced a new default filesystem in desktop variants, [Btrfs][5]. After years of Fedora using [ext4][6] on top of [Logical Volume Manager (LVM)][7] volumes, this is a big shift. Changing the default file system requires [compelling reasons][8]. While Btrfs is an exciting next-generation file system, ext4 on LVM is well established and stable. This guide aims to explore the high-level features of each and make it easier to choose between Btrfs and LVM-ext4.
### In summary
The simplest advice is to stick with the defaults. A fresh Fedora 33 install defaults to Btrfs and upgrading a previous Fedora release continues to use whatever was initially installed, typically LVM-ext4. For an existing Fedora user, the cleanest way to get Btrfs is with a fresh install. However, a fresh install is much more disruptive than a simple upgrade. Unless there is a specific need, this disruption could be unnecessary. The Fedora development team carefully considered both defaults, so be confident with either choice.
### What about all the other file systems?
There are a [large number of file systems for Linux systems][9]. The number explodes after adding in combinations of volume managers, encryption methods, and storage mechanisms . So why focus on Btrfs and LVM-ext4? For the Fedora audience these two setups are likely to be the most common. Ext4 on top of LVM became the default disk layout in Fedora 11, and ext3 on top of LVM came before that.
Now that Btrfs is the default for Fedora 33, the vast majority of existing users will be looking at whether they should stay where they are or make the jump forward. Faced with a fresh Fedora 33 install, experienced Linux users may wonder whether to use this new file system or fall back to what they are familiar with. So out of the wide field of possible storage options, many Fedora users will wonder how to choose between Btrfs and LVM-ext4.
### Commonalities
Despite core differences between the two setups, Btrfs and LVM-ext4 actually have a lot in common. Both are mature and well-tested storage technologies. LVM has been in continuous use since the early days of Fedora Core and ext4 became the [default in 2009 with Fedora 11][10]. Btrfs merged into the mainline Linux kernel in 2009 and [Facebook uses it widely][11]. SUSE Linux Enterprise 12 made it the [default in 2014][12]. So there is plenty of production run time there as well.
Both systems do a great job preventing file system corruption due to unexpected power outages, even though the way they accomplish it is different. Supported configurations include single drive setups as well as spanning multiple devices, and both are capable of creating nearly instant snapshots. A variety of tools exist to help manage either system, both with the command line and graphical interfaces. Either solution works equally well on home desktops and on high-end servers.
### Advantages of LVM-ext4
![Structure of ext4 on LVM][13]
The [ext4 file system][14] focuses on high-performance and scalability, without a lot of extra frills. It is effective at preventing fragmentation over extended periods of time and provides [nice tools][15] for when it does happen. Ext4 is rock solid because it built on the previous ext3 file system, bringing with it all the years of in-system testing and bug fixes.
Most of the advanced capabilities in the LVM-ext4 setup come from LVM itself. LVM sits “below” the file system, which means it supports any file system. Logical volumes (LV) are generic block devices so [virtual machines can use them directly.][16] This flexibility allows each logical volume to use the right file system, with the right options, for a variety of situations. This layered approach also honors the Unix philosophy of small tools working together.
The [volume group][17] (VG) abstraction from the hardware allows LVM to create flexible logical volumes. Each LV pulls from the same storage pool but has its own configuration. Resizing volumes is a lot easier than resizing physical partitions as there are no limitation of ordered placement of the data. LVM [physical volumes][18] (PV) can be any number of partitions and can even move between devices while the system is running.
LVM supports read-only and read-write [snapshots][19], which make it easy to create consistent backups from active systems. Each snapshot has a defined size, and a change to the source or snapshot volume use space from there. Alternately, logical volumes can also be part of a [thinly provisioned pool][20]. This allows snapshots to automatically use data from a pool instead of consuming fixed sized chunks defined at volume creation.
#### Multiple devices with LVM
LVM really shines when there are multiple devices. It has native support for most [RAID levels][21] and each logical volume can have a different RAID level. LVM will automatically choose appropriate physical devices for the RAID configuration or the user can specify it directly. Basic RAID support includes data striping for performance ([RAID0][22]) and mirroring for redundancy ([RAID1][23]). Logical volumes can also use advanced setups like [RAID5][24], [RAID6][25], and [RAID10][26]. LVM RAID support is mature because under the hood LVM uses the same [device-mapper (dm)][27] and [multiple-device (md)][28] kernel support used by [mdadm][29].
Logical volumes can also be [cached volumes][30] for systems with both fast and slow drives. A classic example is a combination of SSD and spinning-disk drives. Cached volumes use faster drives for more frequently accessed data (or as a write cache), and the slower drive for bulk data.
The large number of stable features in LVM and the reliable performance of ext4 are a testament to how long they have been in use. Of course, with more features comes complexity. It can be challenging to find the right options for the right feature when configuring LVM. For single drive desktop systems, features of LVM like RAID and cache volumes dont apply. However, logical volumes are more flexible than physical partitions and snapshots are useful. For normal desktop use, the complexity of LVM can also be a barrier to recovering from issues a typical user might encounter.
### Advantages of Btrfs
![Btrfs Structure][31]
Lessons learned from previous generations guided the features built into [Btrfs][5]. Unlike ext4, it can directly span multiple devices, so it brings along features typically found only in volume managers. It also has features that are unique in the Linux file system space ([ZFS][32] has a similar feature set, but [dont expect it in the Linux kernel][33]).
#### Key Btrfs features
Perhaps the most important feature is the checksumming of all data. Checksumming, along with copy-on-write, provides the [key method][34] of ensuring file system integrity after unexpected power loss. More uniquely, checksumming can detect errors in the data itself. Silent data corruption, sometimes referred to as [bitrot][35], is more common that most people realize. Without active validation, corruption can end up propagating to all available backups. This leaves the user with no valid copies. By transparently checksumming all data, Btrfs is able to immediately detect any such corruption. Enabling the right [dup or raid option][36] allows the file system to transparently fix the corruption as well.
[Copy-on-write][37] (COW) is also a fundamental feature of Btrfs, as it is critical in providing file system integrity and instant subvolume snapshots. Snapshots automatically share underlying data when created from common subvolumes. Additionally, after-the-fact [deduplication][38] uses the same technology to eliminate identical data blocks. Individual files can use COW features by calling _cp_ with the [reflink option][39]. Reflink copies are especially useful for copying large files, such as virtual machine images, that tend to have mostly identical data over time.
Btrfs supports spanning multiple devices with no volume manager required. Multiple device support unlocks data mirroring for redundancy and striping for performance. There is also experimental support for more advanced RAID levels, such as [RAID5][24] and [RAID6][25]. Unlike standard RAID setups, the Btrfs _raid1_ option actually allows an odd number of devices. For example, it can use 3 devices, even if they are are different sizes.
All RAID and dup options are specified at the file system level. As a consequence, individual subvolumes cannot use different options. Note that using the RAID1 option with multiple devices means that all data in the volume is available even if one device fails and the checksum feature maintains the integrity of the data itself. That is beyond what current typical RAID setups can provide.
#### Additional features
Btrfs also enables quick and easy remote backups. Subvolume snapshots can be [sent to a remote system][40] for storage. By leveraging the inherent COW meta-data in the file system, these transfers are efficient by only sending incremental changes from previously sent snapshots. User applications such as [snapper][41] make it easy to manage these snapshots.
Additionally, a Btrfs volume can have [transparent compression][42] and _[chattr +c][43]_ will mark individual files or directories for compression. Not only does compression reduce the space consumed by data, but it helps extend the life of SSDs by reducing the volume of write operations. Compression certainly introduces additional CPU overhead, but a lot of options are available to dial in the right trade-offs.
The integration of file system and volume manager functions by Btrfs means that overall maintenance is simpler than LVM-ext4. Certainly this integration comes with less flexibility, but for most desktop, and even server, setups it is more than sufficient.
### Btrfs on LVM
Btrfs can [convert an ext3/ext4 file system in place][44]. In-place conversion means no data to copy out and then back in. The data blocks themselves are not even modified. As a result, one option for an existing LVM-ext4 systems is to leave LVM in place and simply convert ext4 over to Btrfs. While doable and supported, there are reasons why this isnt the best option.
Some of the appeal of Btrfs is the easier management that comes with a file system integrated with a volume manager. By running on top of LVM, there is still some other volume manager in play for any system maintenance. Also, LVM setups typically have multiple fixed sized logical volumes with independent file systems. While Btrfs supports multiple volumes in a given computer, many of the nice features expect a single volume with multiple subvolumes. The user is still stuck manually managing fixed sized LVM volumes if each one has an independent Btrfs volume. Though, the ability to shrink mounted Btrfs filesystems does make working with fixed sized volumes less painful. With online shrink there is no need to boot a [live image][45].
The physical locations of logical volumes must be carefully considered when using the multiple device support of Btrfs. To Btrfs, each LV is a separate physical device and if that is not actually the case, then certain data availability features might make the wrong decision. For example, using _raid1_ for data typically provides protection if a single drive fails. If the actual logical volumes are on the same physical device, then there is no redundancy.
If there is a strong need for some particular LVM feature, such as raw block devices or cached logical volumes, then running Btrfs on top of LVM makes sense. In this configuration, Btrfs still provides most of its advantages such as checksumming and easy sending of incremental snapshots. While LVM has some operational overhead when used, it is no more so with Btrfs than with any other file system.
### Wrap up
When trying to choose between Btrfs and LVM-ext4 there is no single right answer. Each user has unique requirements, and the same user may have different systems with different needs. Take a look at the feature set of each configuration, and decide if there is something compelling about one over the other. If not, there is nothing wrong with sticking with the defaults. There are excellent reasons to choose either setup.
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/choose-between-btrfs-and-lvm-ext4/
作者:[Troy Curtis Jr][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://fedoramagazine.org/author/troycurtisjr/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/12/btrfs-lvm-ext4-816x345.jpg
[2]: https://unsplash.com/@raulpetri?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[3]: https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[4]: https://fedoramagazine.org/announcing-fedora-33/
[5]: https://btrfs.wiki.kernel.org/index.php/Main_Page
[6]: https://ext4.wiki.kernel.org/index.php/Main_Page
[7]: https://man7.org/linux/man-pages/man8/lvm.8.html
[8]: https://fedoraproject.org/wiki/Changes/BtrfsByDefault
[9]: https://man7.org/linux/man-pages/man5/filesystems.5.html
[10]: https://docs.fedoraproject.org/en-US/Fedora/11/html/Release_Notes/index.html#sect-Release_Notes-Fedora_11_Overview
[11]: https://facebookmicrosites.github.io/btrfs/docs/btrfs-facebook.html
[12]: https://www.suse.com/releasenotes/x86_64/SUSE-SLES/12/#fate-317221
[13]: https://fedoramagazine.org/wp-content/uploads/2020/12/ext4-on-LVM.jpg
[14]: https://opensource.com/article/18/4/ext4-filesystem
[15]: https://man7.org/linux/man-pages/man8/e4defrag.8.html
[16]: https://libvirt.org/storage.html#StorageBackendLogical
[17]: https://www.redhat.com/sysadmin/create-volume-group
[18]: https://www.redhat.com/sysadmin/create-physical-volume
[19]: https://tldp.org/HOWTO/LVM-HOWTO/snapshotintro.html
[20]: https://man7.org/linux/man-pages/man7/lvmthin.7.html
[21]: https://rhea.dev/articles/2018-08/LVM-RAID-on-Fedora
[22]: https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_0
[23]: https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_1
[24]: https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_5
[25]: https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_6
[26]: https://en.wikipedia.org/wiki/Non-standard_RAID_levels#Linux_MD_RAID_10
[27]: https://man7.org/linux/man-pages/man8/dmsetup.8.html
[28]: https://man7.org/linux/man-pages/man4/md.4.html
[29]: https://fedoramagazine.org/managing-raid-arrays-with-mdadm/
[30]: https://man7.org/linux/man-pages/man7/lvmcache.7.html
[31]: https://fedoramagazine.org/wp-content/uploads/2020/12/Btrfs-Volume.jpg
[32]: https://en.wikipedia.org/wiki/ZFS
[33]: https://itsfoss.com/linus-torvalds-zfs/
[34]: https://btrfs.wiki.kernel.org/index.php/FAQ#Can_I_have_nodatacow_.28or_chattr_.2BC.29_but_still_have_checksumming.3F
[35]: https://arstechnica.com/information-technology/2014/01/bitrot-and-atomic-cows-inside-next-gen-filesystems/
[36]: https://man7.org/linux/man-pages/man8/mkfs.btrfs.8.html#DUP_PROFILES_ON_A_SINGLE_DEVICE
[37]: https://en.wikipedia.org/wiki/Copy-on-write
[38]: https://btrfs.wiki.kernel.org/index.php/Deduplication
[39]: https://btrfs.wiki.kernel.org/index.php/UseCases#How_do_I_copy_a_large_file_and_utilize_COW_to_keep_it_from_actually_being_copied.3F
[40]: https://fedoramagazine.org/btrfs-snapshots-backup-incremental/
[41]: http://snapper.io/
[42]: https://btrfs.wiki.kernel.org/index.php/Compression
[43]: https://www.man7.org/linux/man-pages/man1/chattr.1.html
[44]: https://btrfs.wiki.kernel.org/index.php/Conversion_from_Ext3
[45]: https://fedoramagazine.org/reclaim-hard-drive-space-with-lvm/

View File

@ -0,0 +1,131 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Learn Lua by writing a "guess the number" game)
[#]: via: (https://opensource.com/article/20/12/lua-guess-number-game)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Learn Lua by writing a "guess the number" game
======
Get to know Lua, a dynamically typed, lightweight, efficient, and
embeddable scripting language, by programming a simple game.
![Puzzle pieces coming together to form a computer screen][1]
If you're a fan of scripting languages like Bash, Python, or Ruby, you might find Lua interesting. Lua is a dynamically typed, lightweight, efficient, and embeddable scripting language with an API to interface with C. It runs by interpreting bytecode with a register-based virtual machine, and it can be used for everything from procedural programming to functional programming to data-driven programming. It can even be used for object-oriented programming through the clever use of arrays, or _tables_, used to mimic classes.
A great way to get a feel for a language is by writing a simple application you're already familiar with. Recently, some Opensource.com correspondents have demonstrated how to use their favorite languages to create a number-guessing game. [Lua][2] is one of my favorites, so here's my Lua version of the guessing game.
### Install Lua
If you're on Linux, you can install Lua from your distribution's software repository. On macOS, you can install Lua from [MacPorts][3] or [Homebrew][4]. On Windows, you can install Lua from [Chocolatey][5].
Once you have Lua installed, open your favorite text editor and get ready to code.
### Lua code
First, you must set up a pseudo-random number generator, so your player has something unpredictable to try to guess. This is a two-step process: first, you start a random seed based on the current time, and then you select a number within the range of 1 to 100:
```
math.randomseed(os.[time][6]())
number = math.random(1,100)
```
Next, create what Lua calls a _table_ to represent your player. A table is like an [array in Bash][7] or an ArrayList in Java. You can create a table and then assign child variables associated with that table. In this code, `player` is the table, and `player.guess` is an entry in that table:
```
player = {}
player.guess = 0
```
For the purpose of debugging, print the secret number. This isn't good for the game, but it's great for testing. Comments in Lua are preceded by double dashes:
```
`print(number) --debug`
```
Next, set up a `while` loop that runs forever upon the condition that the value assigned to `player.guess` is not equal to the random `number` established at the start of the code. Currently, `player.guess` is set to 0, so it is not equal to `number`. Lua's math operator for inequality is `~=`, which is admittedly unique, but you get used to it after a while.
The first thing that happens during this infinite loop is that the game prints a prompt so that the player understands the game.
Next, Lua pauses and waits for the player to enter a guess. Lua reads from files and standard in (stdin) using the `io.read` function. You can assign the results of `io.read` to a variable that is dynamically created in the `player` table. The problem with the player's input is that it is read as a string, even if it's a number. You can convert this input to an integer type using the `tonumber()` function, assigning the result back to the `player.guess` variable that initially contained 0:
```
while ( player.guess ~= number ) do
  print("Guess a number between 1 and 100")
  player.answer = io.read()
  player.guess = tonumber(player.answer)
```
Now that `player.guess` contains a new value, it's compared to the random number in an `if` statement. Lua uses the keywords `if`, `elseif`, and `else` and terminates the statement with the keyword `end:`
```
  if ( player.guess &gt; number ) then
    print("Too high")
  elseif ( player.guess &lt; number) then
    print("Too low")
  else
    print("That's right!")
    os.[exit][8]()
  end
end
```
At the end, the function `os.exit()` closes the application upon success and the keyword `end` is used twice: once to end the `if` statement and again to end the `while` loop.
### Run the application
Run the game in a terminal:
```
$ lua ./guess.lua
96
Guess a number between 1 and 100
1
Too low
Guess a number between 1 and 100
99
Too high
Guess a number between 1 and 100
96
That's right!
```
That's it!
### Intuitive and consistent
As you may be able to tell from this code, Lua is sublimely consistent and fairly intuitive. Its table mechanism is a refreshing way of associating data, and its syntax is minimalistic and efficient. There are few wasted lines in Lua code; in fact, at least one pair of lines in this example could be optimized further, but I wanted to demonstrate data conversion as its own step (maybe you can find the two lines I'm referring to and restructure them).
Lua is a pleasure to use, and its [documentation is a pleasure to read][9], mostly because there's just not that much to it. You'll learn the core language in no time, and then you'll be free to explore [LuaRocks][10] to discover all the great libraries others have contributed to make your time with Lua even easier. "Lua" means "moon" in Portuguese, so give it a try tonight.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/lua-guess-number-game
作者:[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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/puzzle_computer_solve_fix_tool.png?itok=U0pH1uwj (Puzzle pieces coming together to form a computer screen)
[2]: https://www.lua.org/
[3]: https://opensource.com/article/20/11/macports
[4]: https://opensource.com/article/20/6/homebrew-mac
[5]: https://opensource.com/article/20/3/chocolatey
[6]: http://www.opengroup.org/onlinepubs/009695399/functions/time.html
[7]: https://opensource.com/article/20/6/associative-arrays-bash
[8]: http://www.opengroup.org/onlinepubs/009695399/functions/exit.html
[9]: https://www.lua.org/docs.html
[10]: https://opensource.com/article/19/11/getting-started-luarocks

View File

@ -0,0 +1,73 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Use the Markdown Editor app in Nextcloud)
[#]: via: (https://opensource.com/article/20/12/nextcloud-markdown)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Use the Markdown Editor app in Nextcloud
======
Nextcloud has one of the smoothest editors of the popular Markdown file
type, with lots of convenient and intuitive features.
![Digital images of a computer desktop][1]
The advantage of plain text is that theres no extra computer-specific information cluttering up your otherwise human-readable writing. The good thing about computers is that theyre programmable, and so as long as we humans agree to follow very specific conventions when writing, we can program computers to interpret human-readable text as secret instructions. For instance, by surrounding a word with two asterisks, we not only give a visual cue to humans that a word is significant, but we can also program computers to display the word in **bold**.
This is exactly the theory and practice behind [Markdown][2], the popular plain text format that promises writers that as long as _they_ use specific plain text conventions, then their text will be rendered with a specific style.
Traditionally, that has meant that an author writes in plain text and doesnt see the pretty styling until the text is fed to a converter application (originally `markdown.pl`), but the Markdown Editor app in Nextcloud changes that.
With Nextclouds Markdown Editor, you can type in plain text while seeing the style it renders. This is a gamechanger for authors who struggle to remember Markdowns sometimes confusing notation (do the brackets become before or after the parentheses in a hyperlink?) or who just dont like the look of plain text. And better yet, it runs in the (Next)cloud, so its available to you anywhere.
### Install
To use Nextclouds Markdown Editor, you must have an install of Nextcloud. The good news is, Nextcloud is surprisingly _easy_ to install. Ive installed it on a Raspberry Pi, on a shared server, and even as a local app (which is silly, dont do it). If you dont trust your own abilities, you can even rely on [Turnkey Linux][3] to do the hard part for you, or else just purchase managed hosting directly from [Nextcloud.com][4]. Once you have Nextcloud installed, adding apps is simple. Click on your user icon in the top right corner of the Nextcloud interface and select **Apps**. Navigate to the **Office and Text** category and click to install and enable the **Markdown Editor**.
![Nextcloud app store showing Markdown Editor installer][5]
### Launching
After activation, the Markdown Editor gets associated with any file ending in .md in your Nextcloud files, so when you open a Markdown file, you launch Markdown Editor.
### Using Markdown Editor
The Markdown Editor contains a large text field for you to type into and a single toolbar along the top.
![Example markdown file ][6]
The toolbar contains the basic functions of a word processor—styling your text with bold, italics, and strike-through, creating headings and paragraphs, lists, and so on.
Many of these functions get invoked automatically as you type if you know Markdown. If youre not familiar with Markdown, then the toolbar or the usual keyboard shortcuts (**Ctrl+B** for bold, **Ctrl+I** for italics, and so on) help you style your text.
The great thing about the way Markdown Editor works is that it truly is all things for all users: if you want to type in Markdown, then it accepts that and instantly converts it into visual styling, and if you dont want to think about Markdown, then it generates the style for you when you use keyboard shortcuts or toolbar buttons. Either way, you never have to see the Markdown syntax, but you also never lose it. Its the perfect compromise.
Its an awfully smart editor, too. It offers to create a hyperlink for you when you select a word, it auto-converts Markdown quickly and smoothly, and it knows a few different "flavors" of Markdown syntax (Commonmark primarily, but also traditional Markdown, Github Markdown, and so on).
![black text on white background, word highlighted in blue to create an automatic link][7]
### Try Nextcloud
Ive used a few Markdown preview applications, and Nextclouds Markdown Editor is one of the smoothest. It respects its user and does the bare minimum to display Markdown, so its conversion is fast and accurate. Because its an app in Nextcloud, you also get the benefit of having your work saved instantly, with version control, on your own private, open source cloud. Text editing doesnt get much better than that.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/nextcloud-markdown
作者:[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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_desk_home_laptop_browser.png?itok=Y3UVpY0l (Digital images of a computer desktop)
[2]: https://opensource.com/article/19/9/introduction-markdown
[3]: https://www.turnkeylinux.org/nextcloud
[4]: http://nextcloud.com
[5]: https://opensource.com/sites/default/files/uploads/nextcloud-app-install-31_days-markdown-opensource.jpg (Nextcloud app store showing Markdown Editor installer)
[6]: https://opensource.com/sites/default/files/uploads/nextcloud-markdown-31-days-opensource.jpg (Example markdown file )
[7]: https://opensource.com/sites/default/files/uploads/nextcloud-link-31_days_markdown-opensource.jpg (black text on white background, word highlighted in blue to create an automatic link)

View File

@ -0,0 +1,131 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to use heredoc as a text editor)
[#]: via: (https://opensource.com/article/20/12/heredoc)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
如何使用 heredoc 作为一个文本编辑器
======
这个不起眼的终端功能在紧要关头提供了一个文本编辑器。
![woman on laptop sitting at the window][1]
在 Linux 和 Unix shells 中有一个不为人知的功能,它能让你为 [cat][2] 命令打开一个 do-while 循环。它被称为 _heredoc_,无论你使用什么 shell它都能让你或多或少地拥有一个文本编辑器。它的语法是
```
`$ cat << EOF >> example.txt`
```
中间的字符串,本质上是一个停止循环的条件。也就是说,如果你在一行中单独输入它,循环就会结束。在循环过程中,无论你在终端中输入什么,都会被管道传送到目标文件中(在本例中)。
### 安装
只要你有一个终端,你就能够启动 heredoc。我在 [Bash][3]、[tsh][4] 和 Korn shell 中使用过这个语法技巧。
### 使用 heredoc
要打开一个 heredoc “会话”,你可以使用 cat 命令重定向,它首先指向具有终止字符串的 cat常见约定是 **EOF**,代表 “End Of File”但它实际上可以是任何东西。在终止关键字之后你将输出重定向到一个目标文件。然后你就可以直接在终端中输入使用最常见的 shell 键盘快捷键来处理你的工作。当你在一行上输入你指定的终止字符串时,你的会话就结束了。你可以通过唯一的提示符(通常是 **&gt;**)知道你是在一个 heredoc 循环中。
```
$ cat &lt;&lt; EOF &gt;&gt; example.txt
&gt; Everything you type here will be placed into example.txt when I type EOF on a line by itself. Until then, you can type...
&gt;
&gt; whatever...
&gt;
&gt; you want to type.
&gt;
&gt; EOF
$  
```
在终端等待 **EOF**你输入的所有内容都会被放入目标文件中提示符被省略EOF 本身也不是文件的一部分。
```
Everything you type here will be placed into example.txt when I type EOF on a line by itself. Until then, you can type...
whatever...
you want to type.
```
现实中,你可能不会用 heredoc 语法来代替一个好的文本编辑器。它是一个很好的快速处理,可以输入多行,但超过 10 行左右就开始限制它的作用了。例如,如果不触发你 shell 的 [history][5] 功能,你就不能编辑以前的行。根据你的 shell 和配置,你可能可以先向上,然后向下来调用你的文本,然后用 **Ctrl+B** 来后退。 
你的 shell 的大部分功能都能正常工作,但可能没有撤销功能,也没有什么错误恢复功能。
此外,即使是最简安装,也可能至少安装了 [Vi][6] 或 [ed][7]。
然而 heredoc 还是很有用的!它比 **echo** 更灵活,当你在使用 shell 脚本时,它是不可缺少的。例如,想象一下你正在编写一个安装脚本,这样你就可以自动安装一组自定义应用。其中一个应用没有生成 `.dekstop`文件,所以它不会出现在你的应用菜单中。为了解决这个问题,你决定在安装时生成一个 `.desktop` 文件。
与其编写一个 `.desktop` 文件,然后作为安装脚本的外部依赖,不如在安装脚本中使用 heredoc
```
#!/bin/sh
VERSION=${VERSION:-x.y.z}
PKGNAM=${VERSION:-example}
PKG="${PKGNAM}"-"${VERSION}"-`arch`.tgz
# download package
wget "${PKG}"
tar txvf "${PKG}"
# use here doc to create missing .desktop file
cat &lt;&lt; EOF &gt;&gt; $HOME/.local/share/applications/example.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name="${PKGNAM}"
Comment="${PKGNAM}"
Exec="${PKGNAM}" %F
EOF
# insert the rest of an install script...
```
你可以自动将文本输入到一个文件中,不需要文本编辑器(当然,除了你用来写脚本的那个)。下面是生成的 `.desktop` 文件的样子:
```
[Desktop Entry]
Version=1.0
Type=Application
Name=example
Comment=example
Exec=example %F
```
正如你所看到的,你可以在 heredoc 中使用变量,而且它们得到了正确的解析。`EOF` 字符串并没有出现在文件中,它只是标志着 heredoc 的结束。
### 比 echo 更好
heredoc 技术通常被认为比 `echo` 或 [printf][8] 更容易,因为一旦你“进入”了文档,你就可以自由地做任何你想做的事情。从这个意义上说,它是自由的,但与合适的文本编辑器相比,它是有限的。
使用 heredoc 来做快速笔记和 shell 脚本,再也不用为如何动态生成配置文件而烦恼了。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/heredoc
作者:[Seth Kenlon][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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lenovo-thinkpad-laptop-window-focus.png?itok=g0xPm2kD (young woman working on a laptop)
[2]: https://opensource.com/article/19/2/getting-started-cat-command
[3]: https://opensource.com/article/20/4/bash-sysadmins-ebook
[4]: https://opensource.com/article/20/8/tcsh
[5]: https://opensource.com/article/20/6/bash-history-commands
[6]: https://opensource.com/article/19/3/getting-started-vim
[7]: https://opensource.com/article/20/12/gnu-ed
[8]: https://opensource.com/article/20/8/printf