【Linux】Linux命令快速学习神器tldr、cheat介绍和使用

简介: 【Linux】Linux命令快速学习神器tldr、cheat介绍和使用

引言

本文介绍tldr和Cheat等实用工具的安装和使用,这些工具虽然本身不能替代maninfo等命令,但是在很多时候想要快速学习和掌握命令但是忘记常见用法非常有帮助。

个人看法:对于非运维人员简直是神器。

tldr:全称 too long, Don’t read,翻译成中文就是太长不想阅读,比–help或者man这些传统手册更便捷、更便于使用。 cheat:作弊。

这两个命令有什么用?这里简单举个例子就知道了:

ubuntu@VM-8-8-ubuntu:~$ sudo 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 */

内容概览

  1. Ubuntu和CenterOs介绍和安装tldr命令。
  1. CenterOs和Ubuntu的安装方式使用
  2. Ubuntu的常见问题和解决方案。
  1. Ubuntu和CenterOs介绍和安装cheat命令。
  1. 安装验证和使用
  2. Ubuntu和CenterOs处理方式一致
  1. 类似项目列举。

官方资料

image.png

在线wiki搜索:tldr | simplified, community driven man pages (ostera.io) (注意国内访问比较慢,需要自带魔法)

官方的安装介绍页面地址:tldr.sh/#installati…

tldr项目地址:github.com/tldr-pages/…

tldr

Ubuntu安装tldr

安装

Ubuntu 安装比较简单,直接使用sudo apt-get install tldr安装。

sudo apt-get install tldr

如果上面的命令安装之后依然无法使用,可以按照下面的命令进行安装:

sudo apt-get install npm
sudo apt-get install nodejs-legacy
sudo npm install n -g

注意这里有两种方式,一种是使用latest版本,另外一种是使用stable版本,个人建议使用stable版本,如果Ubuntu的系统版本比较低,则需要降低node版本。

sudo n stable
(或 sudo n latest)
sudo npm install -g tldr

当然也可以不使用nodeJS,也可以使用pip

pip3 install tldr

如果是Mac系统就十分简单了:

brew install tldr

验证

在ubuntu当中验证直接使用:

ubuntu@VM-8-8-ubuntu:~$ tldr
tldr - Simplified and community-driven man pages
Usage: tldr [-v|--version] 
            ((-u|--update) | [-p|--platform PLATFORM] COMMAND | (-a|--about))
  tldr Client program
Available options:
  -h,--help                Show this help text
  -v,--version             Show version
  -u,--update              Update offline cache of tldr pages
  -p,--platform PLATFORM   Prioritize specfic platform while searching. Valid
                           values include linux, osx, windows, sunos
  COMMAND                  name of the command
  -a,--about               About this program

Ubuntu安装常见问题

No tldr entry for xxx

Ubuntu安装tldr使用tldr ls之后,很有可能出现类似No tldr entry for ls的命令,出现这种情况可能有下面两种情况:

  • 首次安装需要更新tldr的“数据库”。
  • 当天用户安装使用sudo,tldr的数据库没法访问。
ubuntu@VM-8-8-ubuntu:~$ tldr ls
No tldr entry for ls

更新tldr的数据库:

ubuntu@VM-8-8-ubuntu:~$ sudo tldr --update
✔ Updating...
✔ Creating index...

当然也可以使用tldr -u

ubuntu@VM-8-8-ubuntu:~$ sudo tldr --u

sudo安装使用

个人的云服务器ubuntu使用了sudo安装之后,需要使用sudo tldr才可以正常使用,因为日常登录的用户为ubuntu用户,安装的过程全部使用sudo,查询某个命令也需要使用root身份进行查询。

如果出现No tldr entry for xxx,有可能是你用的sudo安装但是当前的用户却没有sudo的权限。

ubuntu@VM-8-8-ubuntu:~$ sudo 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 */

nodeJs版本降级

版本降级相关资料参考自:blog.csdn.net/Fabulous111…

(1)安装node版本管理模块n

sudo npm install n -g

下边步骤请根据自己需要选择

(2)安装稳定版

sudo n stable

(3)安装最新版

sudo n latest

(4) 版本降级/升级

sudo n 版本号

(5)检测目前安装了哪些版本的node

n

提示内容如下:

ο node/16.15.1
    node/18.13.0
    node/19.5.0
Use up/down arrow keys to select a version, return key to install, d to delete, q to quit

切换版本(不会删除已经安装的其他版本)

n 版本号

比如:n 16.15.1

(7)删除版本

sudo n rm 版本号

(8)直接移除Nodejs

PS:注意不同的操作系统命令会有差别,这里为Ubuntu的卸载方式

sudo apt-get remove nodejs

简单使用

sudo npm install -g n
sudo n install 16.15.1 # 太新的也会有问题

以上就是ubuntu常见问题和处理。

CenterOs 安装 tldr

CenterOs的安装方式和Ubuntu类似,这里展示安装Node环境之后安装tldr并使用的过程。

安装

  1. 安装NodeJs,如果嫌麻烦可以直接安装sudo yum install -y npm

[[【Linux】NodeJs 安装和环境变量配置]]

  1. 我们使用官方提供的命令安装。
sudo npm install -g tldr
  1. 如果是使用NodeJs环境变量设置的方式安装,需要设置软链接,tldr命令默认会安装到nodeJs安装路径的Bin目录下面,如果不好理解,可以参考下面的软链接构建命令。

还有一种方式是在Path中设置/xx/nodejs/bin 为环境变量

[zxd@localhost ~]$ sudo ln -s /opt/nodeJs/bin/tldr /usr/local/bin
[sudo] password for zxd:

如果软链接路径构建错误,可以使用sudo ln -fs /opt/nodeJs/bin/tldr /usr/local/bin加入 -f参数强制覆盖之前的软链接。

验证

因为构建了tldr软链接,我们可以再任意路径使用这个命令。如果敲入tldr命令出现下面的提示证明安装成功:

[zxd@localhost bin]$ tldr
Usage: tldr command [options]
Simplified and community-driven man pages
Options:
  -v, --version            Display version
  -l, --list               List all commands for the chosen platform in the cache
  -a, --list-all           List all commands in the cache
  -1, --single-column      List single command per line (use with options -l or -a)
  -r, --random             Show a random command
  -e, --random-example     Show a random example
  -f, --render [file]      Render a specific markdown [file]
  -m, --markdown           Output in markdown format
  -o, --os [type]          Override the operating system [linux, osx, sunos, windows]
  --linux                  Override the operating system with Linux
  --osx                    Override the operating system with OSX
  --sunos                  Override the operating system with SunOS
  --windows                Override the operating system with Windows
  -t, --theme [theme]      Color theme (simple, base16, ocean)
  -s, --search [keywords]  Search pages using keywords
  -u, --update             Update the local cache
  -c, --clear-cache        Clear the local cache
  -h, --help               Show this help message
  Examples:
    $ tldr tar
    $ tldr du --os=linux
    $ tldr --search "create symbolic link to file"
    $ tldr --list
    $ tldr --list-all
    $ tldr --random
    $ tldr --random-example
  To control the cache:
    $ tldr --update
    $ tldr --clear-cache
  To render a local file (for testing):
    $ tldr --render /path/to/file.md

我们使用tldr ls查看ls命令的用法,确实赏心悦目。

[zxd@localhost ~]$ tldr ls
✔ Page not found. Updating cache...
⠴ Creating index...
✔ Creating index...
  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 */

Cheat

介绍

这个漫画是Cheat恶搞man命令查一个命令需要翻几本书的时间,挺有意思的。

cheat:有欺骗的意思,可以直接理解为舞弊或者作弊

官方资料

github项目地址: cheat/cheat: cheat allows you to create and view interactive cheatsheets on the command-line. It was designed to help remind *nix system administrators of options for commands that they use frequently, but not frequently enough to remember. (github.com)

官方安装教程:cheat/INSTALLING.md at master · cheat/cheat (github.com)

手动安装

类Unix

类Unix系统可以使用下面一串命令解决。

cd /tmp \
  && wget https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz \
  && gunzip cheat-linux-amd64.gz \
  && chmod +x cheat-linux-amd64 \
  && sudo mv cheat-linux-amd64 /usr/local/bin/cheat

个人的CenterOs实验如下:

