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

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

【Linux】Linux命令快速学习神器tldr、cheat介绍和使用(一)https://developer.aliyun.com/article/1395256


验证

因为构建了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:有欺骗的意思,可以直接理解为舞弊或者作弊。

image.png

官方资料

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系统版本或者内核版本低而不支持的问题。

相关文章
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
1175 1
二、Linux文本处理与文件操作核心命令
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
888 137
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
1875 58
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
1809 2
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
1201 0
Linux内存问题排查命令详解
Linux部署04-ls命令的参数和选项,主体,参数,选项,ls / 查看根目录下的文件夹,-a的意思是列出全部选项 ls -a home全部文件,.代表着隐藏的文件夹,-l 选项,以列表竖向的形式展
Linux部署04-ls命令的参数和选项,主体,参数,选项,ls / 查看根目录下的文件夹,-a的意思是列出全部选项 ls -a home全部文件,.代表着隐藏的文件夹,-l 选项,以列表竖向的形式展
Linux部署 cd-pwd命令,cd 不写参数 就直接回到用户的HOME目录,pwd 查看当前的工作目录,pwd是常看当前目录的路径,无参数
Linux部署 cd-pwd命令,cd 不写参数 就直接回到用户的HOME目录,pwd 查看当前的工作目录,pwd是常看当前目录的路径,无参数
Linux02---命令基础 Linux命令基础, ls命令入门,ls命令参数和选项,命令行是一种以纯字符操作系统的方式,command命令本身,options命令的细节行为,parameter命令的
Linux02---命令基础 Linux命令基础, ls命令入门,ls命令参数和选项,命令行是一种以纯字符操作系统的方式,command命令本身,options命令的细节行为,parameter命令的
|
安全 网络协议 Linux
【专栏】Linux系统中ping命令的使用,包括其基本语法、输出信息、常用参数及高级用法
【4月更文挑战第28天】本文详细介绍了Linux系统中ping命令的使用,包括其基本语法、输出信息、常用参数及高级用法。通过ping,用户可测试网络连通性、诊断故障及评估性能。此外,文章还讨论了ping在不同协议、模拟网络环境及与其他命令结合使用时的场景。注意防火墙和网络环境可能影响ping结果,理解错误信息有助于网络问题排查。熟练掌握ping命令,能助你成为Linux网络专家。不断学习和实践,提升网络技能,为构建稳定网络环境贡献力量。
1584 0
|
Shell Linux Perl
65Linux - RPM 命令参数使用详解
65Linux - RPM 命令参数使用详解
452 1