用大写字母输入Linux命令以将其作为sudo用户运行

用大写字母输入Linux命令以将其作为sudo用户运行

我非常喜欢 Linux 社区的原因是他们创建了很多有趣的项目,你很少能在任何其他操作系统中找到它们。不久前,我们看了一个名为 Hollywood 的有趣项目,它在类 Ubuntu 系统将终端变成了好莱坞技术情景剧的黑客界面。还有一些其他工具,例如 cowsayfortunesltoilet 等,用来消磨时间自娱自乐!它们可能没有用,但这些程序娱乐性不错并且使用起来很有趣。今天,我偶然发现了另一个名为 SUDO 的类似工具。正如名字暗示的那样,你无论何时用大写字母输入 Linux 命令,SUDO 程序都会将它们作为 sudo 用户运行!这意味着,你无需在要运行的 Linux 命令前面输入 SUDO。很酷,不是么?

安装 SUDO

提醒一句:

在安装这个程序(或任何程序)之前,请查看源代码(最后给出的链接),并查看是否包含会损害你的系统的可疑/恶意代码。在 VM 中测试它。如果你喜欢或觉得它很有用,你可以在个人/生产系统中使用它。

用 Git 克隆 SUDO 仓库:

  1. <span class="pln">$ </span><span class="kwd">git</span><span class="pln"> </span><span class="kwd">clone</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//github.com/jthistle/SUDO.git</span>

此命令将克隆 SUDO GIT 仓库的内容,并将它们保存在当前目录下的 SUDO 的目录中。

  1. <span class="typ">Cloning</span><span class="pln"> into </span><span class="str">'SUDO'</span><span class="pun">...</span>
  2. <span class="pln">remote</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Enumerating</span><span class="pln"> objects</span><span class="pun">:</span><span class="pln"> </span><span class="lit">42</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">done</span><span class="pun">.</span>
  3. <span class="pln">remote</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Counting</span><span class="pln"> objects</span><span class="pun">:</span><span class="pln"> </span><span class="lit">100</span><span class="pun">%</span><span class="pln"> </span><span class="pun">(</span><span class="lit">42</span><span class="pun">/</span><span class="lit">42</span><span class="pun">),</span><span class="pln"> </span><span class="kwd">done</span><span class="pun">.</span>
  4. <span class="pln">remote</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Compressing</span><span class="pln"> objects</span><span class="pun">:</span><span class="pln"> </span><span class="lit">100</span><span class="pun">%</span><span class="pln"> </span><span class="pun">(</span><span class="lit">29</span><span class="pun">/</span><span class="lit">29</span><span class="pun">),</span><span class="pln"> </span><span class="kwd">done</span><span class="pun">.</span>
  5. <span class="pln">remote</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Total</span><span class="pln"> </span><span class="lit">42</span><span class="pln"> </span><span class="pun">(</span><span class="pln">delta </span><span class="lit">17</span><span class="pun">),</span><span class="pln"> reused </span><span class="lit">30</span><span class="pln"> </span><span class="pun">(</span><span class="pln">delta </span><span class="lit">12</span><span class="pun">),</span><span class="pln"> pack</span><span class="pun">-</span><span class="pln">reused </span><span class="lit">0</span>
  6. <span class="typ">Unpacking</span><span class="pln"> objects</span><span class="pun">:</span><span class="pln"> </span><span class="lit">100</span><span class="pun">%</span><span class="pln"> </span><span class="pun">(</span><span class="lit">42</span><span class="pun">/</span><span class="lit">42</span><span class="pun">),</span><span class="pln"> </span><span class="kwd">done</span><span class="pun">.</span>

切换到 SUDO 目录:

  1. <span class="pln">$ </span><span class="kwd">cd</span><span class="pln"> SUDO</span><span class="pun">/</span>

并使用命令安装它:

  1. <span class="pln">$ </span><span class="pun">./</span><span class="pln">install</span><span class="pun">.</span><span class="pln">sh</span>

