Cheat : 一个实用 Linux 命令示例集合
我们中的许多人经常查看 man 页面 来了解命令开关(选项),它会显示有关命令语法、说明、细节和可用的选项,但它没有任何实际的例子。因此,在组合成一个我们需要的完整命令时会遇到一些麻烦。
你确实遇到这个麻烦而想要一个更好的解决方案吗?我会建议你试一下 cheat
。
Cheat 是什么
cheat 允许你在命令行中创建和查看交互式的速查表cheatsheet。它旨在帮助提醒 *nix 系统管理员他们经常使用但还没频繁到会记住的命令的选项。
如何安装 Cheat
cheat
是使用 python 开发的,所以可以用 pip
来在你的系统上安装 cheat
。
pip
是一个与 setuptools
捆绑在一起的 Python 模块,它是在 Linux 中安装 Python 包推荐的工具之一。
对于 Debian/Ubuntu 用户,请使用 apt-get 命令或apt 命令来安装 pip
。
<span class="pun">[对于</span><span class="typ">Python2</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt install python</span><span class="pun">-</span><span class="pln">pip python</span><span class="pun">-</span><span class="pln">setuptools</span>
<span class="pun">[对于</span><span class="typ">Python3</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt install python3</span><span class="pun">-</span><span class="pln">pip</span>
RHEL/CentOS 官方仓库中没有 pip,因此使用 EPEL 仓库,并使用 YUM 命令安装 pip
。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">yum</span><span class="pln"> install python</span><span class="pun">-</span><span class="pln">pip python</span><span class="pun">-</span><span class="pln">devel python</span><span class="pun">-</span><span class="pln">setuptools</span>
对于 Fedora 系统,使用 dnf 命令来安装 pip
。
<span class="pun">[对于</span><span class="typ">Python2</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> dnf install python</span><span class="pun">-</span><span class="pln">pip</span>
<span class="pun">[对于</span><span class="typ">Python3</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> dnf install python3</span>
对于基于 Arch Linux 的系统,请使用 Pacman 命令 来安装 pip
。
<span class="pun">[对于</span><span class="typ">Python2</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S python2</span><span class="pun">-</span><span class="pln">pip python</span><span class="pun">-</span><span class="pln">setuptools</span>
<span class="pun">[对于</span><span class="typ">Python3</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S python</span><span class="pun">-</span><span class="pln">pip python3</span><span class="pun">-</span><span class="pln">setuptools</span>
对于 openSUSE 系统,使用 Zypper 命令来安装 pip
。
<span class="pun">[对于</span><span class="typ">Python2</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S python</span><span class="pun">-</span><span class="pln">pip</span>
<span class="pun">[对于</span><span class="typ">Python3</span><span class="pun">]</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S python3</span><span class="pun">-</span><span class="pln">pip</span>
用 pip
来在你的系统上安装 cheat
。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pip install cheat</span>
如何使用 Cheat
运行 cheat
,然后按相应的命令
来查看速查表,作为例子,我们要来看下 tar
命令的例子。
<span class="pln">$ cheat </span><span class="kwd">tar</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> extract an uncompressed archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">xvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="kwd">tar</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> create an uncompressed archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">cvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">/</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> extract a </span><span class="pun">.</span><span class="pln">gz archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">xzvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="pln">tgz</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> create a </span><span class="pun">.</span><span class="pln">gz archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">czvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="pln">tgz </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">/</span>
<span class="com">#</span><span class="typ">To</span><span class="kwd">list</span><span class="pln"> the content of an </span><span class="pun">.</span><span class="pln">gz archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">ztvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="pln">tgz</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> extract a </span><span class="pun">.</span><span class="pln">bz2 archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">xjvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="pln">tgz</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> create a </span><span class="pun">.</span><span class="pln">bz2 archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">cjvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="pln">tgz </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">/</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> extract a </span><span class="pun">.</span><span class="kwd">tar</span><span class="kwd">in</span><span class="pln"> specified </span><span class="typ">Directory</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">xvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">-</span><span class="pln">C </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">destination</span><span class="pun">/</span>
<span class="com">#</span><span class="typ">To</span><span class="kwd">list</span><span class="pln"> the content of an </span><span class="pun">.</span><span class="pln">bz2 archive</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">jtvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="pln">tgz</span>
<span class="com">#</span><span class="typ">To</span><span class="pln"> create a </span><span class="pun">.</span><span class="pln">gz archive </span><span class="kwd">and</span><span class="pln"> exclude all jpg</span><span class="pun">,</span><span class="pln">gif</span><span class="pun">,...</span><span class="kwd">from</span><span class="pln"> the tgz</span>
<span class="kwd">tar</span><span class="pln"> czvf </span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">.</span><span class="pln">tgz </span><span class="pun">--</span><span class="pln">exclude</span><span class="pun">=</span><span class="pln">\*</span><span class="pun">.{</span><span class="pln">jpg</span><span class="pun">,</span><span class="pln">gif</span><span class="pun">,</span><span class="pln">png</span><span class="pun">,</span><span class="pln">wmv</span><span class="pun">,</span><span class="pln">flv</span><span class="pun">,</span><span class="kwd">tar</span><span class="pun">.</span><span class="pln">gz</span><span class="pun">,</span><span class="pln">zip</span><span class="pun">}</span><span class="pun">/</span><span class="pln">path</span><span class="pun">/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">foo</span><span class="pun">/</span>
<span class="com">#</span><span class="typ">To</span><span class="kwd">use</span><span class="pln"> parallel </span><span class="pun">(</span><span class="pln">multi</span><span class="pun">-</span><span class="pln">threaded</span><span class="pun">)</span><span class="pln"> implementation of compression algorithms</span><span class="pun">:</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">z </span><span class="pun">...</span><span class="pun">-></span><span class="kwd">tar</span><span class="pun">-</span><span class="typ">Ipigz</span><span class="pun">...</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">j </span><span class="pun">...</span><span class="pun">-></span><span class="kwd">tar</span><span class="pun">-</span><span class="typ">Ipbzip2</span><span class="pun">...</span>
<span class="kwd">tar</span><span class="pun">-</span><span class="pln">J </span><span class="pun">...</span><span class="pun">-></span><span class="kwd">tar</span><span class="pun">-</span><span class="typ">Ipixz</span><span class="pun">...</span>
运行下面的命令查看可用的速查表。
<span class="pln">$ cheat </span><span class="pun">-</span><span class="pln">l</span>
进入帮助页面获取更多详细信息。
<span class="pln">$ cheat </span><span class="pun">-</span><span class="pln">h</span>
via: https://www.2daygeek.com/cheat-a-collection-of-practical-linux-command-examples/
作者:Magesh Maruthamuthu 译者:geekpi 校对:wxy