cheat命令 == Linux命令小抄大全

1、安装cheat

首先,需要安装python、python-pip(这是cheat命令所依赖的)注:Linux默认已经安装Python

  1. [[email protected] ~]# yum -y install python
  2. [[email protected] ~]# yum -y install wget
  3. [[email protected] ~]# wget https://bootstrap.pypa.io/get-pip.py
  4. [[email protected] ~]# python get-pip.py

2、使用git工具安装cheat

安装git

  1. [[email protected] ~]# yum -y install git

安装Python依赖文件:

  1. [[email protected] ~]# pip install docopt pygments

从git克隆项目

  1. [[email protected] ~]# git clone https://github.com/chrisallenlane/cheat

切换到cheat目录进行安装

  1. [[email protected] ~]# cd cheat/
  2. [[email protected] cheat]# python setup.py install

测试安装是否成功

  1. [[email protected] cheat]# cheat -v
  2. cheat 2.1.26

3、配置cheat

(1)、设置自定义备忘单

cheat还有一个好处就是你可以定义自己常用的备忘单,默认的只是一些最基础的例子。自定义的备忘录放到~/.cheat/目录下,当设置好编辑环境可以使用下面的命令进行编辑

  1. # cheat -e foo

注:这里默认使用的是Nano编辑器,提示中的^X代表Ctrl + X组合键可推出编辑器,其他以此类推。

如果新建的foo已经存在,会直接打开编写,不存在会创建然后编辑

(2)、设置cheat环境变量

  1. [[email protected] ~]# cheat -d        
  2. /root/.cheat
  3. /usr/lib/python2.6/site-packages/cheat/cheatsheets #cheat默认的常用命令保存路径

修改

  1. [[email protected] ~]# mkdir /opt/cheats
  2. [[email protected] ~]# vim ~/.bashrc                   #设置参数(见参数)
  3. [[email protected] ~]# source ~/.bashrc                #使设置生效
  4. [[email protected] ~]# cheat -d
  5. /opt/cheat                                                    #默认cheat保存路径已经改变
  6. /usr/lib/python2.6/site-packages/cheat/cheatsheets

其中:在~/.bashrc末尾添加的具体参数如下:

  1. export DEFAULT_CHEAT_DIR=‘/opt/cheat‘    #设置cheat默认保存路径
  2. export EDITOR=/usr/bin/vim         #设置默认编辑器(可根据自己喜好添加,如nano等)
  3. export CHEATCOLORS=true            #语法高亮

(3)、开启自动补全功能

下载自动补全脚本到/etc/bash_completion.d目录:

  1. [[email protected] ~]# wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash
  2. [[email protected] ~]# mv cheat.bash /etc/bash_completion.d/

其他脚本地址:

三个文件的具体内容如下:

  1. [[email protected] ~]# cat /etc/bash_completion.d/cheat.bash
  2. function _cheat_autocomplete {
  3. sheets=$(cheat -l | cut -d‘ ‘ -f1)
  4. COMPREPLY=()
  5. if [ $COMP_CWORD = 1 ]; then
  6. COMPREPLY=(`compgen -W "$sheets" -- $2`)
  7. fi
  8. }
  9. complete -F _cheat_autocomplete cheat
  10. [[email protected] ~]# cat /etc/bash_completion.d/cheat.fish
  11. #completion for cheat
  12. complete -c cheat -s h -l help -f -x --description "Display help and exit"
  13. complete -c cheat -l edit -f -x --description "Edit <cheatsheet>"
  14. complete -c cheat -s e -f -x --description "Edit <cheatsheet>"
  15. complete -c cheat -s l -l list -f -x --description "List all available cheatsheets"
  16. complete -c cheat -s d -l cheat-directories -f -x --description "List all current cheat dirs"
  17. complete -c cheat --authoritative -f
  18. for cheatsheet in (cheat -l | cut -d‘ ‘ -f1)
  19. complete -c cheat -a "$cheatsheet"
  20. complete -c cheat -o e -a "$cheatsheet"
  21. complete -c cheat -o ‘-edit‘ -a "$cheatsheet"
  22. end
  23. [[email protected] ~]# cat /etc/bash_completion.d/cheat.zsh
  24. #compdef cheat
  25. #
  26. #declare -a cheats
  27. #cheats=$(cheat -l | cut -d‘ ‘ -f1)
  28. #_arguments "1:cheats:(${cheats})" && return 0
  29. [[email protected] ~]#

