如何在 Ubuntu 上安裝和使用命令列備忘單
Cheat 是一款主要基於 Python 的命令列軟體,允許系統管理員檢視和儲存有用的備忘單。它檢索給定命令的純文字示例,這將提醒使用者選項、引數或常見用法。Cheat 用於“您經常使用的命令,但頻率不足以記住的命令”。
安裝 Cheat
在安裝 Cheat 之前,我們需要確保系統上的所有內容都已更新,如下面的命令所示:
$ sudo apt-get update && sudo apt-get upgrade
最好使用 Python 包管理器 Pip 安裝 Cheat。要安裝 pip,請使用以下命令:
$ sudo apt-get install python-pip
要安裝 cheat,請使用以下命令:
$ sudo pip install cheat
示例輸出應如下所示:
Collecting cheat Downloading cheat-2.1.24.tar.gz (42kB) 100% |████████████████████████████████| 51kB 89kB/s Collecting docopt>=0.6.1 (from cheat) Downloading docopt-0.6.2.tar.gz Collecting pygments>=1.6.0 (from cheat) Downloading Pygments-2.1.3-py2.py3-none-any.whl (755kB) 100% |████████████████████████████████| 757kB 892kB/s Installing collected packages: docopt, pygments, cheat Running setup.py install for docopt ... done Running setup.py install for cheat ... done Successfully installed cheat-2.1.24 docopt-0.6.2 pygments-2.1.3
要驗證 cheat 是否已安裝,請使用以下命令:
$ cheat -v
示例輸出應如下所示:
cheat 2.1.24
設定文字編輯器
我們可以繼續建立自己的備忘單,Cheat 需要知道我們希望預設使用哪個文字編輯器來編輯備忘單。要設定 nano 文字編輯器,請使用以下命令:
$ export EDITOR=/usr/bin/vim
我們可以使用以下命令確認上述命令是否成功:
$ printenv EDITOR
輸出應如下所示:
/usr/bin/vim
為了使此更改在所有未來的 shell 會話中持續有效,您必須將環境變數宣告新增到您的 .bashrc 檔案中。這是在 bash shell 會話開始時執行的幾個檔案之一。要開啟 bashrc 檔案,請使用以下命令:
$ nano ~/.bashrc
示例輸出應如下所示:
# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac export EDITOR=/usr/bin/vim # don't put duplicate lines or lines starting with space in the history. # See bash(1) for more options HISTCONTROL=ignoreboth # append to the history file, don't overwrite it shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) HISTSIZE=1000
然後新增與下面相同的匯出命令
..................................................... # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac export EDITOR=/usr/bin/vim # don't put duplicate lines or lines starting with space in the history. # See bash(1) for more options HISTCONTROL=ignoreboth ...........................................
儲存並退出檔案。
執行 Cheat
要以最基本的形式為 tail 命令執行 Cheat,請使用以下命令:
$ cheat tail
示例輸出應如下所示:
# To show the last 10 lines of file tail file # To show the last N lines of file tail -n N file # To show the last lines of file starting with the Nth tail -n +N file # To show the last N bytes of file tail -c N file # To show the last 10 lines of file and to wait for file to grow tail -f file
要檢視所有現有備忘單的列表,請使用以下命令:
$ cheat -l
輸出應如下所示:
7z /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/7z ab /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ab apk /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apk apparmor /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apparmor apt /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apt apt-cache /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apt-cache apt-get /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apt-get aptitude /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/aptitude asciiart /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/asciiart asterisk /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/asterisk at /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/at awk /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/awk bash /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/bash bower /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/bower chmod /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/chmod chown /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/chown convert /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/convert crontab /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/crontab csplit /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/csplit cups /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/cups curl /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/curl cut /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/cut date /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/date dd /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/dd df /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/df dhclient /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/dhclient ..............................................................................................
建立和編輯備忘單
要建立備忘單,請使用以下命令:
$ cheat -e tutorialspoint
上述命令 tutorialspoint 是一個備忘單名稱。它將開啟一個空白備忘單。現在新增您的備忘內容並儲存。
搜尋備忘單
要搜尋備忘單,請使用以下命令:
$ cheat -s tail
上述命令正在搜尋 tail 命令。示例輸出應如下所示:
asterisk:
# To print out the details of SIP accounts:
dnf:
# To search package details for the given string
dpkg:
# List all installed packages with versions and details
hardware-info:
# Display all hardware details
journalctl:
# Actively follow log (like tail -f)
mdadm:
# See detailed array confiration/status
mdadm --detail /dev/md${M}
mdadm --detail --scan > /etc/mdadm/mdadm.conf
p4:
# Print details related to Client and server configuration
pacman:
pacman -Ql | sed -n -e 's/.*\/bin\///p' | tail -n +2
pip:
# Show details of a package
tail:
tail file
tail -n N file
tail -n +N file
tail -c N file
tail -f file就是這樣。透過本文,您將能夠理解 - 如何在 Ubuntu 上安裝和使用命令列備忘單,我們將推出更多基於 Linux 的技巧和提示。繼續關注!
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP