Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls --color=auto rendering directory color as file color #2343

Closed
evandrocoan opened this issue Jul 17, 2017 · 7 comments
Closed

ls --color=auto rendering directory color as file color #2343

evandrocoan opened this issue Jul 17, 2017 · 7 comments

Comments

@evandrocoan
Copy link

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.15063]

  • What you're doing and what's happening:
    I am doing ls --color=auto on a folder on the file system, and I am getting all the files within the same color set to the fi (files).

    This is a screenshot take from the Bash for Windows shell:

    image

    This are all the files, including the .bashrc settings I am using right now:

    1. https://github.com/evandrocoan/MyLinuxSettings/tree/1c6e119b022f7e226b086e8572bd2f88bb8868dd
    2. https://github.com/evandrocoan/MyLinuxSettings/blob/1c6e119b022f7e226b086e8572bd2f88bb8868dd/.bashrc#L392-L410

    In special, the files colors can be found are:

    LS_COLORS=$LS_COLORS':no=00'
    LS_COLORS=$LS_COLORS':di=36;01'
    LS_COLORS=$LS_COLORS':tw=33;01'
    LS_COLORS=$LS_COLORS':ow=33;01'
    LS_COLORS=$LS_COLORS':fi=93'
    LS_COLORS=$LS_COLORS':ln=00'
    LS_COLORS=$LS_COLORS':pi=00'
    LS_COLORS=$LS_COLORS':so=00'
    LS_COLORS=$LS_COLORS':ex=00'
    LS_COLORS=$LS_COLORS':bd=00'
    LS_COLORS=$LS_COLORS':cd=00'
    LS_COLORS=$LS_COLORS':or=00'
    LS_COLORS=$LS_COLORS':mi=00'
    LS_COLORS=$LS_COLORS':*.sh=31'
    LS_COLORS=$LS_COLORS':*.sh=31'
    LS_COLORS=$LS_COLORS':*.exe=31'
    LS_COLORS=$LS_COLORS':*.bat=31'
    LS_COLORS=$LS_COLORS':*.com=31'
    export LS_COLORS
    

    I am using the fix Bash for Windows colors are unreadable with default terminal theme vscode#7556 (comment), for windows colors, to get xterm colors correctly.

  • What's wrong / what should be happening instead:
    The colors on the Bash for Windows for directories are being ignored. On this screenshot take from the Cygwin Mintty Terminal shell, on the same folder, with the same color settings, we can see the folders being correctly rendered:

    image

  • Strace of the failing command, if applicable: (If <cmd> is failing, then run strace -o strace.txt -ff <cmd>, and post the strace.txt output here)

I ran strace -o strace.txt -ff ls, and this is the output:

execve("/bin/ls", ["ls"], [/* 20 vars */]) = 0
brk(NULL)                               = 0xe54000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fad07d20000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=27191, ...}) = 0
mmap(NULL, 27191, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fad07d19000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260Z\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=130224, ...}) = 0
mmap(NULL, 2234080, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fad077d0000
mprotect(0x7fad077ef000, 2093056, PROT_NONE) = 0
mmap(0x7fad079ee000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e000) = 0x7fad079ee000
mmap(0x7fad079f0000, 5856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fad079f0000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fad07400000
mprotect(0x7fad075c0000, 2097152, PROT_NONE) = 0
mmap(0x7fad077c0000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7fad077c0000
mmap(0x7fad077c6000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fad077c6000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpcre.so.3", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000\25\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=456632, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fad07d10000
mmap(NULL, 2552072, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fad07190000
mprotect(0x7fad071fe000, 2097152, PROT_NONE) = 0
mmap(0x7fad073fe000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6e000) = 0x7fad073fe000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\r\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14608, ...}) = 0
mmap(NULL, 2109680, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fad06f80000
mprotect(0x7fad06f83000, 2093056, PROT_NONE) = 0
mmap(0x7fad07182000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7fad07182000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260`\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=138696, ...}) = 0
mmap(NULL, 2212904, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fad06d60000
mprotect(0x7fad06d78000, 2093056, PROT_NONE) = 0
mmap(0x7fad06f77000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7fad06f77000
mmap(0x7fad06f79000, 13352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fad06f79000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fad07d00000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fad07cf0000
arch_prctl(ARCH_SET_FS, 0x7fad07cf0800) = 0
mprotect(0x7fad077c0000, 16384, PROT_READ) = 0
mprotect(0x7fad06f77000, 4096, PROT_READ) = 0
mprotect(0x7fad07182000, 4096, PROT_READ) = 0
mprotect(0x7fad073fe000, 4096, PROT_READ) = 0
mprotect(0x7fad079ee000, 4096, PROT_READ) = 0
mprotect(0x61d000, 4096, PROT_READ)     = 0
mprotect(0x7fad07c25000, 4096, PROT_READ) = 0
munmap(0x7fad07d19000, 27191)           = 0
set_tid_address(0x7fad07cf0ad0)         = 267
set_robust_list(0x7fad07cf0ae0, 24)     = 0
rt_sigaction(SIGRTMIN, {0x7fad06d65b50, [], SA_RESTORER|SA_SIGINFO, 0x7fad06d71390}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7fad06d65be0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7fad06d71390}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=8192*1024}) = 0
statfs("/sys/fs/selinux", 0x7fffeabaf3f0) = -1 ENOENT (No such file or directory)
statfs("/selinux", 0x7fffeabaf3f0)      = -1 ENOENT (No such file or directory)
brk(NULL)                               = 0xe54000
brk(0xe75000)                           = 0xe75000
open("/proc/filesystems", O_RDONLY)     = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "nodev      sysfs\nnodev      root"..., 4096) = 367
read(3, "", 4096)                       = 0
close(3)                                = 0
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1668976, ...}) = 0
mmap(NULL, 1668976, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fad07a8d000
close(3)                                = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=37, ws_col=64, ws_xpixel=0, ws_ypixel=0}) = 0
open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
getdents(3, /* d_reclen < sizeof(struct dirent) *//* 1 entries */, 32768) = 733
getdents(3, /* 0 entries */, 32768)     = 0
close(3)                                = 0
fstat(1, {st_mode=S_IFCHR|0660, st_rdev=makedev(4, 2), ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(1, "Cache\t\t    Settings\n", 20) = 20
write(1, "Index\t\t    (Soft) Simple IDE Pac"..., 42) = 42
write(1, "Installed Packages  strace.txt.2"..., 35) = 35
write(1, "Lib\t\t    SublimeStudio.bbcode\n", 30) = 30
write(1, "LICENSE\t\t    Sublime Text Studio"..., 49) = 49
write(1, "Local\t\t    Sublime Text Studio.s"..., 49) = 49
write(1, "Packages\t    Utilities\n", 23) = 23
write(1, "README.MD\n", 10)             = 10
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++



Related issues:

  1. Dark blue text on black background unreadable #930 Dark blue text on black background unreadable
  2. Bash for Windows colors are unreadable with default terminal theme vscode#7556 Bash for Windows colors are unreadable with default terminal theme
@evandrocoan evandrocoan changed the title ls --color=auto rendering directory colors as file color ls --color=auto rendering directory color as file color Jul 17, 2017
@zadjii-msft
Copy link
Member

@evandrocoan could you post the output of ls -lA --color for both the WSL directory and the cygwin directory?

@evandrocoan
Copy link
Author

Sure,

Cygwin Mintty
image

Bash on Windows
image

@zadjii-msft
Copy link
Member

@evandrocoan Yep, just as I thought.
As you can see, the cygwin directories generally have permissions of 705 (drwx---r-x), while the WSL dirs are 777 (drwxrwxrwx).

In this screenshot you can see the before and after of me changing the permissions of a dir from 777 to 705. The left console has the directory as it was initially created, the right is after I changed it to 705.
(It's not the same colors as your own instance, but the concept is the same)
image

@evandrocoan
Copy link
Author

evandrocoan commented Jul 17, 2017

This is related to the issue:

  1. chmod doesn't work? #81 chmod doesn't work?

So the Ubuntu ls is applying the colors to the folders based on their write access 705?

This would mean that for Windows, the ls should use something more concrete to determine whether it is a directory. Perhaps a update on the Ubuntu ls command to not use the 705 criteria to highlight folders, therefore propagating this fix for the Windows Subsystem for Linux?

@zadjii-msft
Copy link
Member

It's possible. It looks to me like that dir has a .lnk in it, so I'd assume it's under your /mnt/c.

ls does color files differently based on the permissions, though I'd say it'd be highly unlikely that you could change ls to add Windows-specific behavior.

Looking at this and this, I'd say that if you changed all of ow, tw, and di to be the same color that you want directories to look.

Change

LS_COLORS=$LS_COLORS':di=36;01'
LS_COLORS=$LS_COLORS':tw=33;01'
LS_COLORS=$LS_COLORS':ow=33;01'

to

LS_COLORS=$LS_COLORS':di=36;01'
LS_COLORS=$LS_COLORS':tw=36;01'
LS_COLORS=$LS_COLORS':ow=36;01'

@evandrocoan
Copy link
Author

Thanks! I changed the colors, now they are correctly displayed.

Basically my colors are wrong not displaying correctly the attributes and directories.

@evanleonard
Copy link

Appears the general underlying issue is WSL not seeing the permissions properly. Here's a fix I found: https://www.turek.dev/posts/fix-wsl-file-permissions/

evandrocoan added a commit to evandrocoan/dotfiles that referenced this issue Jun 28, 2021
perXautomatik pushed a commit to perXautomatik/dotfiles that referenced this issue Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants