Linux和MAC命令參數用法查詢工具:cheat


一、什么是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/ #mac默認的配置補全配置文件放置的地方為:/usr/local/Cellar/cheat/2.1.22/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命令的實例

例子:

$ 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 {} \;

 

在mac上安裝cheat

brew install cheat

之后再按照前面的說明進行配置即可

 

幾個cheatsheet文檔推薦下載:

紅帽 Linux 命令備忘單

Linux 培訓學院備忘單

Linoxide 備忘單

Loggly 備忘單

Cheatography 備忘單

 

參考文檔:

Linux命令參數用法查詢工具:cheat

Cheat – An Ultimate Command Line ‘Cheat-Sheet’ for Linux Beginners and Administrators

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM