ysf
ysf
Published on 2024-10-18 / 37 Visits
0

Ubuntu 安装 tldr

tldr 简介

Github: tldr-pages

Project website

tldr (Too Long; Didn't Read) 是一个开源的命令行工具,提供了简化版的命令使用说明,旨在帮助用户快速掌握命令的常用用法。与 man 相比,tldr 更加简洁,通常展示一些实用的示例,使得用户能够迅速了解命令的基本用途和用法。

tldr 的使用方式非常简单,只需要在 shell 中输入 tldr 后跟要查询的命令名称即可。例如,要查询 ls 命令的简化说明,可以输入 tldr ls ,将显示 ls 命令的常用用法:

(base) root@legion:/home# tldr ls
ls
List directory contents.More information: https://www.gnu.org/software/coreutils/ls.

 - List files one per line:
   ls -1

 - List [a]ll files, including hidden files:
   ls -a

 - List files with a trailing symbol to indicate file type (directory/, symbolic_link@, executable*, ...):
   ls -F

 - List [a]ll files in [l]ong format (permissions, ownership, size, and modification date):
   ls -la

 - List files in [l]ong format with size displayed using [h]uman-readable units (KiB, MiB, GiB):
   ls -lh

 - List files in [l]ong format, sorted by [S]ize (descending) [R]ecursively:
   ls -lSR

 - List files in [l]ong format, sorted by [t]ime the file was modified and in [r]everse order (oldest first):
   ls -ltr

 - Only list [d]irectories:
   ls -d */

安装

TLDR, man pages summarized by examples in Ubuntu

tldr 可以通过 npm、pip 等包管理工具安装,这个在上面的链接中和 tldr-pages 中都有介绍。此外,通过 apt 也可以安装 tldr:

sudo apt update
sudo apt install tldr

如果是 root 用户,可以省略 sudo

我在安装完成后直接执行 tldr 时遇到了 "No tldr entry for xxx" 的错误提示,经查阅发现这是因为首次安装 tldr 需要执行 tldr --update 命令更新 tldr 的本地(数据库)缓存:

(base) root@legion:/home# sudo tldr --update

Cloning into 'tldr'...

remote: Enumerating objects: 115322, done.

remote: Counting objects: 100% (6327/6327), done.

remote: Compressing objects: 100% (623/623), done.

remote: Total 115322 (delta 5999), reused 5736 (delta 5704), pack-reused 108995 (from 1)

Receiving objects: 100% (115322/115322), 27.58 MiB | 664.00 KiB/s, done.

Resolving deltas: 100% (68504/68504), done.

如果执行 tldr --update 提示以下错误:

(base) root@legion:/home# tldr --update
tldr: /root/.local/share/tldr: createDirectory: does not exist (No such file or directory)

则先执行 mkdir -p /root/.local/share/tldr 创建该目录,然后再执行 tldr --update 命令即可。

最后再测试 tldr 的功能是否可用。

使用 tldr

 - Print the tldr page for a specific command (hint: this is how you got here!):
   tldr {{command}}

 - Print the tldr page for a specific subcommand:
   tldr {{command}} {{subcommand}}

 - Print the tldr page for a command in the given [L]anguage (if available, otherwise fall back to English):
   tldr --language {{language_code}} {{command}}

 - Print the tldr page for a command from a specific [p]latform:
   tldr --platform {{android|common|freebsd|linux|osx|netbsd|openbsd|sunos|windows}} {{command}}

 - [u]pdate the local cache of tldr pages:
   tldr --update

 - [l]ist all pages for the current platform and common:
   tldr --list

 - [l]ist all available subcommand pages for a command:
   tldr --list | grep {{command}} | column

更新或清除本地缓存

更新本地缓存:tldr --updatetldr -u

清除本地缓存:tldr -c

查看指定命令的使用说明

tldr [command-name]

(base) root@legion:/home# tldr systemctl
systemctl
Control the systemd system and service manager.More information: https://www.freedesktop.org/software/systemd/man/systemctl.html.

 - Show all running services:
   systemctl status

 - List failed units:
   systemctl --failed

 - Start/Stop/Restart/Reload/Show the status a service:
   systemctl {{start|stop|restart|reload|status}} {{unit}}

 - Enable/Disable a unit to be started on bootup:
   systemctl {{enable|disable}} {{unit}}

 - Reload systemd, scan for new or changed units:
   systemctl daemon-reload

 - Check if a unit is active/enabled/failed:
   systemctl {{is-active|is-enabled|is-failed}} {{unit}}

 - List all service/socket/automount units filtering by running/failed state:
   systemctl list-units --type={{service|socket|automount}} --state={{failed|running}}

 - Show the contents & absolute path of a unit file:
   systemctl cat {{unit}}