[zxd@localhost ~]$ cd /tmp \
>   && wget https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz \
>   && gunzip cheat-linux-amd64.gz \
>   && chmod +x cheat-linux-amd64 \
>   && sudo mv cheat-linux-amd64 /usr/local/bin/cheat
--2023-01-28 18:34:35--  https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
Unable to establish SSL connection.
[zxd@localhost tmp]$ cd /tmp   && wget https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz   && gunzip cheat-linux-amd64.gz   && chmod +x cheat-linux-amd64   && sudo mv cheat-linux-amd64 /usr/local/bin/cheat
--2023-01-28 18:34:59--  https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz
Resolving github.com (github.com)... 
... 省略一些安装提示信息
... github访问比较慢,耐心等待
100%[=============================================================================>] 4,696,443   9.87KB/s   in 6m 11s 
2023-01-28 18:41:13 (12.4 KB/s) - ‘cheat-linux-amd64.gz’ saved [4696443/4696443]

个人的Ubuntu云服务器的实验如下:

ubuntu@VM-8-8-ubuntu:~$ cd /tmp \
  && wget https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz \
  && gunzip cheat-linux-amd64.gz \
  && chmod +x cheat-linux-amd64 \
  && sudo mv cheat-linux-amd64 /usr/local/bin/cheat
--2023-01-28 10:56:00--  https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz
... 省略信息
Saving to: ‘cheat-linux-amd64.gz’
cheat-linux-amd64.gz              100%[==========================================================>]   4.48M   871KB/s    in 1m 42s  
2023-01-28 10:57:43 (44.9 KB/s) - ‘cheat-linux-amd64.gz’ saved [4696443/4696443]
ubuntu@VM-8-8-ubuntu:/tmp$ cheat
A config file was not found. Would you like to create one now? [Y/n]: y
Would you like to download the community cheatsheets? [Y/n]: y
Cloning community cheatsheets to /home/ubuntu/.config/cheat/cheatsheets/community.
Enumerating objects: 335, done.
Counting objects: 100% (335/335), done.
Compressing objects: 100% (314/314), done.
Total 335 (delta 36), reused 274 (delta 19), pack-reused 0
Cloning personal cheatsheets to /home/ubuntu/.config/cheat/cheatsheets/personal.
Created config file: /home/ubuntu/.config/cheat/conf.yml
Please read this file for advanced configuration information.

注意:这里可能需要更改版本号(“4.4.0”)和存档(“cheat-linux-amd64.gz”),具体取决于安装平台。

可以阅读 releases page 了解当前命令支持的平台。

通过 go install安装

如果有GO 1.17 以上的版本,可以通过go install安装cheat。

go install github.com/cheat/cheat/cmd/cheat@latest

其他安装方式

下面是官方介绍的其他安装方式。

Package manager Package(s)
aur cheat, cheat-bin
brew cheat
docker docker-cheat
nix nixos.cheat
snap cheat

基础使用

和tldr类似,第一次使用cheat也需要构建“数据库”,但是cheat比tldr的使用体验更好,我们只需要按照提示输入两次y确认即可:

[zxd@localhost tmp]$ cheat 
A config file was not found. Would you like to create one now? [Y/n]: y
Would you like to download the community cheatsheets? [Y/n]: y
Cloning community cheatsheets to /home/zxd/.config/cheat/cheatsheets/community.
Enumerating objects: 335, done.
Counting objects: 100% (335/335), done.
Compressing objects: 100% (314/314), done.
Total 335 (delta 36), reused 274 (delta 19), pack-reused 0
Cloning personal cheatsheets to /home/zxd/.config/cheat/cheatsheets/personal.
Created config file: /home/zxd/.config/cheat/conf.yml
Please read this file for advanced configuration information.

最后是直接使用,个人感觉要比tldr麻烦事情少很多:

和 tldr的区别是排版的方式有点不同

[zxd@localhost tmp]$ cheat ls
# To display everything in <dir>, excluding hidden files:
ls <dir>
# To display everything in <dir>, including hidden files:
ls -a <dir>
# To display all files, along with the size (with unit suffixes) and timestamp:
ls -lh <dir>
# To display files, sorted by size:
ls -S <dir>
# To display directories only:
ls -d */ <dir>
# To display directories only, include hidden:
ls -d .*/ */ <dir>
# To display all files sorted by changed date, most recent first:
ls -ltc 
# To display files sorted by create time:
ls -lt
# To display files in a single column:
ls -1
# To show ACLs (MacOS):
# see also `cheat chmod` for `/bin/chmod` options for ACLs
/bin/ls -le
# To show all the subtree files (Recursive Mode):
ls -R

