This commit is contained in:
Xingyu Wang 2021-11-10 15:57:24 +08:00
parent fabb7d2cf3
commit e7c3183a41
2 changed files with 140 additions and 156 deletions

View File

@ -1,156 +0,0 @@
[#]: subject: "exa: A Modern Replacement for the ls Command"
[#]: via: "https://itsfoss.com/exa/"
[#]: author: "Pratham Patel https://itsfoss.com/author/pratham/"
[#]: collector: "lujun9972"
[#]: translator: "wxy"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
exa: A Modern Replacement for the ls Command
======
I bet you have used the [ls command in Linux][1]. Its one of the first command you use while [learning Linux][2] commands.
The simple ls command is quite handy for listing directory content. I never really though any command could replace it until I discovered exa.
### What is exa command?
[exa][3] is a command line tool that lists directories and files in the specified path (or in the current directory if not specified). This might sound familiar to you because it is exactly ls command also does.
exa is supposed to be a modern replacement for the venerable ls command from the good old UNIX days. It has more features and better default than the ls command, so it claims.
![exa features | Courtesy exa project website][4]
Here are some reasons why you would want to use the exa command instead of ls:
* exa is just as portable as ls (available on all major Linux distributions, *BSD and macOS)
* Has colorful output by default
* The differently formatted “verbose-ness” of exa might attract users who are new to Linux/BSDs
* File querying is done in parallel, making exa equivalent or on par to the performance of ls
* Shows git staged or un-staged status for individual files
One of the other aspect of exa is that it is written in the Rust programming language. In case you dont know about the Rust language, it has similar execution speed compared to C while cutting down memory related errors at compile time itself; making your software fast _and_ secure.
### Installing exa on your Linux system
exa has gained quite some popularity lately and thus many distributions have started including it in the official repositories. In other words, you should be able to install it using your [distributions package manager][5].
Starting with Ubuntu 20.10, you can install it using the apt command:
```
sudo apt install exa
```
Arch Linux already has it so just [use the pacman command][6]:
```
sudo pacman -S exa
```
If it is not available through your package manager, dont fret. Its a Rust package after all and you can easily install it with Cargo. Please make sure to [install Rust and Cargo on Ubuntu][7] or whichever distribution you are using.
Once you have Rust and Cargo installed, use this command to install exa:
```
cargo install exa
```
### Using exa
exa has a lot of command options, mostly aimed at a better formatted output and some quality of life improvements like git status for staged or unstaged file, and much more.
Below are a few screenshots demonstrating how exa will work on your system.
Simply using the exa command will produce an output similar to ls but with color. This color thing may not be that attractive because distributions like Ubuntu already provide colored ls output at least in desktop version. However, the ls command doesnt have colored output by default.
```
exa
```
![A screenshot of the exa commands output without any additional flags][8]
Please note that exa and ls command do not have all the same options. For example, while the -l option gives long list in both exa and ls, the -h option adds a column header instead of the human readable option like ls.
```
exa -lh
```
![exa has column titles for a better “verbose-ness” as I mentioned before][9]
I told you that exa has built in git integration. The screenshot below gives the demonstration of the git flag. Notice how the test_file shows -N in tracked column of git because it has not been added to the repository sources yet.
```
exa --git -lh
```
![Demonstration of how the git flag works with exa][10]
The example below is not something my cat typed. Its a combination of various options. Exa has even more options for you to try and explore.
```
exa -abghHliS
```
![A very colorful and detailed output with user friendly verbose output][11]
You can get the full list of options by running the following command in your terminal:
```
exa --help
```
However, if you want to see what exa has to offer, you can view the [official documentation][12] on its [git repository][13].
### Worth switching to exa from ls?
As user friendly as exa might be to someone who is new to UNIX like Operating Systems, it trades the ability of being easily used in a script for “easy-ness” and appearance. Which, to be clear is not a bad thing.
In any case, ls is like the universal command. You may use exa for personal use but when it comes to scripting, stick to ls. The difference of one [or many] flags between ls and exa might drive you crazy when the expected output does not match the actual output in either command.
I would like to know your views on exa. Have you already tried it? Hows your experience with it?
--------------------------------------------------------------------------------
via: https://itsfoss.com/exa/
作者:[Pratham Patel][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/pratham/
[b]: https://github.com/lujun9972
[1]: https://linuxhandbook.com/ls-command/
[2]: https://itsfoss.com/free-linux-training-courses/
[3]: https://the.exa.website/
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/exa-features.png?resize=800%2C331&ssl=1
[5]: https://itsfoss.com/package-manager/
[6]: https://itsfoss.com/pacman-command/
[7]: https://itsfoss.com/install-rust-cargo-ubuntu-linux/
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/01_exa.webp?resize=800%2C600&ssl=1
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/02_exa_lh.webp?resize=800%2C600&ssl=1
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/03_exa_git.webp?resize=800%2C600&ssl=1
[11]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/04_exa_all_flags.webp?resize=800%2C600&ssl=1
[12]: https://github.com/ogham/exa#command-line-options
[13]: https://github.com/ogham/exa

View File

@ -0,0 +1,140 @@
[#]: subject: "exa: A Modern Replacement for the ls Command"
[#]: via: "https://itsfoss.com/exa/"
[#]: author: "Pratham Patel https://itsfoss.com/author/pratham/"
[#]: collector: "lujun9972"
[#]: translator: "wxy"
[#]: reviewer: "wxy"
[#]: publisher: " "
[#]: url: " "
exa一个 ls 命令的现代替代品
======
![](https://img.linux.net.cn/data/attachment/album/202111/10/155648vf7iwcwsetitqfuw.jpg)
我敢打赌你使用过 [Linux 上的 ls 命令][1],它是你 [学习 Linux][2] 时首次接触到的命令之一。
这个简单的 `ls` 命令列出目录的内容十分方便,但是直到我发现 `exa` 之前从来没想过会有命令能替代它。
### exa 命令简介
[exa][3] 是一个命令行工具,可以列出指定路径(如未指定则是当前目录)的目录和文件。这也许听起来很熟悉,因为这就是 `ls` 命令所做的事情。
`exa` 被视作从 UNIX 旧时代延续至今的古老的 `ls` 命令的一个现代替代品。如其所声称的那样,它有比 `ls` 命令更多的功能、更好的默认行为。
![exa 功能][4]
以下是一些你应该使用 `exa` 替代 `ls` 的原因:
* `exa``ls` 一样可移植(在所有主流 Linux 发行版、*BSD 和 macOS 上可用)
* 默认彩色输出
* `exa` 不同格式化的“详细”输出也许会吸引 Linux/BSD 新手
* 文件查询是并行进行的,这使得 `exa``ls` 的性能相当
* 显示单个文件的 git 暂存或未暂存状态
`exa` 的另外一个不同的地方是它是用 Rust 编写的。顺便说一句Rust 与 C 语言的执行速度相近,但在编译时减少了内存错误,使你的软件可以快速而安全地执行。
### 在 Linux 系统上安装 exa
`exa` 最近很流行,因为许多发行版开始将其包括在其官方软件库中。也就是说,你应该可以使用你的 [发行版的包管理器] 来安装它。
从 Ubuntu 20.10 开始,你可以使用 `apt` 命令来安装它:
```
sudo apt install exa
```
Arch Linux 已经有了它,你只需要 [使用 pacman 命令][6] 即可:
```
sudo pacman -S exa
```
如果它无法通过你的包管理器安装,请不要担心。毕竟它是一个 Rust 包,你可以很容易地用 Cargo 安装它。请确保在你使用的任何发行版 [或 Ubuntu 上安装了 Rust 和 Cargo][7]。
安装 Rust 和 Cargo 后,使用此命令安装 `exa`
```
cargo install exa
```
### 使用 exa
`exa` 有很多命令选项,主要是为了更好的格式化输出和一些提高舒适度的改进,比如文件的 git 暂存或未暂存状态等等。
下面是一些屏幕截图,展示了 `exa` 是如何在你的系统上工作的。
简单地使用 `exa` 命令将产生类似于 `ls` 但带有颜色的输出。这种彩色的东西可能没有那么吸引人,因为像 Ubuntu 这样的发行版至少在桌面版本中已经提供了彩色的 `ls` 输出。不过,`ls` 命令本身默认没有彩色输出。
```
exa
```
![exa 命令的输出截图,没有任何额外的标志][8]
请注意,`exa` 和 `ls` 命令的选项不尽相同。例如,虽然 `-l` 选项在 `exa``ls` 中都给出了长列表,但 `-h` 选项添加了一个列标题,而不是 `ls` 的人类可读选项。
```
exa -lh
```
![正如我之前提到的exa 有列标题以获得更好的“详细”输出][9]
我前面说过,`exa` 已经内置了 Git 集成。下面的屏幕截图给出了 `git` 标志的演示。请注意 `test_file``git``tracked` 列中显示 `-N` ,因为它尚未添加到存储库中。
```
exa --git -lh
```
![演示 git 标志如何与 exa 一起工作][10]
下面的例子不是我的猫键入的。它是各种选项的组合。`exa` 有可供你尝试和探索的很多选项。
```
exa -abghHliS
```
![一个非常丰富多彩和详细的输出,具有用户友好的详细输出][11]
你可以通过在终端中运行以下命令来获取完整的选项列表:
```
exa --help
```
但是,如果你想了解 `exa` 所提供的功能,可以查看其 [Git 存储库][13] 上的 [官方文档][12]。
### 值得从 ls 切换到 exa 吗?
对于类 UNIX 操作系统的新手来说,`exa` 可能是用户友好的,它牺牲了在脚本中容易使用的能力,以换取“易用性”和外观。其中,显示得更清楚并不是一件坏事。
无论如何,`ls` 就像通用命令。你可以将 `exa` 用于个人用途,但在编写脚本时,请坚持使用 `ls`。当预期输出与任一命令中的实际输出不匹配时,`ls` 和 `exa` 之间一个 [或多个] 标志的差异可能会让你发疯。
我想知道你对 `exa` 的看法。你已经尝试过了吗?你对它的体验如何?
--------------------------------------------------------------------------------
via: https://itsfoss.com/exa/
作者:[Pratham Patel][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/pratham/
[b]: https://github.com/lujun9972
[1]: https://linuxhandbook.com/ls-command/
[2]: https://itsfoss.com/free-linux-training-courses/
[3]: https://the.exa.website/
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/exa-features.png?resize=800%2C331&ssl=1
[5]: https://itsfoss.com/package-manager/
[6]: https://itsfoss.com/pacman-command/
[7]: https://itsfoss.com/install-rust-cargo-ubuntu-linux/
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/01_exa.webp?resize=800%2C600&ssl=1
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/02_exa_lh.webp?resize=800%2C600&ssl=1
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/03_exa_git.webp?resize=800%2C600&ssl=1
[11]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/04_exa_all_flags.webp?resize=800%2C600&ssl=1
[12]: https://github.com/ogham/exa#command-line-options
[13]: https://github.com/ogham/exa