TranslateProject/sources/tech/20211110 exa- A Modern Replacement for the ls Command.md
DarkSun 31d85f9e5d 选题[tech]: 20211110 exa: A Modern Replacement for the ls Command
sources/tech/20211110 exa- A Modern Replacement for the ls Command.md
2021-11-10 05:02:17 +08:00

6.3 KiB
Raw Blame History

exa: A Modern Replacement for the ls Command

I bet you have used the ls command in Linux. Its one of the first command you use while learning Linux 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 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

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.

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:


    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 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 command’s output without any additional flags

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

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

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

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 on its git repository.

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 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出