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

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

The ’exa’ command is a modern replacement for the ’ls’ command, used to list directory contents. It provides a more user-friendly and feature-rich interface compared to ’ls'.

Use case 1: List files one per line

Code:

exa --oneline

Motivation: This use case is helpful when you want a simple and compact list of files, with each file displayed on a separate line.

Explanation:

  • --oneline: This option displays each file on a single line, making it easier to read.

Example output:

file1.txt
file2.jpg
file3.py

Use case 2: List all files, including hidden files

Code:

exa --all

Motivation: Sometimes, you may want to see all the files in a directory, including hidden files that start with a dot (e.g., .gitignore).

Explanation:

  • --all: This option displays all files, including hidden files.

Example output:

file1.txt
file2.jpg
.hidden_file

Use case 3: Long format list of all files

Code:

exa --long --all

Motivation: This use case is beneficial when you need detailed information about the files, such as permissions, ownership, size, and modification date.

Explanation:

  • --long: This option displays the files in a long format, providing additional information.
  • --all: This option displays all files, including hidden files.

Example output:

-rw-r--r--  1 user  group  1024 Oct 25 09:30 file1.txt
-rw-r--r--  1 user  group  2048 Oct 24 14:18 file2.jpg

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

Code:

exa --reverse --sort=size

Motivation: When dealing with large files, it can be helpful to list them in descending order based on their sizes, with the largest files at the top.

Explanation:

  • --reverse: This option reverses the order of the file listing.
  • --sort=size: This option sorts the files based on their sizes.

Example output:

file3.mp4
file2.mov
file1.avi

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

Code:

exa --long --tree --level=3

Motivation: This use case is useful when you want to visualize the directory structure and explore the files and folders within it.

Explanation:

  • --long: This option displays the files in a long format, providing additional information.
  • --tree: This option displays the directory structure as a tree.
  • --level=3: This option limits the depth of the tree to three levels.

Example output:

.
├── folder1
│   ├── file1.txt
│   ├── file2.jpg
│   └── folder2
└── folder3

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

Code:

exa --long --sort=modified

Motivation: Sorting files by modification date can be useful when you want to identify the recently modified files or track changes in a folder over time.

Explanation:

  • --long: This option displays the files in a long format, providing additional information.
  • --sort=modified: This option sorts the files based on their modification dates.

Example output:

Oct 20 08:45 file1.txt
Oct 22 14:18 file2.jpg
Oct 25 09:30 file3.py

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

Code:

exa --long --header --icons --git

Motivation: When working with Git repositories, this use case allows you to list the files along with their headers, icons representing file types, and Git statuses.

Explanation:

  • --long: This option displays the files in a long format, providing additional information.
  • --header: This option displays a header row at the top of the file listing.
  • --icons: This option displays icons representing file types.
  • --git: This option displays Git status information for each file.

Example output:

Permissions User  Group  Size Modified              Icon  Git Status  Name
-rw-r--r--   user  group  1024 Oct 25 09:30      📄                file1.txt
-rw-r--r--   user  group  2048 Oct 24 14:18      📷                file2.jpg

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

Code:

exa --git-ignore

Motivation: This use case is handy when you want to exclude files mentioned in the .gitignore file from the file listing.

Explanation:

  • --git-ignore: This option excludes files mentioned in the .gitignore file from the listing.

Example output:

file1.txt
file2.jpg

Conclusion:

The ’exa’ command is a feature-rich replacement for the ’ls’ command. It provides various options to customize the file listing output, making it more versatile and user-friendly. Whether you need a simple file listing or detailed information, ’exa’ has you covered.

Related Posts

How to use the command xsltproc (with examples)

How to use the command xsltproc (with examples)

XSLT is a language used for transforming XML documents into new formats.

Read More
Managing Power Profiles with powerprofilesctl (with examples)

Managing Power Profiles with powerprofilesctl (with examples)

Managing power profiles on your system can greatly assist in optimizing power consumption and extending battery life.

Read More
How to use the command cs complete-dep (with examples)

How to use the command cs complete-dep (with examples)

The command cs complete-dep is a Coursier command that allows users to search for libraries without directly searching on the web.

Read More