Linux aspell 命令初学者教程(5 个例子)
在此页
- Linux aspell 命令
- Q1。如何使用aspell 命令?
- Q2。如何用 aspell 检查文件的拼写错误?
- Q3。如何用aspell查个别单词?
- Q4。如何用aspell批量查单词?
- Q5。如何控制aspell使用的字典?
- 结论
如果您的工作涉及编写或编辑文本文件或文档,拼写检查器是一个重要的工具。虽然大多数基于 GUI 的编辑器都内置了拼写检查功能,但命令行编辑器却不是这样。但是,有单独的命令行工具可以帮助您进行拼写检查。
在这里,在本教程中,我们将讨论一个这样的实用程序,称为 aspell。但在我们深入研究之前,值得一提的是,本文中的所有示例都已在 Ubuntu 18.04 LTS 机器上进行了测试。
Linux aspell命令
如开头所述,aspell 命令可让您对文本文件执行拼写检查。您甚至可以检查单个单词。以下是它的语法:
aspell [options] <command>
以下是手册页中关于此工具的内容:
aspell is a utility program that connects to the Aspell library so that
it can function as an ispell -a replacement, as an independent spell
checker, as a test utility to test out Aspell library features, and as
a utility for managing dictionaries used by the library.
The Aspell library contains an interface allowing other programs direct
access to its functions and therefore reducing the complex task of
spell checking to simple library calls. The default library does not
contain dictionary word lists. To add language dictionaries, please
check your distro first for modified dictionaries, otherwise look here
for base language dictionaries <http://aspell.net>.
以下是一些 Q&A 风格的示例,可以让您更好地了解该实用程序的工作原理。
Q1。如何使用aspell 命令?
aspell 的基本用法并不完全直接,因此最好获取用法摘要,您可以使用 usage 命令选项获取该摘要。
aspell usage
以下是您可能会得到的输出:
Usage: aspell [options] <command>
<command> is one of:
-?|usage display a brief usage message
help display a detailed help message
-c|check <file> to check a file
-a|pipe "ispell -a" compatibility mode
[dump] config dumps the current configuration to stdout
config <key> prints the current value of an option
[dump] dicts | filters | modes
lists available dictionaries / filters / filter modes
[options] is any of the following:
--encoding=<str> encoding to expect data to be in
--mode=<str> filter mode
-l,--lang=<str> language code
-d,--master=<str> base name of the main dictionary to use
--sug-mode=<str> suggestion mode
Q2。如何用 aspell 检查文件的拼写错误?
这可以使用 -c 命令行选项来完成。例如:
aspell -c test.txt
以下是执行上述命令时工具显示的内容:

因此,您可以看到该工具突出显示了文本中的第一个拼写错误,并在窗口的下半部分提供了它认为我感兴趣的选项作为替代。此外,如果您仔细观察,还可以选择忽略当前突出显示的拼写错误、替换所有出现的当前突出显示的单词、添加到 aspells 词典以及退出此视图。
Q3.如何用aspell查个别单词?
您可以使用 -a 命令行选项执行此操作。
aspell -a
一旦运行此命令,它将等待用户输入。在此模式下键入一个词,按回车键,您将在标准输出上看到一个提供拼写建议的拼写。
以下屏幕截图显示了此命令行选项的运行情况:

Q4.如何用aspell批量查单词?
您可以使用 list 命令选项执行此操作。
aspell list
上面的命令在运行时将等待用户输入。添加任意数量的单词,完成后,按 Ctrl+D。然后您会看到 aspell 会在您提供的输入下方显示拼写错误的单词。
以下屏幕截图显示了此选项的运行情况:

Q5.如何控制aspell使用的字典?
aspell 的手册页提供了各种选项,您可以使用这些选项来控制此命令使用的词典。以下是一些重要的:
--master=<name>, -d <name>
Base name of the dictionary to use. If this option is specified
then Aspell will either use this dictionary or die.
--dict-dir=<directory>
Location of the main dictionary word list.
--lang=<string>, -l <string>
Language to use. It follows the same format of the LANG envi?
ronmental variable on most systems. It consists of the two let?
ter ISO 639 language code and an optional two letter ISO 3166
country code after a dash or underscore. The default value is
based on the value of the LC_MESSAGES locale.
--size=<string>
The preferred size of the dictionary word list. This consists
of a two char digit code describing the size of the list, with
typical values of: 10=tiny, 20=really small, 30=small, 40=med-
small, 50=med, 60=med-large, 70=large, 80=huge, 90=insane.
结论
您可能同意 aspell 是 Linux 命令行用户应该了解的有用工具。我们在这里讨论了该工具的基础知识。练习完这些选项后,请前往命令手册页了解更多信息。