<section id="nice" data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px; color: black; padding: 0 10px; line-height: 1.6; word-spacing: 0px; letter-spacing: 0px; word-break: break-word; word-wrap: break-word; text-align: left; font-family: Helvetica;"><p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">Termux:Android 上的一款终端神器</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;"><span class="footnote-word" style="color: #1e6bb8; font-weight: bold;">Termux</span><sup class="footnote-ref" style="line-height: 0; color: #1e6bb8; font-weight: bold;">[1] 是一款基于 Android 平台的开源 Linux 终端模拟器,使用 pkg(apt) 进行软件包的管理。最重要的是,它无需 root 权限,因此,绝大多数 Android 都可以运行。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">目前来说,它能做一些简单的 Linux 任务:</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; list-style-type: disc;">
<li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">享受 Bash 和 Zsh</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">使用 Vim 编辑文件</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">通过 SSH 访问服务器</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">使用 GCC 和 Clang 编译代码</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">使用 Git 检查项目</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">运行 MySQL,Redis 等服务器</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">...</section></li></ul>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 20px; color: #ab1942;">使用方法</span><span class="suffix"></span></h2>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://cdn.sspai.com/2019/08/04/751123e3d5f5a165eae773e4e9a55750.jpeg?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1" alt="neofetch" style="display: block; margin: 0 auto; max-width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">neofetch</figcaption></figure>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">因为 Termux 是一款 Linux 终端模拟器,因此,在命令的使用方面和 Linux 是一致的。在这里,我将介绍一些针对 Termux 工具的一些使用方法。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">初次使用的准备工作</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">业内已经有了一种共识,在涉及包管理方面,尽量都会将官方源替换成国内镜像源,Termux 也不例外。初次进入 Termux 后,我们可以使用 TUNA 的 <span class="footnote-word" style="color: #1e6bb8; font-weight: bold;">Termux 镜像</span><sup class="footnote-ref" style="line-height: 0; color: #1e6bb8; font-weight: bold;">[2]:</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://files.mdnice.com/user/3441/876cad08-0422-409d-bb5a-08afec5da8ee.svg); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #282c34; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;">@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux stable main@'</span> <span class="hljs-variable" style="color: #d19a66; line-height: 26px;"> pkg up <span class="hljs-comment" style="color: #5c6370; font-style: italic; line-height: 26px;"># 更新源文件</span>
termux-setup-storage
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">执行命令之后,会弹出权限确认窗口,选择「始终允许」即可。</p>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://cdn.sspai.com/2019/08/04/bb5ca5317f63765fd33db22b257ad1ab.jpeg?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1" alt="权限确认" style="display: block; margin: 0 auto; max-width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">权限确认</figcaption></figure>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">pkg 使用命令速记</span><span class="suffix" style="display: none;"></span></h3>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; list-style-type: disc;">
<li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">pkg search <query> 搜索包</query></section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">pkg install <query> 安装包</query></section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">pkg uninstall <query> 卸载包</query></section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">pkg update 更新源</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">pkg upgrade 升级软件包</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">pkg shoe <packge> 显示某个包的详细信息</packge></section></li></ul>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">长按屏幕</span><span class="suffix" style="display: none;"></span></h3>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://cdn.sspai.com/2019/08/04/4f94e8774273e76c1e951ab2c0b2bbda.jpeg?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1" alt="长按屏幕" style="display: block; margin: 0 auto; max-width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">长按屏幕</figcaption></figure>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">如果需要对 Termux 中的内容进行复制以及粘贴内容至 Termux,可以通过长按屏幕实现。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">额外按键视图</span><span class="suffix" style="display: none;"></span></h3>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://cdn.sspai.com/2019/08/04/039bcf1c14a4bed40be90596e78594b2.jpg?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1" alt="额外按键视图" style="display: block; margin: 0 auto; max-width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">额外按键视图</figcaption></figure>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">可以看到,在正常的键盘上方,还有一盘额外的功能键,分别是:ESC 键,Tab 键,CTRL 键,ALT 键,- 符号,向下以及向上功能键。有了这一行额外视图,可以更加方便地实现 Android 键盘上没有,而电脑键盘上有的功能。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">音量+组合</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">因为 Android 键盘没有电脑键盘上的一些功能按键,此时,我们可以通过按住音量键+,再输入键盘某个字母数字键,可以达到一些功能键的作用。</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; list-style-type: disc;">
<li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">音量+ Q:显示/隐藏额外按键视图</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">音量+数字键:Fx(电脑键盘上的数字功能键)</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">音量+L:|(管道字符)</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">音量+H:~(波浪字符)</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">音量+U:_(下划线字符)</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">音量+P:上一页</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;">音量+N:下一页</section></li></ul>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 20px; color: #ab1942;">一些简单的应用</span><span class="suffix"></span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">HTTP Server</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">有些时候,我们需要将 Android 上的某些文件发送到其他设备(例如笔记本,分享)。以往的解决方案一般是用微信或者 QQ 来作为中转站,现在,可以利用 Termux 搭建一个简单的文件服务器来实现。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://files.mdnice.com/user/3441/876cad08-0422-409d-bb5a-08afec5da8ee.svg); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #282c34; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;"> ifconfig wlan0 <span class="hljs-comment" style="color: #5c6370; font-style: italic; line-height: 26px;"># 查看 Android 在局域网中的 IP 地址(我的为 192.168.2.104)</span>
$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/)...
</code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">命令成功运行之后,可以看到输出信息中包含了端口地址(我这里是 8000)。此时,用另外一台处于相同局域网(例如 Wi-Fi)的设备在浏览器地址输入 <code style="font-size: 14px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #e96900; background: #f8f8f8;">192.168.2.104:8000</code> 即可访问文件服务器了。</p>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://cdn.sspai.com/2019/08/04/f28d7de2ddfa009ee7f7dc729bdc32c0.png?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1" alt="HTTP Server" style="display: block; margin: 0 auto; max-width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">HTTP Server</figcaption></figure>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">看起来像黑客</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;">一提到命令行,怎能少得了那些酷炫的字符如降雨一般,这看起来就很黑客。我们可以通过安装 <code style="font-size: 14px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #e96900; background: #f8f8f8;">pkg install cmartix</code> 来实现这种效果。</p>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://cdn.sspai.com/2019/08/04/29ed98b026b63207a82b0156ca3b7676.jpeg?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1" alt="Cmatrix" style="display: block; margin: 0 auto; max-width: 100%;"><figcaption style="margin-top: 5px; text-align: center; color: #888; font-size: 14px;">Cmatrix</figcaption></figure>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 18px; color: #3da742;">参考文章</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;"><span class="footnote-word" style="color: #1e6bb8; font-weight: bold;">Learn Termux</span><sup class="footnote-ref" style="line-height: 0; color: #1e6bb8; font-weight: bold;">[3]</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;"><span class="footnote-word" style="color: #1e6bb8; font-weight: bold;">Termux 高级终端安装使用配置教程</span><sup class="footnote-ref" style="line-height: 0; color: #1e6bb8; font-weight: bold;">[4]</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; font-size: 16px;"><span class="footnote-word" style="color: #1e6bb8; font-weight: bold;">Termux 入门教程:架设手机 Server 下载文件</span><sup class="footnote-ref" style="line-height: 0; color: #1e6bb8; font-weight: bold;">[5]</p>
<h3 class="footnotes-sep" data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span style="display: block;">参考资料</span></h3>
<section class="footnotes" data-tool="mdnice编辑器">
<span id="fn1" class="footnote-item" style="display: flex;"><span class="footnote-num" style="display: inline; width: 10%; background: none; font-size: 80%; opacity: 0.6; line-height: 26px; font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;">[1] </span><p style="padding-top: 8px; padding-bottom: 8px; display: inline; font-size: 14px; width: 90%; padding: 0px; margin: 0; line-height: 26px; color: black; word-break: break-all; width: calc(100%-50);">Termux: <em style="font-style: italic; color: black;">https://termux.com/</em></p>
</span>
<span id="fn2" class="footnote-item" style="display: flex;"><span class="footnote-num" style="display: inline; width: 10%; background: none; font-size: 80%; opacity: 0.6; line-height: 26px; font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;">[2] </span><p style="padding-top: 8px; padding-bottom: 8px; display: inline; font-size: 14px; width: 90%; padding: 0px; margin: 0; line-height: 26px; color: black; word-break: break-all; width: calc(100%-50);">Termux 镜像: <em style="font-style: italic; color: black;">https://mirror.tuna.tsinghua.edu.cn/help/termux/</em></p>
</span>
<span id="fn3" class="footnote-item" style="display: flex;"><span class="footnote-num" style="display: inline; width: 10%; background: none; font-size: 80%; opacity: 0.6; line-height: 26px; font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;">[3] </span><p style="padding-top: 8px; padding-bottom: 8px; display: inline; font-size: 14px; width: 90%; padding: 0px; margin: 0; line-height: 26px; color: black; word-break: break-all; width: calc(100%-50);">Learn Termux: <em style="font-style: italic; color: black;">https://github.com/breathiness/learn-termux</em></p>
</span>
<span id="fn4" class="footnote-item" style="display: flex;"><span class="footnote-num" style="display: inline; width: 10%; background: none; font-size: 80%; opacity: 0.6; line-height: 26px; font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;">[4] </span><p style="padding-top: 8px; padding-bottom: 8px; display: inline; font-size: 14px; width: 90%; padding: 0px; margin: 0; line-height: 26px; color: black; word-break: break-all; width: calc(100%-50);">Termux 高级终端安装使用配置教程: <em style="font-style: italic; color: black;">https://www.sqlsec.com/2018/05/termux.html#toc-heading-2</em></p>
</span>
<span id="fn5" class="footnote-item" style="display: flex;"><span class="footnote-num" style="display: inline; width: 10%; background: none; font-size: 80%; opacity: 0.6; line-height: 26px; font-family: ptima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;">[5] </span><p style="padding-top: 8px; padding-bottom: 8px; display: inline; font-size: 14px; width: 90%; padding: 0px; margin: 0; line-height: 26px; color: black; word-break: break-all; width: calc(100%-50);">Termux 入门教程:架设手机 Server 下载文件: <em style="font-style: italic; color: black;">http://www.ruanyifeng.com/blog/2019/07/termux-tutorial.html</em></p>
</span>
</section>
</section>
开源前哨
日常分享热门、有趣和实用的开源项目。参与维护 10万+ Star 的开源技术资源库,包括:Python、Java、C/C++、Go、JS、CSS、Node.js、PHP、.NET 等。