coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

'ls -l' in symbolic link directory on Windows lists the link itself instead of the target directory contents

Open chengwu26 opened this issue 8 months ago • 3 comments

​Description​​

When using ls -l inside a symbolic link directory (created as a symlink to another directory) on ​​Windows​​, the command only displays the symbolic link itself rather than the contents of the target directory. This behavior does NOT occur when running ls without the -l flag.

# ls -l
total 0
dr-xr-xr-x 1 somebody somegroup 0 May  1 22:30 apps
drwxrwxrwx 1 somebody somegroup 0 Mar 23 14:15 media
lr-xr-xr-x 1 somebody somegroup 0 Mar 23 14:36 pkgs -> 'E:\pkgs'
lr-xr-xr-x 1 somebody somegroup 0 May  1 23:21 scoop -> '.\apps\scoop'

# cd scoop && ls -l
lr-xr-xr-x 1 somebody somegroup 0 May  1 23:21 . -> '.\apps\scoop'

# ls
apps  buckets  modules  persist  scoop.db  shims  workspace

​Environment​​

OS infomation

版本 Windows 11 专业版 版本号 24H2 安装日期 ‎2025/‎2/‎16 操作系统版本 26100.3915 体验 Windows 功能体验包 1000.26100.83.0

ls version

ls 0.0.30

chengwu26 avatar May 02 '25 07:05 chengwu26

commit 2c130ae7 changed the behavior of -l option, though can't find why.

zhw2101024 avatar May 04 '25 10:05 zhw2101024

update: i posted this in the wrong issue


it has the same behavior on redox os

BarryLhm avatar Aug 11 '25 11:08 BarryLhm

Just to clarify my own understanding, on Unix the behaviour is to list the link if a path to a directory symlink is given. However, if the path is . then it lists the directory instead of showing the link.

Presumably the reason for this is that on unix the current directory is actually being resolved to the real directory before ls interacts with it whereas on Windows it's being used exactly as set. One possible workaround would be to special case the handling of . to always list the directory but I don't know if that would have any unwanted effects.

ChrisDenton avatar Aug 11 '25 11:08 ChrisDenton