linux查询命令参数用法,Linux和MAC命令参数用法查询工具:cheat(示例代码)

一、什么是cheat?

cheat是在GNU通用公共许可证下,为Linux命令行用户发行的交互式备忘单应用程序。简单来说,它没有提供其他额外多余的信息,只通过使用实例告诉你一个命令参数如何使用。

二、在Redhat、CentOS系统中安装Cheat:

Cheat主要有两个依赖python和pip

1、安装python、pip

# yum install python python-pip -y

# pipinstall --upgrade pip(更新pip到最新版本)

注:pip是一个方便的Python第三方包安装器。

2、下载并安装Cheat

目前只能通过Git下载Cheat,所以先安装git包:

# yum install git -y

使用pip安装所需要的python依赖包:

# pip install docopt pygments

接下来复制cheat的Git库:

# git clone https://github.com/chrisallenlane/cheat.git

进入cheat目录,运行setup.py脚本安装:

# cd cheat

# python setup.pyinstall

安装完成,运行cheat -v就可以看到目前的版本号。

三、cheat的一些配置设置:

1、你必须在~/.bashrc文件里设置EDITOR环境变量,打开用户.bashrc文件,加入下面这行保存退出:

export EDITOR=/usr/bin/vim

注:你也可以使用你喜欢的编辑器来替代vim。

2、添加cheat的自动补全特性,来确保不同解释器下命令行的自动补全。方法:将cheat.bash脚本clone下来,复制到你系统正确的路径下。

# wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash

# cp cheat.bash /etc/bash_completion.d/ #mac默认的配置补全配置文件放置的地方为:/usr/local/Cellar/cheat/2.1.22/etc/bash_completion.d

3、让语法高亮显示(可选):

在.bashrc文件中添加如下环境变量

export CHEATCOLOR=true

4、添加更多的命令参数:

Cheat默认只提供最基本和最常用的命令。cheat备忘单的内容保存在~/.cheat/目录里,我们可以手动在这个目录添加备忘单里面的内容,这样cheat将更强大。

# cheat -e xyz

这将打开xyz备忘单,如果对应的cheat-sheet可用的话。否则cheat会创建一个cheat-sheet。

使用关键字搜索备忘单,来看看包含所有命令的内置备忘单。

# cheat -d/root/.cheat/usr/lib/python2.7/site-packages/cheat/cheatsheets

复制内置的备忘单到你的本地目录。

# cp /usr/lib/python2.7/site-packages/cheat/cheatsheets/*/root/.cheat/

四、一些Cheat命令的实例

例子:

$ cheat find

# To find files by case-insensitive extension (ex: .jpg, .JPG, .jpG):find . -iname "*.jpg"# Tofinddirectories:find . -type d

# Tofindfiles:find . -type f

# Tofindfiles by octal permission:find . -type f -perm 777# Tofindfiles with setuid bit set:find . -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l

# Tofind files with extension ‘.txt‘and remove them:find ./path/ -name ‘*.txt‘ -exec rm ‘{}‘\;

# Tofind files with extension ‘.txt‘ and look for a stringinto them:find ./path/ -name ‘*.txt‘ | xargs grep ‘string‘# Tofind files with size bigger than 5 Mb and sortthem by size:find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z

# Tofind files bigger thank 2MB and list them:find . -type f -size +20000k -exec ls -lh {} \; | awk ‘{ print $9 ": " $5 }‘# Tofind files modified more than 7 days ago and list fileinformationfind . -type f -mtime +7d -ls# Tofind symlinks owned by a user and list fileinformationfind . -type l --user=username -ls# To searchforand delete empty directoriesfind . -type d -empty -exec rmdir{} \;

# To searchfor directories named build at a max depth of 2directoriesfind . -maxdepth 2 -name build -type d

# To search all fileswho are not in.git directoryfind . ! -iwholename ‘*.git*‘ -type f

# Tofindall files that have the same node (hard link) as MY_FILE_HEREfind . -type f -samefile MY_FILE_HERE 2>/dev/null# Tofind all files inthe current directory and modify their permissionsfind . -type f -exec chmod 644 {} \;

在mac上安装cheat

brew install cheat

之后再按照前面的说明进行配置即可

几个cheatsheet文档推荐下载:

参考文档:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值