Uuntu的使用类似:

# 基础使用
ubuntu@VM-8-8-ubuntu:/tmp$ cheat cp
# To copy a file:
cp ~/Desktop/foo.txt ~/Downloads/foo.txt
# To copy a directory:
cp -r ~/Desktop/cruise_pics/ ~/Pictures/
# To create a copy but ask to overwrite if the destination file already exists:
cp -i ~/Desktop/foo.txt ~/Documents/foo.txt
# To create a backup file with date:
cp foo.txt{,."$(date +%Y%m%d-%H%M%S)"}
# To copy a symlink that points to a directory (and is thus soft) and not
# 'expand' the symlink (aka, preserve its nature as a symlink):
# Note this does NOT work (note trailing '/'):  cp -P /path/to/symlink-dir/
cp -P <symlink-dir> <dest-dir>
# To copy sparsely:
cp --sparse=always <src> <dest>

类似项目

还有更多和cheat以及tldr类似的项目,这里就不过多介绍了。

Cheat 允许您在命令行上创建和查看交互式备忘单。它旨在帮助提醒 Linux 系统管理员他们经常使用但不够频繁而无法记住的命令的选项。

cheat.sh 将来自多个来源(包括 tldr-pages)的备忘单聚合到 1 个统一界面中。

devhints Rico 的备忘单不仅仅关注命令行,还包括大量与编程相关的其他备忘单。

eg 在命令行上提供了详细的示例和解释。示例来自存储库,但例如支持显示自定义示例和命令以及默认值。

kb 是一个极简的命令行知识库管理器。 kb 可用于以极简主义和干净的方式组织您的笔记和备忘单。它还支持非文本文档。

navi 是一个交互式备忘单工具,它允许您即时浏览特定示例或完整命令。

bropages(已弃用)是对手册页的高度可读性补充。它显示了 Unix 命令的简明、常见示例。这些示例由用户群提交,可以投票赞成或反对;最好的条目是人们在查找命令时最先看到的内容。

写在最后

整体体验下来个人比较偏向cheat一点,类Unix系统安装官方的教程一个名称就可以完成,而tldr需要Node环境,同时因为Node更新速度就像喝汤容易导致Linux系统版本或者内核版本低而不支持的问题。

相关文章
|
2天前
|
安全 Linux 测试技术
|
2天前
|
安全 Linux Windows
Linux中Shutdown命令使用介绍
Linux中Shutdown命令使用介绍
|
2天前
|
自然语言处理 Java Linux
【Linux】开始学习进程替换吧!
通过学习进程替换,我们可以体会到多语言混搭的快乐,可以从C语言直接蹦到python ,也可以从c++里运行java代码。是不是很厉害!这是通过调度多个进程的效果,联系我们之前学习的进程,进程控制等概念。我们可以想要运行其他代码可以通过创建子进程来实现,但是这样也肯定是同一种语言,如果想要运行其他语言,那是不是有种方法可以调度一个进程来当做子进程呢??? 我们开始今天的学习吧!
9 0
|
3天前
|
缓存 关系型数据库 Linux
Linux目录结构:深入理解与命令创建指南
Linux目录结构:深入理解与命令创建指南
|
3天前
|
数据挖掘 Linux vr&ar
Linux命令实战:解决日常问题的利器
Linux命令实战:解决日常问题的利器
|
3天前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
17 0
|
9月前
|
安全 关系型数据库 MySQL
Linux学习笔记——Linux基本命令篇(三)
Linux学习笔记——Linux基本命令篇(三)
|
9月前
|
Linux 数据库 数据安全/隐私保护
Linux学习笔记——Linux基本命令篇(二)
Linux学习笔记——Linux基本命令篇(二)
|
9月前
|
Oracle 网络协议 Unix
Linux学习笔记——Linux基本命令篇(一)
Linux学习笔记——Linux基本命令篇(一)
|
缓存 网络协议 Linux
Linux 学习笔记之超详细基础linux命令(the end)
Linux 学习笔记之超详细基础linux命令(the end)
105 0