exa：一个 ls 命令的现代替代品
ls exa
![](/data/attachment/album/202111/10/155648vf7iwcwsetitqfuw.jpg)


我敢打赌你使用过 [Linux 上的 ls 命令](https://linuxhandbook.com/ls-command/)，它是你 [学习 Linux](https://itsfoss.com/free-linux-training-courses/) 时首次接触到的命令之一。


这个简单的 `ls` 命令列出目录的内容十分方便，但是直到我发现 `exa` 之前从来没想过会有命令能替代它。


### exa 命令简介


[exa](https://the.exa.website/) 是一个命令行工具，可以列出指定路径（如未指定则是当前目录）的目录和文件。这也许听起来很熟悉，因为这就是 `ls` 命令所做的事情。


`exa` 被视作从 UNIX 旧时代延续至今的古老的 `ls` 命令的一个现代替代品。如其所声称的那样，它有比 `ls` 命令更多的功能、更好的默认行为。


![exa 功能](/data/attachment/album/202111/10/155702mm72rrjvmpz9kprh.png)


以下是一些你应该使用 `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 命令](https://itsfoss.com/pacman-command/) 即可：



```
sudo pacman -S exa

```

如果它无法通过你的包管理器安装，请不要担心。毕竟它是一个 Rust 包，你可以很容易地用 Cargo 安装它。请确保在你使用的任何发行版 [或 Ubuntu 上安装了 Rust 和 Cargo](https://itsfoss.com/install-rust-cargo-ubuntu-linux/)。


安装 Rust 和 Cargo 后，使用此命令安装 `exa`：



```
cargo install exa

```

### 使用 exa


`exa` 有很多命令选项，主要是为了更好的格式化输出和一些提高舒适度的改进，比如文件的 git 暂存或未暂存状态等等。


下面是一些屏幕截图，展示了 `exa` 是如何在你的系统上工作的。


简单地使用 `exa` 命令将产生类似于 `ls` 但带有颜色的输出。这种彩色的东西可能没有那么吸引人，因为像 Ubuntu 这样的发行版至少在桌面版本中已经提供了彩色的 `ls` 输出。不过，`ls` 命令本身默认没有彩色输出。



```
exa

```

![exa 命令的输出截图，没有任何额外的标志](/data/attachment/album/202111/10/155702nwcizcfc5c1q1ug9.jpg)


请注意，`exa` 和 `ls` 命令的选项不尽相同。例如，虽然 `-l` 选项在 `exa` 和 `ls` 中都给出了长列表，但 `-h` 选项添加了一个列标题，而不是 `ls` 的人类可读选项。



```
exa -lh

```

![正如我之前提到的，exa 有列标题以获得更好的“详细”输出](/data/attachment/album/202111/10/155702k8226p6c3ra2fafn.jpg)


我前面说过，`exa` 已经内置了 Git 集成。下面的屏幕截图给出了 `–git` 标志的演示。请注意 `test_file` 在 `git` 的 `tracked` 列中显示 `-N` ，因为它尚未添加到存储库中。



```
exa --git -lh

```

![演示 git 标志如何与 exa 一起工作](/data/attachment/album/202111/10/155703wdr02s72rex3b29q.jpg)


下面的例子不是我的猫键入的。它是各种选项的组合。`exa` 有可供你尝试和探索的很多选项。



```
exa -abghHliS

```

![一个非常丰富多彩和详细的输出，具有用户友好的详细输出](/data/attachment/album/202111/10/155703j81475lb746bbrb8.jpg)


你可以通过在终端中运行以下命令来获取完整的选项列表：



```
exa --help

```

但是，如果你想了解 `exa` 所提供的功能，可以查看其 [Git 存储库](https://github.com/ogham/exa) 上的 [官方文档](https://github.com/ogham/exa#command-line-options)。


### 值得从 ls 切换到 exa 吗？


对于类 UNIX 操作系统的新手来说，`exa` 可能是用户友好的，它牺牲了在脚本中容易使用的能力，以换取“易用性”和外观。其中，显示得更清楚并不是一件坏事。


无论如何，`ls` 就像通用命令。你可以将 `exa` 用于个人用途，但在编写脚本时，请坚持使用 `ls`。当预期输出与任一命令中的实际输出不匹配时，`ls` 和 `exa` 之间一个 [或多个] 标志的差异可能会让你发疯。


我想知道你对 `exa` 的看法。你已经尝试过了吗？你对它的体验如何？




---


via: <https://itsfoss.com/exa/>


作者：[Pratham Patel](https://itsfoss.com/author/pratham/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
I bet you have used the [ls command in Linux](https://linuxhandbook.com/ls-command/). It’s one of the first command you use while [learning Linux](https://itsfoss.com/free-linux-training-courses/) 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](https://the.exa.website/) 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](https://itsfoss.com/content/images/wordpress/2021/11/exa-features-800x331.png)

[exa project website](https://the.exa.website/)

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 don’t 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 [distribution’s package manager](https://itsfoss.com/package-manager/).

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](https://itsfoss.com/pacman-command/):

`sudo pacman -S exa`


If it is not available through your package manager, don’t fret. It’s a Rust package after all and you can easily install it with Cargo. Please make sure to [install Rust and Cargo on Ubuntu](https://itsfoss.com/install-rust-cargo-ubuntu-linux/) 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 doesn’t have colored output by default.

`exa`


![01 exa](https://itsfoss.com/content/images/wordpress/2021/11/01_exa-800x600.webp)

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`


![02 exa lh](https://itsfoss.com/content/images/wordpress/2021/11/02_exa_lh-800x600.webp)

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`


![03 exa git](https://itsfoss.com/content/images/wordpress/2021/11/03_exa_git-800x600.webp)

The example below is not something my cat typed. It’s a combination of various options. Exa has even more options for you to try and explore.

`exa -abghHliS`


![04 exa all flags](https://itsfoss.com/content/images/wordpress/2021/11/04_exa_all_flags-800x600.webp)

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](https://github.com/ogham/exa#command-line-options) on its [git repository](https://github.com/ogham/exa).

## 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? How’s your experience with it?