Linux命令速查工具

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

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

Tldr

官方资料

img

安装

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

img

官方资料

安装

  • 类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 managerPackage(s)
aurcheat, cheat-bin
brewcheat
dockerdocker-cheat
nixnixos.cheat
snapcheat

在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 <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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值