How to use the command `eza` (with examples)

How to use the command `eza` (with examples)

The eza command is a modern and maintained replacement for the ls command, built on exa. It provides additional features and options for listing and displaying files. This article will illustrate several use cases of the eza command.

Use case 1: List files one per line

Code:

eza --oneline

Motivation: Sometimes, we might need to have a concise and easy-to-read list of files without any additional information. The --oneline option simplifies the output by displaying each file on a separate line, making it easier to process or manipulate the list.

Example output:

file1.txt
file2.txt
file3.txt

Use case 2: List all files, including hidden files

Code:

eza --all

Motivation: By default, the ls command does not display hidden files (files starting with a .). However, there are cases where we need to see these hidden files along with the regular files. The --all option allows us to list all files, including hidden ones.

Example output:

file1.txt
.file2.txt
file3.txt

Use case 3: Long format list of all files

Code:

eza --long --all

Motivation: The long format of the ls command provides additional information about each file, such as permissions, ownership, size, and modification date. This can be useful when inspecting files in detail or when troubleshooting permissions issues. The --long option enables the long format, while the --all option lists all files, including hidden ones.

Example output:

-rw-r--r--  username  groupname  1024  Jun 10 09:00  file1.txt
-rw-r--r--  username  groupname  2048  Jun 12 13:45  .file2.txt
-rw-r--r--  username  groupname  512   Jun 15 17:30  file3.txt

Use case 4: List files with the largest at the top

Code:

eza --reverse --sort=size

Motivation: Sometimes, we might need to identify the largest files in a directory or prioritize our attention to files of a certain size. The --sort=size option sorts the files by size, while the --reverse option reverses the sorting order, displaying the largest files at the top.

Example output:

file3.txt
file2.txt
file1.txt

Use case 5: Display a tree of files, three levels deep

Code:

eza --long --tree --level=3

Motivation: When dealing with complex directory structures, visualizing the hierarchy of files and directories can provide a better understanding of the overall organization. The --tree option displays a tree-like representation of files, and the --level=3 option limits the depth of the tree to three levels.

Example output:

.
├── dir1
│   ├── file1.txt
│   ├── file2.txt
│   └── file3.txt
├── dir2
│   ├── file4.txt
│   ├── file5.txt
│   └── file6.txt
└── dir3
    ├── file7.txt
    ├── file8.txt
    └── file9.txt

Use case 6: List files sorted by modification date (oldest first)

Code:

eza --long --sort=modified

Motivation: When working with files that have different modification dates, it can be beneficial to list them in chronological order. The --sort=modified option sorts the files by modification date, with the oldest files appearing first.

Example output:

-rw-r--r--  username  groupname  1024  Jun 10 09:00  file1.txt
-rw-r--r--  username  groupname  512   Jun 15 17:30  file3.txt
-rw-r--r--  username  groupname  2048  Jun 12 13:45  .file2.txt

Use case 7: List files with their headers, icons, and Git statuses

Code:

eza --long --header --icons --git

Motivation: Adding additional information and visual enhancements to the file listing can make it more informative and visually appealing. The --header option includes a header row with column names, the --icons option displays icons representing file types, and the --git option shows Git statuses for version-controlled files.

Example output:

Permissions  Owner    Group     Size   Modified          Name                    Git Status
-rw-r--r--   username groupname 1024   Jun 10 09:00     file1.txt               ✗
-rw-r--r--   username groupname 2048   Jun 12 13:45     .file2.txt              ✓
-rw-r--r--   username groupname 512    Jun 15 17:30     file3.txt               ✗

Use case 8: Don’t list files mentioned in .gitignore

Code:

eza --git-ignore

Motivation: When working with a Git codebase, we might want to avoid listing files that are excluded by the .gitignore rules. The --git-ignore option filters out files that would be ignored by Git, providing a cleaner and more relevant file listing.

Example output:

file1.txt
file3.txt

Conclusion:

The eza command is a powerful and versatile replacement for the traditional ls command. It provides a range of options for customizing the file listing, including different formats, sorting orders, tree visualization, and Git integration. By understanding and utilizing these use cases, users can effectively manage and view files in a directory.

Related Posts

Clear Command (with examples)

Clear Command (with examples)

The “clear” command is used to clear the screen of the terminal.

Read More
How to use the command 'swaylock' (with examples)

How to use the command 'swaylock' (with examples)

The ‘swaylock’ command is a screen locking utility specifically designed for Wayland compositors.

Read More
How to use the command qrencode (with examples)

How to use the command qrencode (with examples)

QR codes are widely used in various industries for efficient and convenient data transfer.

Read More