Clean lsd -l output with Icons but without Symlink Targets

2 min read Original article ↗

A robust one-liner and shell function to use lsd (LSDeluxe) with all its NerdFont-powered visual glory — while hiding symlink targets (⇒ path).

It preserves icons, formatting, and works beautifully in scripts and aliases.

Perfect for minimalist terminal users who love beauty without unnecessary clutter.


🧠 What It Does

Step Purpose
script -q -c "lsd -l" Runs lsd in a pseudo-terminal (PTY) to preserve icons and formatting that would otherwise be lost in a pipe.
perl -pe 's/\r/\n/g; s/ ⇒ .*//' Converts terminal line-overwrites into proper newlines, and strips symlink targets while preserving icons.
awk '!seen[$0]++' Removes duplicate lines caused by the overwrite behavior of PTYs.

✅ One-Liner

script -q -c "lsd -l --color=always" /dev/null \
  | perl -pe 's/\r/\n/g; s/ ⇒ .*//' \
  | awk '!seen[$0]++'

🧰 Shell Function

Add this to your ~/.bashrc, ~/.zshrc, or equivalent shell config:

dls() {
  script -q -c "lsd -l --color=always" /dev/null \
    | perl -pe 's/\r/\n/g; s/ ⇒ .*//' \
    | awk '!seen[$0]++'
}

Then just run:

Enjoy a clean, symlink-target-free, icon-rich ls output.


🖥️ Requirements

  • lsd installed (dnf install lsd or via your package manager)
  • perl
  • awk
  • script (from util-linux, usually installed by default)
  • NerdFont-compatible terminal (for full icon goodness)

✨ Credit

Discovered and refined by Michael Longval and ChatGPT (aka Peregrin).
It took ANSI necromancy, regex diplomacy, and a brave stand against the tyranny of \r.