关于linux:LinuxLinux命令快速学习神器tldrcheat介绍和使用

5次阅读

共计 10894 个字符,预计需要花费 28 分钟才能阅读完成。

引言

本文介绍 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 的常见问题和解决方案。
  2. Ubuntu 和 CenterOs 介绍和装置 cheat 命令。

    1. 装置验证和应用
    2. Ubuntu 和 CenterOs 解决形式统一
  3. 相似我的项目列举。

官网材料

在线 wiki 搜寻:tldr | simplified, community driven man pages (ostera.io)
(留神国内拜访比较慢,须要自带魔法)

官网的装置介绍页面地址:https://tldr.sh/#installation

tldr 我的项目地址:https://github.com/tldr-pages/tldr

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 的数据库没法拜访。

更新 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 版本降级

版本降级相干材料参考自:https://blog.csdn.net/Fabulous1111/article/details/84983869

(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 零碎版本或者内核版本低而不反对的问题。

正文完
 0