g: An Elegant Alternative for the ls Command in Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

โ€œgโ€ is a free and open-source cross-platform alternative to the ls command, offering more advanced features than any other alternative, such as what โ€œexaโ€ can provide.

๐Ÿ˜ฎ
The developer named this tool โ€œgโ€ because itโ€™s written in Go, and โ€œgโ€ is simply easy to remember.

It offers various ways to customize output, multiple ways to layout the output, integrated support for Git, advanced sorting mechanisms, fuzzy path matching, and hyperlink support.

The โ€œgโ€ command option is very user-friendly, and the way I use it is by creating a custom โ€œgโ€ command with different options according to my requirements and creating an alias for it to later use it directly without retyping.

I cannot stress enough how excellent this tool is at fulfilling its purpose. Discover it yourself by reading the entire article to understand its features, installation steps, and usage guide.

Tutorial Details

Descriptiong: An Alternative to the ls Command
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityLinux, Windows, and macOS
Prerequisitesโ€“
Internet RequiredYes (for installation)

Features of g Tool

The following is a list of features that the โ€œgโ€ tool offers you:

  • Customize output by adding icons or colors to specific file types.
  • Select from grid, across, byline, zero, comma, table, JSON, Markdown, and tree layouts.
  • Directly view the file git-status/repo-status/repo-branch in your listings.
  • Enjoy highly customizable sorting options such as version-sort.
  • Available for Linux, Windows, and MacOS.
  • Benefit from fuzzy path matching similar to zoxide and fzf.
  • Open files/directories in the file explorer with just one click.

How to Install g Tool on Linux

The โ€œgโ€ tool can be installed in multiple ways; the one I recommend the most is by using the brew command in Linux or macOS.

$ brew install g-ls

If you prefer to install via Go, then run.

$ go install -ldflags="-s -w"  github.com/Equationzhao/g@latest

If you prefer installing via the โ€œ.debโ€ file on Debian and Ubuntu-based distributions, head to the release page, download the latest โ€œ.debโ€ file for Linux x86 architecture, navigate to the location, and execute the following command for installation.

$ sudo dpkg -i ./g_*_amd64.deb 

Users using an Arch-based distribution such as Manjaro and EndeavourOS can effortlessly install it using an AUR helper like Yay.

$ yay -S g-ls

Lastly, on Windows systems, you can install via the Scoop package manager.

$ scoop install https://raw.githubusercontent.com/Equationzhao/g/master/scoop/g.json

How to Use g Tool

The โ€œgโ€ command-line usage is pretty straightforward; for example, executing the command without any options gets the following output:

$ g

Output:

g command output

To customize output by adding an icon, use the โ€œ--iconsโ€ option with the โ€œgโ€ command.

๐Ÿ“
For an icon to appear in the output, your terminal must be configured with the Nerd font.
$ g --icons

Output:

g command output with icon

To display the output with absolute path, relative path, git status, or time, you can use the corresponding options: โ€œ--full-pathโ€œ, โ€œ--relative-to=baseโ€œ, โ€œ--gitโ€œ, and โ€œ--timeโ€œ.

$ g --full-path
$ g --relative-to=base
$ g --git
$ g --time

Output:

showing absolute, relative, git status, and time in the g command output

The default displaying style for time is โ€œDay.Month'Year Hour:Minuteโ€ (16.Novโ€™22 15:48), but it can be changed using the following style with the โ€œ--time-styleโ€ option.

  • iso
  • long-iso
  • full-iso
  • locale
$ g --time --time-style=iso
$ g --time --time-style=long-iso
$ g --time --time-style=full-iso
$ g --time --time-style=locale

Output:

changing time style in g command output

To print relative time, size, total size, block, and inode in the output, use the corresponding options: โ€œ--relative-timeโ€œ, โ€œ--total-size --sizeโ€œ, โ€œ--blockโ€œ, and โ€œ--inodeโ€œ.

$ g --relative-time
$ g --total-size --size
$ g --block
$ g --inode

Output:

displaying relative time, total size, block, and inode in g command

For displaying the owner and group names, files and directories permissions, mime type, and charset, use the corresponding options: โ€œ--owner --groupโ€œ, โ€œ--permโ€œ, โ€œ--mimeโ€œ, and โ€œ--charsetโ€œ.

$ g --owner --group
$ g --perm
$ g --mime
$ g --charset

Output:

printing owner and group name, permission, mime, charset in the g command output

To add links to files and directories so that when you click on them by holding the โ€œCtrlโ€ key in your terminal, they will open in their default launcher, use the โ€œ--linkโ€ option.

$ g --link

Output:

adding link to files and directories in g command output

Lastly, if you are wondering which command Iโ€™ve kept as an alias, then it is the following one:

$ g --table --table-style=unicode --total-size --size --long

Output:

g command in table format

There are tons of options that you can use with the โ€œgโ€ command. To get a glimpse of them, use the โ€œg --helpโ€ command. You may feel overwhelmed by the long list of options, so itโ€™s best to first check out its official documentation.

At last, if you have any questions or queries related to the topic, then do let me know in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.