注:本文参考网址:

1、一个cheat命令 == Linux命令小抄大全  http://mp.weixin.qq.com/s?__biz=MzA3OTgyMDcwNg==&mid=2650625792&idx=1&sn=02cfdf9dcf3206a6bb91282234ef89c9&scene=2&srcid=0805bWEEe3lULY8qUBtLzbqU&from=timeline&isappinstalled=0#wechat_redirect

2、Linux下更好用的帮助命令—cheat  http://www.mamicode.com/info-detail-1470185.html

3、Cheat—— 给Linux初学者和管理员一个终极命令行"备忘单"-技术 ◆ 学习|Linux.中国-开源社区  https://linux.cn/article-3760-1.html

来自为知笔记(Wiz)

时间: 2024-08-25 11:00:30

cheat命令 == Linux命令小抄大全的相关文章

一个cheat命令 == Linux命令小抄大全

本文介绍一个Linux超级命令,有了这个命令,你就可以开开心心的使用linux上的各种命令了. 当你要执行一个linux命令,在这个命令参数选项众多时,你一般怎么做?对,我们大多数人都会去求助man命令.此外,linux上帮助相关的命令还有"help""whereis""whatis"等命令. 当然,在linux上,man命令几乎是万能的,但它却不是最高效的.尤其是对英文不太好的童鞋,man命令给出的帮助信息很长,在短时间内不好理解.如下图所示,

gpasswd命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 本文出自 "airfish2000" 博客,更多命令查看博客: http://airfish2000.blog.51cto.com/10829608/1892594 gpasswd命令 使用gpasswd命令可以设置一个组群的组群密码,或者是在组群中添加.删除用户. 命令语法: gpasswd [选

quotaoff命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 本文出自 "airfish2000" 博客,更多命令查看博客: http://airfish2000.blog.51cto.com/10829608/1892599 quotaoff命令 使用quotaoff命令可以关闭指定文件系统的磁盘配额空间限制. 命令语法: quotaoff [选项] [文件

dhcpd命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 本文出自 "airfish2000" 博客,更多命令查看博客: http://airfish2000.blog.51cto.com/10829608/1894367 dhcpd命令 使用dhcpd命令可以运行DHCP服务器. 命令语法: dhcpd [选项] [网络接口] 命令中各选项的含义如表所示

vmstat命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 本文出自 "airfish2000" 博客,更多命令查看博客: http://airfish2000.blog.51cto.com/10829608/1894368 vmstat命令 使用vmstat命令可以对操作系统的虚拟内存.进程.分页.块I/O和CPU活动等进行监控.它是对系统的整体情况进行统

setfacl命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 本文出自 "airfish2000" 博客,更多命令查看博客: http://airfish2000.blog.51cto.com/10829608/1894364 setfacl命令 使用setfacl命令可以设置文件或目录的ACL. 命令语法: setfacl [选项] [目录|文件] 命令中各

usermod命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 本文出自 "airfish2000" 博客,更多命令查看博客: http://airfish2000.blog.51cto.com/10829608/1887965 usermod命令 使用usermod命令可以修改用户账户属性,比如更改用户的Shell类型.所属的组群.用户密码的有效期.用户的登录

killall命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 本文出自 "airfish2000" 博客,更多命令查看博客: http://airfish2000.blog.51cto.com/10829608/1887968 killall命令 使用killall命令可以用于杀死指定进程名称的进程. 命令语法: killall[选项] [进程名] 命令中各选

rmdir命令--Linux命令应用大词典729个命令解读

内容来源于人民邮电出版社<Linux命令应用大词典> 讲述729个命令,1935个例子 学习Linux系统的参考书.案头书,遇到不懂的命令或命令选项一查即可 争取每天都发布内容 rmdir命令 使用rmdir命令可以在Linux系统中删除空目录. 命令语法: rmdir [选项] [目录] 命令中各选项的含义如表所示. 表                                  rmdir命令选项含义 选项 含义 -p 递归删除目录,当子目录删除后其父目录为空时,也一同被删除 -v