linux命令查找软件,(总结)Linux命令参数用法查询工具:cheat

PS:今天发现一个相当实用的工具,可以查询linux各种命令的详细参数用法,比man、help这种查询实用快速很多,在linux上,man命令几乎是万能的,但它并不很高效直接。总结分享一下:

一、什么是cheat?

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

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

Cheat主要有两个依赖python和pip

1、安装python、pip

# yum install python python-pip -y

# pip install --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.py install

安装完成,运行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/

其余解释器的自动补全脚本在这里:

https://github.com/chrisallenlane/cheat/tree/master/cheat/autocompletion

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命令的实例

find命令

# To find files by case-insensitive extension (ex: .jpg, .JPG, .jpG):

find . -iname "*.jpg"

# To find directories:

find . -type d

# To find files:

find . -type f

# To find files by octal permission:

find . -type f -perm 777

# To find files with setuid bit set:

find . -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l

# To find files with extension '.txt' and remove them:

find ./path/ -name '*.txt' -exec rm '{}' \;

# To find files with extension '.txt' and look for a string into them:

find ./path/ -name '*.txt' | xargs grep 'string'

# To find files with size bigger than 5 Mb and sort them by size:

find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z

# To find files bigger thank 2 MB and list them:

find . -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

# To find files modified more than 7 days ago and list file information

find . -type f -mtime +7d -ls

# To find symlinks owned by a user and list file information

find . -type l --user=username -ls

# To search for and delete empty directories

find . -type d -empty -exec rmdir {} \;

# To search for directories named build at a max depth of 2 directories

find . -maxdepth 2 -name build -type d

# To search all files who are not in .git directory

find . ! -iwholename '*.git*' -type f

# To find all files that have the same node (hard link) as MY_FILE_HERE

find . -type f -samefile MY_FILE_HERE 2>/dev/null

# To find all files in the current directory and modify their permissions

find . -type f -exec chmod 644 {} \;

sed命令

0d02d1dc9e81637fb95e7ed054f9a530.png

rpm命令

bf7e3d07f7d98521f4410af852fa7afa.png

五、结论

一句话,一个实用的工具!

参考:http://www.tecmint.com/cheat-command-line-cheat-sheet-for-linux-users/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值