10 款你不知道的 Linux 环境下的替代工具!

{"type":"doc","content":[{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作者:JackTian","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"来源:公众号「杰哥的IT之旅」","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ID:Jake_Internet","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"转载请联系授权(微信ID:Hc220088)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原文地址:","attrs":{}},{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s/p9WlxEBfFj0h7IQIOa9Xqw","title":"","type":null},"content":[{"type":"text","text":"https://mp.weixin.qq.com/s/p9WlxEBfFj0h7IQIOa9Xqw","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大家好,我是杰哥。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Linux 操作系统下,我们经常使用 cat 命令去连接多个文件并打印到标准输出,合成几个文件为一个目标文件,追加几个文件到目标文件中。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最近我在 GitHub 上发现了一个具有相似作用的命令叫做 “","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Bat","attrs":{}}],"attrs":{}},{"type":"text","text":"”,它是 cat 命令的替代品,具有一些例如","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"语法高亮","attrs":{}}],"attrs":{}},{"type":"text","text":"、 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Git 集成","attrs":{}}],"attrs":{}},{"type":"text","text":"和","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"自动分页","attrs":{}}],"attrs":{}},{"type":"text","text":"等非常酷的特性。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在这篇文章中,就来给大家介绍下如何在 Linux 中安装和使用 bat 命令。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"一、bat","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"安装 bat","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"Arch Linux","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"bat 可以在 Arch Linux 操作系统的默认软件源中进行获取,可直接使用 pacman 命令在任何基于  Arch 的系统上来安装它。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"pacman -S bat","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"Fedora","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"dnf install bat","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"macOS","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"brew install bat","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"Ubuntu 21.10","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我是通过 Ubuntu 环境下安装的 bat,从 bat 的发布页面下载","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":".deb","attrs":{}}],"attrs":{}},{"type":"text","text":"文件,可执行如下命令进行下载和安装。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"sudo apt-get install wget\nwget https://github.com/sharkdp/bat/releases/tag/v0.18.3/bat_0.18.3_amd64.deb\nsudo dpkg -i bat_0.18.3_amd64.deb","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"对于其他系统,也许需要从软件源编译并安装,或参考 GitHub 上 bat 的其他操作系统安装方式。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"bat 命令的使用","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"bat 命令的使用与 cat 命令的使用非常相似。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用 bat 命令创建一个新文件:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"bat > jiaoben1.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用 bat 命令查看文件内容:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"bat jiaoben1.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用 bat 命令同时查看多个文件:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"bat jiaoben1.sh jiaoben2.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用 bat 命令将多个文件的内容合并到一个单独的文件中:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"bat jiaoben1.sh jiaoben2.sh > test.txt","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上述介绍了 bat 创建新文件、查看文件内容、将多个文件的内容合并到一个单独的文件中的方式。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接下来,我们就来看一下 bat 命令一些非常酷的特性。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"bat 命令支持大多数编程和标记语言的语法高亮,那么我们就来使用 cat 和 bat 命令展示下 jiaoben1.sh 里面的内容做个鲜明的对比。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c0/c09b2479b8cb4e22a8049644aed2e885.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可以看出,cat 命令以纯文本格式显示文件的内容,而 bat 命令显示了语法高亮和整齐的文本对齐格式。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"从上面 bat 命令的输出,可以看出是有表格线的,如果你只想显示行号(而没有表格)可以使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"-n","attrs":{}}],"attrs":{}},{"type":"text","text":"参数来实现,虽然 cat 执行也会显示行号,但还是没有 bat 执行输出后的效果美观。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"bat -n jiaoben2.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/0f/0f87a007ded1c2b15457e73b720ab31b.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"bat 命令支持 Git 集成,可以轻松查看和编辑 Git 存储库中的文件,bat 与 Git 连接可显示关于索引的修改。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/a0/a0b3679df51ebf393d1073c839392d5d.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"bat 支持自动分页,这点特性也是需要值得注意的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"支持分页意思也就是说,当文件的输出内容超出屏幕显示的时候,bat 命令会自动将自己输出的内容传到 less 命令中,你将可以使用回车键一页一页的查看输出内容,使用空格键可直接跳转至文末最后一行。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"当你使用 bat 命令时这些都是不必要的,bat 命令将自动传输跨越多个页面的文件的输出。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"bat jiaoben3.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c7/c797db5fc451b18158096e2268610a63.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"对比下 cat 命令,查看 jiaoben3.sh 跨多个页面文件内容时,提示符会直接跳到文件的最后一页,将无法看到跨多个页面文件开头及中间部分的内容。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"cat jiaoben3.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/dc/dc57b7c0be968bf78f057a19ac5545c2.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你想要通过 cat 来实现 bat 命令的效果,则需要去使用 cat 的输出传输到 less 命令中去,这样就可以从开头部分一页一页的查看内容了。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"cat jiaoben3.sh | less","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/0d/0d2e110d8921443c0a1869f092eb5cca.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同样,这种方式也是可以使用回车键一页一页的查看输出内容以及使用空格键可直接跳转至文末最后一行。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"bat 定制主题","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前 bat 定制主题有 24 种,包括:Coldark-Cold、GitHub、Monokai Extended Light、OneHalfDark、Solarized (light)、TwoDark、Visual Studio Dark+、base16、zenburn 等;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你不喜欢默认主题,也是可以根据自己的风格进行修改,只需执行:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"bat --list-themes","attrs":{}}],"attrs":{}},{"type":"text","text":"命令,即可显示可用的主题。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"# bat --list-themes\nTheme: 1337\n\n // Output the square of a number.\n fn print_square(num: f64) {\n let result = f64::powf(num, 2.0);\n println!(\"The square of {:.2} is {:.2}.\", num, result);\n }\n\n......","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"例如你要选择","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Dracula","attrs":{}}],"attrs":{}},{"type":"text","text":"主题,可直接执行:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"bat --theme=Dracula 文件名","attrs":{}}],"attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/40/4060de17c2f2ecd8ffa2b8989d85988f.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你想永久改变某一个主题,可使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"export BAT_THEME=\"Dracula\"","attrs":{}}],"attrs":{}},{"type":"text","text":"在你的 shell 启动文件,以使更改为永久。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"您可以使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"--style","attrs":{}}],"attrs":{}},{"type":"text","text":"参数选项来控制","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"bat","attrs":{}}],"attrs":{}},{"type":"text","text":"输出的外观,配置元素包括:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"行号、文件头、网格边框、Git修改","attrs":{}}],"attrs":{}},{"type":"text","text":"来显示除文件内容之外的东西,参数是一个逗号分隔的列表。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"--style=numbers,changes","attrs":{}}],"attrs":{}},{"type":"text","text":"可以使用仅显示 Git修改和行号,而不显示网格和文件标题,设置","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"BAT_STYLE","attrs":{}}],"attrs":{}},{"type":"text","text":"环境变量以使这些更改为永久。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"关于更多 bat 的使用方法可通过执行命令","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"man bat","attrs":{}}],"attrs":{}},{"type":"text","text":"或","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"bat --help","attrs":{}}],"attrs":{}},{"type":"text","text":"。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除此之外,也可以通过 bat 项目的 GitHub 库查看更多详细信息,我用过 bat 后就不会再想用回 cat 了!","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"二、duf","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Linux 环境下,我们知道 df 命令是用于显示磁盘分区上可使用的磁盘空间,默认显示单位为 KB,你还可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"# df\nFilesystem     1K-blocks    Used Available Use% Mounted on\n/dev/sda3       18439940 4943264  12559972  29% /\ntmpfs             506176      76    506100   1% /dev/shm\n/dev/sda1          99150   30003     64027  32% /boot\n/dev/sr0         4363088 4363088         0 100% /media/CentOS_6.5_Final","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除此之外,du 命令也是查看使用空间的,但与 df 命令不同的是 Linux du 命令是对文件和目录磁盘使用的空间的查看,和 df 命令还是有一些区别的。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"# du\n4    ./.abrt\n8    ./.dbus/session-bus\n12    ./.dbus\n4    ./.nautilus\n40    ./.local/share/gvfs-metadata\n24    ./.local/share/applications\n68    ./.local/share\n72    ./.local","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接下来就跟大家介绍一款终端工具,你可以理解为传统的 Linux 命令 df 和 du 整合版 —— duf。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"duf 是一个用 Golang 编写的跨平台磁盘使用情况工具,可以让你轻松地检查可用磁盘空间,对输出进行分类,并以用户友好的方式进行呈现,适用于 Linux、Windows、macOS、Android、FreeBSD;","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"Ubuntu 安装方式:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"$ sudo apt install gdebi\n#如果报错,Failed to fetch http://security.ubuntu.com......\n# sudo apt-get update\n\n$ sudo gdebi duf_0.5.0_linux_amd64.deb\n#要先在下载duf_0.5.0_linux_amd64.deb,下载地址为:https://github.com/muesli/duf/releases/download/v0.5.0/duf_0.5.0_linux_amd64.deb","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"MacOS 安装方式:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"#先安装Homebrew,按照提示安装即可。\n/bin/zsh -c \"$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)\"\n\n#安装duf\nbrew install duf\n\n#或者\nsudo port selfupdate && sudo port install duf","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"Windows 安装方式:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"choco install duf\n\n#或者\n\nscoop install duf","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"安装完毕后,可直接使用 duf,方法也非常简单。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不添加任何参数,会输出所有本地设备、已挂载的任何云存储设备以及任何其他特殊设备(包括临时存储位置等)的详细信息;","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"$ duf","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f1/f1b19791db4754f887014fc00d44b6fa.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你只想查看本地连接设备的详细信息,而不想看其他的,可执行:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"$ duf --only local","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4d/4db04c8543c5a55f804ae04a1d43a5bb.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你只想根据大小按特定顺序对输出信息进行排序,可执行:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"$ duf --sort size","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/be/beb67ee9bd32771874e1bb979b3fb2a4.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"更多参数使用方式:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"duf /home /some/file 根据参数,则 duf 将仅列出特定的设备和安装点\nduf --all 列出所有内容\nduf --hide-network 隐藏网络文件系统,与之对应的 --hide-fuse --hide-special --hide-loops --hide-binds\nduf --inodes 列出inodes\nduf --output mountpoint,size,usage 指定输出的格式 对应的还有(mountpoint, size, used, avail, usage, inodes, inodes_used, inodes_avail, inodes_usage, type, filesystem)\nduf --json 以json格式输出\nduf --theme light 如果 duf 无法正确检测终端的颜色,可以设置一个主题\nduf --help 查看所有 duf 的可用命令","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"三、tldr","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"对于初学者学习 Linux 来说,遇到最多的问题就是在 Linux 操作系统下有记不完的命令以及包括各种参数的使用方法,其实你根本不用死记硬背它,当你用到时去查找相关资料或通过","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"man","attrs":{}}],"attrs":{}},{"type":"text","text":"命令来查看相关文档,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"man","attrs":{}}],"attrs":{}},{"type":"text","text":"手册输出的信息也比较多,而对于参数较多的命令来说,翻看","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"man","attrs":{}}],"attrs":{}},{"type":"text","text":"手册也非常吃力。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/e6/e6813d76f82d12ef95d9ba4af4dfdf3f.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这次就给大家介绍一款工具:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"tldr","attrs":{}}],"attrs":{}},{"type":"text","text":",它的全称是:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Too Long, Don't Read","attrs":{}}],"attrs":{}},{"type":"text","text":",中文意思:太长不看的意思。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其实跟","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"man","attrs":{}}],"attrs":{}},{"type":"text","text":"命令的结果基本上就是太长不看,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"tldr","attrs":{}}],"attrs":{}},{"type":"text","text":" 这个工具你可以理解为简化了 man 命令的帮助文档,把 Linux 命令最常用的一些命令用法列举出来,非常容易看懂。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同时,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"tldr","attrs":{}}],"attrs":{}},{"type":"text","text":"包括非常多语言编写的客户端,比如:C、Go、iOS、Python、nodejs 等等,你可以使用不同的客户端来安装;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我这里的环境是 Ubuntu,需要先安装 Node.js,然后根据下述安装方式操作:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"sudo apt-get install nodejs\n\nsudo apt-get install npm\n\nsudo npm install -g tldr","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"执行完上述三条命令后,还需要再执行","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"tldr --update","attrs":{}}],"attrs":{}},{"type":"text","text":",更新","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"tldr","attrs":{}}],"attrs":{}},{"type":"text","text":"至最新的状态,然后就可以直接使用了;","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"tldr --update","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"tldr 的使用:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"tldr 命令的使用也非常简单,只需 tldr + 你所要查询的命令即可;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/59/595d09e91029090399e4b22d09fb52f5.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"四、htop","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Linux 操作系统上显示进程运行状态信息最常用工具是我们熟悉的 top,它是每位系统管理员的好帮手。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"htop 可以说是 top 的绝佳替代品,它是用 C 写的,是一个跨平台的交互式的进程监控工具,具有更好的视觉效果,一目了然更容易理解当前系统的状况,允许垂直和水平滚动进程列表以查看它们的完整命令行和相关信息,如内存和 CPU 消耗。还显示了系统范围的信息,例如平均负载或交换使用情况。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"显示的信息可通过图形设置进行配置,并且可以交互排序和过滤,与进程相关的任务(例如终止和重新处理)可以在不输入其 PID 的情况下进行完成。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"安装也很简单,只需执行命令:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"apt install htop","attrs":{}}],"attrs":{}},{"type":"text","text":"即可完成。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/05/055389ed1fcf0803b707a0f941ab710f.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"htop 比起 top,优势很明显,除了功能更加完善以外,它的色彩搭配也很丰富,整体上使用起来更加友好。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"五、glances","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Glances 是用 Python 写的一个跨平台的监控工具,旨在通过 curses 或基于 Web 的界面呈现大量系统监控信息,该信息根据用户界面的大小动态调整,是 GNU/Linux、BSD、Mac OS 和 Windows 操作系统的 top/htop 替代品。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"它可以在客户端/服务器模式下工作,远程监控可以通过终端、Web 界面或 API(XML-RPC 和 RESTful)完成,统计数据也可以导出到文件或外部时间/值数据库。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除了列出所有进程及其 CPU 和内存使用情况之外,它还可以显示有关系统的其他信息,比如:","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"网络及磁盘使用情况","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"文件系统已使用的空间和总空间","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"来自不同传感器(例如电池)的数据","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以及最近消耗过多资源的进程列表","attrs":{}}]}]}],"attrs":{}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/6e/6e494d0d619602db6740982711f741ad.gif","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"六、exa","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"提到 ls 命令,大家都不陌生,在 Linux 环境下,其主要作用:列出当前目录下所包含的文件及子目录,如果当前目录下文件过多,则使用命令 ls 不是很好,因为这输出出来的结果跟你所要查找的文件未能达成一致,第一:需要进行二次过滤查找;第二:文件过多时,终端输出结果较慢;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"EXA 是 Unix 和 Linux 操作系统附带的命令行程序的 ls 现代替代品,赋予它更多功能和更好的默认值。它使用颜色来区分文件类型和元数据。它了解符号链接、扩展属性和 Git。它","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"体积小","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"速度快","attrs":{}}],"attrs":{}},{"type":"text","text":",而且只有一个","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"二进制文件","attrs":{}}],"attrs":{}},{"type":"text","text":"。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"EXA 与 LS 有什么不同之处?","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"终端屏幕不再是瓶颈:exa 功能强大,比 ls 要友好,输出结果会更快;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"颜色:exa 大量使用颜色;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不与 ls 命令冲突","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"EXA 的特征","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"色彩:文件类型列表以及如何区分文件;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"网格视图:在与终端窗口大小相同的网格中显示文件;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"长远:在表中显示文件及其元数据;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"树视图:在树中显示文件及其子代;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Git 集成:在存储库中时,查看文件的 Git 状态;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"筛选:隐藏列表中的文件,显示不可见的文件,并对输出进行排序;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Xattrs:列出文件的扩展属性;","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Ubuntu 21.10 安装只需执行命令:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"apt install exa","attrs":{}}],"attrs":{}},{"type":"text","text":"即可。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"显示选项","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-1,--oneline:每行显示一个条目","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-G,--grid:将条目显示为网格(默认)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-l,--long:显示扩展细节和属性","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-R,--recurse:递归到目录","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-T,--tree:作为树递归到目录中","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-x,--across:对网格进行排序,而不是向下排序","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-F,--classify:按文件名显示类型指示器","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"--colo[u]r:何时使用终端颜色","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"--colo[u]r-scale : 清楚地突出显示文件大小的级别","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"--icons : 显示图标","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"--no-icons : 不显示图标(总是覆盖 --icons)","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"过滤选项","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-a,--all:显示隐藏和“点”文件","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-d,--list-dirs:像普通文件一样列出目录","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-L,--level=(depth):限制递归深度","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-r,--reverse:反转排序顺序","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-s,--sort=(field):按哪个字段排序","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"--group-directories-first:在其他文件之前列出目录","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-D,--only-dirs:只列出目录","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"--git-ignore:忽略中提到的文件.gitignore","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-I,--ignore-glob=(globs):要忽略的文件的全局模式(管道分隔)","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"传递该","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"--all","attrs":{}}],"attrs":{}},{"type":"text","text":"选项两次以同时显示","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":".","attrs":{}}],"attrs":{}},{"type":"text","text":"和","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"..","attrs":{}}],"attrs":{}},{"type":"text","text":"目录。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4b/4bd01bd6ef8c2edd57f3fee25a0d7c79.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"关于 EXA 更多可参考:","attrs":{}},{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s?__biz=MzAwMjg1NjY3Nw==&mid=2247488292&idx=1&sn=5bec2375a46edd32f3f78aae796005ea&scene=21#wechat_redirect","title":"","type":null},"content":[{"type":"text","text":"https://mp.weixin.qq.com/s?__biz=MzAwMjg1NjY3Nw==&mid=2247488292&idx=1&sn=5bec2375a46edd32f3f78aae796005ea&scene=21#wechat_redirect","attrs":{}}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"七、fd","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"fd 是一个在文件系统中查找条目的程序,它是 find 命令的一个简单、快速且用户友好的替代品,fd 目的不是取代 find 命令所提供的全部功能,而是在多数用例中提供了合理的默认值,在某些情况下非常有用。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"fd 输出是彩色的,类似于某些 ls 模式,它是递归的,在包含 Git 存储库的目录中搜索源代码文件时,fd 会自动排除隐藏的文件和目录,包括","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":".","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":".git","attrs":{}}],"attrs":{}},{"type":"text","text":"目录,并忽略","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":".gitignore","attrs":{}}],"attrs":{}},{"type":"text","text":"文件中的模式。一般来说,搜索速度更快,而且第一次搜索时会提供了更多相关结果。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"默认情况下,fd 在当前目录中执行不区分大小写的模式搜索,但是,如果你的搜索模式包含一个大写字母,fd 将以区分大小写的模式进行执行。当然,也可以重写默认值,但在许多情况下还是有利的。同样使用 find 进行相同的搜索需要你提供额外的命令行参数。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"fd 可用于许多 Linux 发行版,执行以下命令,可以使用标准存储库在 Ubuntu 中安装:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"sudo apt install fd-find","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Ubuntu 操作系统中,命令是 fdfind,避免与其他现有的实用程序名称发生冲突,如果希望它是 fd,可以设置一个别名:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"alias fd=fdfind","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"要使别名保持不变,在重启后仍然可用,请将其放入“","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":".bashrc","attrs":{}}],"attrs":{}},{"type":"text","text":"”或“","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":".bash_aliases","attrs":{}}],"attrs":{}},{"type":"text","text":"”文件中。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用不带参数选项的 fd,则类似于 ls,不同之处在于它默认情况下也会将子目录中的文件进行列出。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"fd\nbat_0.18.3_amd64.deb\nfd_8.3.0_amd64.deb\njiaoben1.sh\njiaoben2.sh\njiaoben3.sh\nsnap\nsnap/firefox\nsnap/firefox/631\nsnap/firefox/731\nsnap/firefox/common\nsnap/firefox/current\nsnap/snap-store\nsnap/snap-store/557\nsnap/snap-store/558\nsnap/snap-store/common\nsnap/snap-store/current\ntest.md","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在当前目录中搜索所有的 markdown 文件(.md 或.MD ),find 命令如下:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"find . -iname \"*.md\"\n./test.md","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用 fd 进行同样的搜索:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"fd *.md\ntest.md","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在某些情况下,fd 需要额外的选项;例如,如果你想包含隐藏文件和目录,则必须使用选项 -H,而这在 find 中是不需要的,关于 fd 更多命令行参数选项的使用方法,可查阅 fd GitHub 存储库。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"八、ag","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"ack","attrs":{}}],"attrs":{}},{"type":"text","text":"和","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"ag","attrs":{}}],"attrs":{}},{"type":"text","text":"是两个文本搜索工具,比自带的","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"grep","attrs":{}}],"attrs":{}},{"type":"text","text":"要好用得多。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在指定目录下搜索文本时,不需要像 grep 那样指定各种命令行选项,输出结果也会包含文件名和行号,并且会高亮显示搜索关键字。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"ag","attrs":{}}],"attrs":{}},{"type":"text","text":"是可以比","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"grep","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"ack","attrs":{}}],"attrs":{}},{"type":"text","text":"更快的递归搜索文件内容。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Ubuntu 21.10 安装 ag 和 ack","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"ack和ag是两个文本搜索工具,比自带的grep要好用得多。\n\n在指定目录下搜索文本时,不需要像 grep 那样指定各种命令行选项,输出结果也会包含文件名和行号,并且会高亮显示搜索关键字。\n\nag是可以比grep、ack更快的递归搜索文件内容。\n\nUbuntu 21.10 安装 ag 和 ack","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"ag 命令常用参数","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag -g (文件名):类似于 find . -name (文件名)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag -i sed:忽略大小写搜索含 sed 文本","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag -A sed:搜索含 sed 文本,并显示匹配内容之后的 n 行文本","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag -B sed:搜索含 sed 文本,并显示匹配内容之前的 n 行文本","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag -C sed:搜索含 sed 文本,并同时显示匹配内容以及它前后各 n 行文本的内容","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag -w sed:全匹配搜索,只搜索与所搜内容完全匹配的文本","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag --java sed:在 java 文件中搜索含 sed 的文本","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ag --xml sed:在 XML 文件中搜索含 sed 的文本","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"ag 命令的使用","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"根据文件名进行搜索对应的文件,可使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"-g","attrs":{}}],"attrs":{}},{"type":"text","text":"参数选项。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"ag -g jiaoben\njiaoben2.sh\njiaoben1.sh\njiaoben3.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"搜索当前目录下有关 sed 关键字的文本。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"ag -w sed\njiaoben1.sh\n10:                sed -i '2d' \"$new_filename\"","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/12/12b9855dd1e17edc5d21615474e46e1c.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"更多参数选项,大家可根据自身实际场景进行运用。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"九、axel","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"axel 是命令行多线程下载工具,下载文件时可以替代 curl、wget。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Ubuntu 21.10 安装 axel","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"apt-get install axel","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"axel 参数选项","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-n:指定线程数","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-o:指定另存为目录","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-s:指定每秒的最大比特数","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"-q:静默模式","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"案例","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"# axel -n 10 -o /tmp/ http://mirrors.163.com/ubuntu/ls-lR.gz\n# exa /tmp/ls-lR.gz\n/tmp/ls-lR.gz","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可以看出,我们通过 axel 也是可以把 ls-lR.gz 这个文件正常下载到 /tmp 目录下的。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"十、pydf","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Linux 系统下,我们可以使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"df","attrs":{}}],"attrs":{}},{"type":"text","text":"命令来显示磁盘的相关信息。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"# df\n文件系统          1K-块     已用    可用 已用% 挂载点\ntmpfs            199180     1660  197520    1% /run\n/dev/sda3      19946096 10317864 8589692   55% /\ntmpfs            995884        0  995884    0% /dev/shm\ntmpfs              5120        4    5116    1% /run/lock\n/dev/sda2        524252     5344  518908    2% /boot/efi\ntmpfs            199176      100  199076    1% /run/user/1000\n/dev/sr0        3043440  3043440       0  100% /media/jacktian/Ubuntu 21.10 amd64\ntmpfs            199176       60  199116    1% /run/user/0","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Ubuntu 21.10 安装 pydf","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"apt install pydf","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"pydf 可以说是 df 的替代品,它以更简洁的方式显示磁盘使用状态。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b6/b60ea56575498f3aef43f3fe463eed67.webp","alt":"图片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"参考","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"bat:https://github.com/sharkdp/bat","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"duf:https://github.com/muesli/duf","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"tldr:https://github.com/tldr-pages/tldr","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"htop:https://github.com/htop-dev/htop","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"glances:https://github.com/nicolargo/glances","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"exa:https://github.com/ogham/exa","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"fd:https://github.com/sharkdp/fd/","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"最后","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"虽然我们在日常工作中,大多数还都是用的默认基本命令工具,当如果你替换成上述所介绍的 10 款替代品工具时,相信在许多场景中还是非常有用的。当然了,可能还有更多的 Linux 命令行替代工具,也欢迎大家在下面的留言区补充。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上就是今天所要分享的全部内容了。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你觉得这篇文章对你有点用的话,为本文","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"点个赞","attrs":{}},{"type":"text","text":" or ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"在看","attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"留个言","attrs":{}},{"type":"text","text":"或者","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"转发","attrs":{}},{"type":"text","text":"一下,让更多的朋友看到,因为这将是我持续输出更多优质文章的最强动力!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​ ","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/01/019b65e5ec6661e8bbcaec704494797d.jpeg","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章