前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux中更懂你帮助命令tldr

linux中更懂你帮助命令tldr

作者头像
入门笔记
发布2022-06-02 17:01:50
1.1K0
发布2022-06-02 17:01:50
举报
文章被收录于专栏:入门小站入门小站

什么是 tldr

该 tldr页面项目旨在提供一个简单的替代手册页,一个强调可读性和实际的例子。

与手册页一样,你可以使用 tldr 页面来查找命令及其可用选项的描述。但是,与手册页不同,tldr 页面不会尝试为每个命令提供完整的选项列表。相反,它侧重于每个命令最有用的选项,并为每个选项提供清晰实用的示例。

如何安装 tldr

本指南为你提供了两个最流行的 tldr 客户端的安装步骤,一个使用Node.js,另一个使用Python 3。查看以下部分中的每个 tldr 客户端,了解如何在 Linux 系统上安装它们。

1.使用 Node.js

  • 1.安装 节点包管理器 (NPM)。推荐的方法是首先安装节点版本管理器 (NVM)。

你可以使用下面显示的一系列命令先安装 NVM,然后使用它来安装当前版本的 Node.js。Node.js 安装包括当前的 NPM 版本。

在继续之前,请检查 NVM 版本页面,并将v0.38.0下面的命令替换为你在版本页面上找到的最新版本的版本号。

代码语言:javascript
复制
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0/install.sh | bash
source ~/.bashrc
nvm install node

然后,你可以使用以下命令验证你的 NPM 安装:

代码语言:javascript
复制
npm --version
7.21.0
    1. tldr通过 NPM安装。使用该-g选项安装tldr为全局 NPM 包。
代码语言:javascript
复制
npm install tldr -g

2.使用 Python 3

  • 1.确保已安装 Python 3。

DebianUbuntu 上,最近的版本默认包含 Python 3,你可以使用该--version标志进行验证。

代码语言:javascript
复制
python3 --version
Python 3.8.10

AlmaLinuxCentOS(8 或更高版本)和Fedora 上,使用以下命令安装 Python 3。

代码语言:javascript
复制
sudo dnf install python3
  • 2.通过 Pip 3 安装 tldr,这是 Python 3 的默认包安装程序。
代码语言:javascript
复制
sudo pip3 install tldr

如何使用 tldr

你可以通过发出tldr命令后跟你想了解更多信息的命令名称来开始使用 tldr 页面。例如,你可以获取该ls命令的 常见示例,如下所示:

代码语言:javascript
复制
tldr ls
ls
  List directory contents.
  More information: https://www.gnu.org/software/coreutils/ls.
  - List files one per line:
    ls -1
  - List all files, including hidden files:
    ls -a
  - List all files, with trailing `/` added to directory names:
    ls -F
  - Long format list (permissions, ownership, size, and modification date) of all files:
    ls -la
  - Long format list with size displayed using human-readable units (KiB, MiB, GiB):
    ls -lh
  - Long format list sorted by size (descending):
    ls -lS
  - Long format list of all files, sorted by modification date (oldest first):
    ls -ltr
  - Only list directories:
    ls -d */

相比之下,这里是该ls命令的大量手册页的摘录。

代码语言:javascript
复制
man ls

LS(1)                                                                            User Commands                                                                            LS(1)
NAME
       ls - list directory contents
SYNOPSIS
       ls [OPTION]... [FILE]...
DESCRIPTION
       List information about the FILEs (the current directory by default).  Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
       Mandatory arguments to long options are mandatory for short options too.
       -a, --all
              do not ignore entries starting with .
       -A, --almost-all
              do not list implied . and ..
       --author
              with -l, print the author of each file
       -b, --escape
              print C-style escapes for nongraphic characters
       --block-size=SIZE
              with -l, scale sizes by SIZE when printing them; e.g., '--block-size=M'; see SIZE format below
       -B, --ignore-backups
              do not list implied entries ending with ~
[...]

如你所见,tldr 页面侧重于为你提供与该命令最相关的一些选项的清晰描述和示例。另一方面,手册页侧重于选项的综合列表。出于这个原因,手册页的选项描述并不总是清晰的,并且无法帮助你找到最有用的选项。

下面是另一个示例,进一步说明了 tldr 页面和手册页之间的对比。

代码语言:javascript
复制
tldr vim

vim
  Vim (Vi IMproved), a command-line text editor, provides several modes for different kinds of text manipulation.
  Pressing `i` enters insert mode. `Esc` enters normal mode, which enables the use of Vim commands.
  More information: https://www.vim.org.
  - Open a file:
    vim path/to/file
  - Open a file at a specified line number:
    vim +line_number path/to/file
  - View Vim's help manual:
    :help<Enter>
  - Save and Quit:
    :wq<Enter>
  - Undo the last operation:
    u
  - Search for a pattern in the file (press `n`/`N` to go to next/previous match):
    /search_pattern<Enter>
  - Perform a regular expression substitution in the whole file:
    :%s/regular_expression/replacement/g<Enter>
  - Display the line numbers:
    :set nu<Enter>

同样,下面的输出显示了手册页的摘录以进行比较。

代码语言:javascript
复制
man vim

VIM(1)                                                                      General Commands Manual                                                                      VIM(1)
NAME
       vim - Vi IMproved, a programmer's text editor
SYNOPSIS
       vim [options] [file ..]
       vim [options] -
       vim [options] -t tag
       vim [options] -q [errorfile]
       ex gex
       view
       gvim gview vimx evim eview
       rvim rview rgvim rgview
DESCRIPTION
[...]

请注意,对于 tldr 页面,几乎没有对命令行参数的引用。这是因为 Vim 不经常使用它们。相反,tldr 页面侧重于你可能希望在 Vim 中使用的命令。当开始使用像 Vim 这样的工具时,这会更有帮助。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-12-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 入门小站 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 什么是 tldr
  • 如何安装 tldr
  • 1.使用 Node.js
  • 2.使用 Python 3
  • 如何使用 tldr
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档