Linux命令速查工具

我们在使用linux时经常会忘了某些命令的用法,虽然可以使用help和man等查看帮助,但这些帮助通常只会给出选项用法,不会给出具体例子,不够直观,特别是man的帮助信息特别长,而我们需要的可能仅仅是其中一部分用法。

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

Tldr

官方资料

Linux命令速查工具_第1张图片

  • 在线wiki搜索:tldr | simplified, community driven man pages (ostera.io)
  • 官方的安装介绍页面地址:https://tldr.sh/#installation
  • tldr项目地址:https://github.com/tldr-pages/tldr

安装

  • ubuntu
sudo apt-get install tldr

如果apt源没有tldr或安装后不生效,还可以使用npm安装

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

如果你有python环境,也可以使用pip安装

pip3 install tldr
  • macos
brew install tldr
  • centos
sudo yum install -y npm
sudo npm install -g tldr

随后将tldr加入环境变量,默认会安装到nodeJs安装路径的Bin目录下面

# in ~/.bashrc or other shell
export PATH="$PATH:"

# example: export PATH="$PATH:$HOME/nodejs/bin"

更新数据库

如果出现tldr找不到命令使用方法的提示,可能是由于tldr数据库还没有更新

sudo tldr --update

使用如上命令更新数据库

使用效果

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 */

Cheat

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

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

Linux命令速查工具_第2张图片

官方资料

  • 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

注意releases版本可能随系统不同而不同

  • GO

如果有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

在cheat安装后,第一次使用会提示用户更新数据库

[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.

使用效果

[zxd@localhost tmp]$ cheat ls
# To display everything in , excluding hidden files:
ls <dir>

# To display everything in , 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

你可能感兴趣的:(linux,运维,服务器,笔记)