Linuxコマンドのチートシートをコマンドラインからみよう!『Cheat』

LinuxのようなUNIXライクのOSを扱う際、大体はCUIでの操作になるだろう。つまり、UNIXのコマンドを使って操作したりすることになる。
今回はLinuxのコマンドライン上から、コマンドのチートシートを参照する『Cheat』というパッケージがあるようなので、それを試してみることにした。

1.インストール

まずは、以下のコマンドを実行し必要なパッケージをインストールする。

Debian/Ubuntu

sudo apt-get install git python-pip
sudo pip install docopt pygments
git clone https://github.com/chrisallenlane/cheat.git
cd cheat
sudo python setup.py install

RHEL系

sudo yum install git python-pip
sudo pip install docopt pygments
git clone https://github.com/chrisallenlane/cheat.git
cd cheat
sudo python setup.py install

最後に、以下のコマンドを実行する。

wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash
sudo cp cheat.bash /etc/bash_completion.d/

2.コマンドの実行

さて、それでは実際にチートシートを見てみよう。
まずは、シートが用意されているコマンドのリストを確認するため「cheat -l」コマンドを実行する。

test@test-vm-ubuntu:~$ 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-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
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
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
diff           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/diff
distcc         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/distcc
emacs          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/emacs
find           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/find
gcc            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/gcc
gdb            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/gdb
git            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/git
gpg            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/gpg
grep           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/grep
gs             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/gs
head           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/head
history        /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/history
ifconfig       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ifconfig
indent         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/indent
iptables       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/iptables
irssi          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/irssi
iwconfig       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/iwconfig
journalctl     /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/journalctl
less           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/less
ln             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ln
ls             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ls
lsof           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/lsof
markdown       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/markdown
mkdir          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/mkdir
mount          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/mount
mysql          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/mysql
mysqldump      /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/mysqldump
ncat           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ncat
netstat        /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/netstat
nmap           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/nmap
notify-send    /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/notify-send
od             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/od
openssl        /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/openssl
pacman         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/pacman
pdftk          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/pdftk
php            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/php
ps             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ps
python         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/python
rm             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/rm
rsync          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/rsync
sam2p          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/sam2p
scp            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/scp
screen         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/screen
sed            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/sed
shred          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/shred
sockstat       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/sockstat
sort           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/sort
split          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/split
sqlmap         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/sqlmap
ssh            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ssh
ssh-copy-id    /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ssh-copy-id
ssh-keygen     /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ssh-keygen
stdout         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/stdout
strace         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/strace
systemctl      /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/systemctl
tail           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/tail
tar            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/tar
tcpdump        /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/tcpdump
tee            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/tee
tmux           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/tmux
top            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/top
truncate       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/truncate
uname          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/uname
vim            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/vim
wget           /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/wget
xargs          /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/xargs
yaourt         /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/yaourt
youtube-dl     /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/youtube-dl
yum            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/yum

次に、実際にコマンドのチートシートを見てみよう。
「cheat <コマンド名>」でシートを参照出来る。

test@test-vm-ubuntu:~$ cheat sed
# To replace all occurrences of "day" with "night" and write to stdout:
sed 's/day/night/g' file.txt

# To replace all occurrences of "day" with "night" within file.txt:
sed -i 's/day/night/g' file.txt

# To replace all occurrences of "day" with "night" on stdin:
echo 'It is daytime' | sed 's/day/night/g'

# To remove leading spaces
sed -i -r 's/^\s+//g' file.txt

# Remove empty lines and print results to stdout:
sed '/^$/d' file.txt

その他、「-e」オプションで対象となるコマンドのチートシートを編集出来たりもする。