该命令将在 ~/.bashrc 文件中添加以下行:

  1. <span class="pun">[...]</span>
  2. <span class="com">#</span><span class="pln"> SUDO </span><span class="pun">-</span><span class="pln"> shout at </span><span class="kwd">bash</span><span class="pln"> to </span><span class="kwd">su</span><span class="pln"> commands</span>
  3. <span class="com">#</span><span class="pln"> </span><span class="typ">Distributed</span><span class="pln"> under GNU </span><span class="typ">GPLv2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">@jthistle</span><span class="pln"> on github</span>
  4.  
  5. <span class="pln">shopt </span><span class="pun">-</span><span class="pln">s expand_aliases</span>
  6.  
  7. <span class="pln">IFS_</span><span class="pun">=</span><span class="pln">$</span><span class="pun">{</span><span class="pln">IFS</span><span class="pun">}</span>
  8. <span class="pln">IFS</span><span class="pun">=</span><span class="str">":"</span><span class="pln"> read </span><span class="pun">-</span><span class="pln">ra PATHS </span><span class="pun"><<<</span><span class="pln"> </span><span class="str">"$PATH"</span>
  9.  
  10. <span class="kwd">for</span><span class="pln"> i </span><span class="kwd">in</span><span class="pln"> </span><span class="str">"${PATHS[@]}"</span><span class="pun">;</span><span class="pln"> </span><span class="kwd">do</span>
  11. <span class="pln"> </span><span class="kwd">for</span><span class="pln"> j </span><span class="kwd">in</span><span class="pln"> $</span><span class="pun">(</span><span class="pln"> </span><span class="kwd">ls</span><span class="pln"> </span><span class="str">"$i"</span><span class="pln"> </span><span class="pun">);</span><span class="pln"> </span><span class="kwd">do</span>
  12. <span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> $</span><span class="pun">{</span><span class="pln">j</span><span class="pun">^^}</span><span class="pln"> </span><span class="pun">!=</span><span class="pln"> $j </span><span class="pun">]</span><span class="pln"> </span><span class="pun">&&</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> $j </span><span class="pun">!=</span><span class="pln"> </span><span class="str">"sudo"</span><span class="pln"> </span><span class="pun">];</span><span class="pln"> </span><span class="kwd">then</span>
  13. <span class="pln"> </span><span class="kwd">alias</span><span class="pln"> $</span><span class="pun">{</span><span class="pln">j</span><span class="pun">^^}=</span><span class="str">"sudo $j"</span>
  14. <span class="pln"> </span><span class="kwd">fi</span>
  15. <span class="pln"> </span><span class="kwd">done</span>
  16. <span class="kwd">done</span>
  17.  
  18. <span class="kwd">alias</span><span class="pln"> SUDO</span><span class="pun">=</span><span class="str">'sudo $(history -p !!)'</span>
  19.  
  20. <span class="pln">IFS</span><span class="pun">=</span><span class="pln">$</span><span class="pun">{</span><span class="pln">IFS_</span><span class="pun">}</span>
  21.  
  22. <span class="com">#</span><span class="pln"> </span><span class="kwd">end</span><span class="pln"> SUDO</span>

它还会备份你的 ~/.bashrc 并将其保存为 ~/.bashrc.old。如果有重大错误,你可以恢复它。

最后,使用命令更新更改:

  1. <span class="pln">$ source </span><span class="pun">~/.</span><span class="pln">bashrc</span>

现在,用大写字母中输入 Linux 命令,将它们作为 Sudo 用户运行

通常我们像下面那样执行需要 sudo/root 权限的命令。

  1. <span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">mkdir</span><span class="pln"> </span><span class="pun">/</span><span class="pln">ostechnix</span>

对么?没错!上面的命令将在根目录(/)中创建名为 ostechnix 的目录。让我们使用 Ctrl + c 取消。

一旦安装了 SUDO,你就可以在不使用 sudo 的情况下输入任何大写 Linux 命令并运行它们。因此,你可以像下面那样运行上面的命令:

  1. <span class="pln">$ MKDIR </span><span class="pun">/</span><span class="pln">ostechnix</span>
  2. <span class="pln">$ TOUCH </span><span class="pun">/</span><span class="pln">ostechnix</span><span class="pun">/</span><span class="kwd">test</span><span class="pun">.</span><span class="pln">txt</span>
  3. <span class="pln">$ LS </span><span class="pun">/</span><span class="pln">ostechnix</span>

用大写字母输入Linux命令以将其作为sudo用户运行

相关推荐