Inconsistent color output from `ls` command
Clash Royale CLAN TAG#URR8PPP
I teach an Intro to UNIX/Linux course at a local college and one of my students asked the following question:
Why are some of the files in my directory colored white and others are gray? Are the white ones the ones I created today and the gray are existing files?
As I looked into this I first thought the answer would be in the LS_COLORS
variable, but further investigation revealed that the color listings were different when using the -l
switch versus the -al
switch with the ls
command. See the following screen shots:
Using ls -l
the file named '3' shows as white but using the -al
switch the same file shows a gray.
Is this a bug in ls or does anyone know why this is happening?
linux command-line ls colors
add a comment |
I teach an Intro to UNIX/Linux course at a local college and one of my students asked the following question:
Why are some of the files in my directory colored white and others are gray? Are the white ones the ones I created today and the gray are existing files?
As I looked into this I first thought the answer would be in the LS_COLORS
variable, but further investigation revealed that the color listings were different when using the -l
switch versus the -al
switch with the ls
command. See the following screen shots:
Using ls -l
the file named '3' shows as white but using the -al
switch the same file shows a gray.
Is this a bug in ls or does anyone know why this is happening?
linux command-line ls colors
Wrt your question title: such coloring has nothing to do with thels
command itself.
– Drew
Feb 11 at 2:32
FWIW, the closest you can get to this by messing with LS_COLORS isLS_COLORS='rs=0;1' ls -l
, but it looks very different.
– wjandrea
Feb 11 at 5:23
4
@Drew You only know that after investigating the problem. Obviouslyls
can change the color of its output.
– pipe
Feb 11 at 10:50
@pipe: Nah, I know that from long before there was color. It need not provide color, even if recent versions ofls
can provide color. ;-)
– Drew
Feb 11 at 14:25
add a comment |
I teach an Intro to UNIX/Linux course at a local college and one of my students asked the following question:
Why are some of the files in my directory colored white and others are gray? Are the white ones the ones I created today and the gray are existing files?
As I looked into this I first thought the answer would be in the LS_COLORS
variable, but further investigation revealed that the color listings were different when using the -l
switch versus the -al
switch with the ls
command. See the following screen shots:
Using ls -l
the file named '3' shows as white but using the -al
switch the same file shows a gray.
Is this a bug in ls or does anyone know why this is happening?
linux command-line ls colors
I teach an Intro to UNIX/Linux course at a local college and one of my students asked the following question:
Why are some of the files in my directory colored white and others are gray? Are the white ones the ones I created today and the gray are existing files?
As I looked into this I first thought the answer would be in the LS_COLORS
variable, but further investigation revealed that the color listings were different when using the -l
switch versus the -al
switch with the ls
command. See the following screen shots:
Using ls -l
the file named '3' shows as white but using the -al
switch the same file shows a gray.
Is this a bug in ls or does anyone know why this is happening?
linux command-line ls colors
linux command-line ls colors
edited 2 days ago
fra-san
1,8291518
1,8291518
asked Feb 11 at 0:25
Bill RBill R
14615
14615
Wrt your question title: such coloring has nothing to do with thels
command itself.
– Drew
Feb 11 at 2:32
FWIW, the closest you can get to this by messing with LS_COLORS isLS_COLORS='rs=0;1' ls -l
, but it looks very different.
– wjandrea
Feb 11 at 5:23
4
@Drew You only know that after investigating the problem. Obviouslyls
can change the color of its output.
– pipe
Feb 11 at 10:50
@pipe: Nah, I know that from long before there was color. It need not provide color, even if recent versions ofls
can provide color. ;-)
– Drew
Feb 11 at 14:25
add a comment |
Wrt your question title: such coloring has nothing to do with thels
command itself.
– Drew
Feb 11 at 2:32
FWIW, the closest you can get to this by messing with LS_COLORS isLS_COLORS='rs=0;1' ls -l
, but it looks very different.
– wjandrea
Feb 11 at 5:23
4
@Drew You only know that after investigating the problem. Obviouslyls
can change the color of its output.
– pipe
Feb 11 at 10:50
@pipe: Nah, I know that from long before there was color. It need not provide color, even if recent versions ofls
can provide color. ;-)
– Drew
Feb 11 at 14:25
Wrt your question title: such coloring has nothing to do with the
ls
command itself.– Drew
Feb 11 at 2:32
Wrt your question title: such coloring has nothing to do with the
ls
command itself.– Drew
Feb 11 at 2:32
FWIW, the closest you can get to this by messing with LS_COLORS is
LS_COLORS='rs=0;1' ls -l
, but it looks very different.– wjandrea
Feb 11 at 5:23
FWIW, the closest you can get to this by messing with LS_COLORS is
LS_COLORS='rs=0;1' ls -l
, but it looks very different.– wjandrea
Feb 11 at 5:23
4
4
@Drew You only know that after investigating the problem. Obviously
ls
can change the color of its output.– pipe
Feb 11 at 10:50
@Drew You only know that after investigating the problem. Obviously
ls
can change the color of its output.– pipe
Feb 11 at 10:50
@pipe: Nah, I know that from long before there was color. It need not provide color, even if recent versions of
ls
can provide color. ;-)– Drew
Feb 11 at 14:25
@pipe: Nah, I know that from long before there was color. It need not provide color, even if recent versions of
ls
can provide color. ;-)– Drew
Feb 11 at 14:25
add a comment |
2 Answers
2
active
oldest
votes
It looks as if your prompt-string ($PS1
) is setting the bold attribute on characters to make the colors nicer, and not unsetting it. The output from ls
doesn't know about this, and does unset bold. So after the first color output of ls
, everything looks dimmer.
1
Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!
– Bill R
Feb 11 at 19:09
3
You can mark it accepted, then.
– Thomas Dickey
Feb 12 at 0:13
add a comment |
The whole output of ls will be printed in the last active color. If ls
is called without color:
$ printf 'e[0;31m color testn'; /bin/ls
color test
filea fileb filec filed filee filef fileg fileh
will print the list of files in red.
Or, if there is no color change needed for ls, the last color will remain:
$ mkdir t1; cd t1; touch filea..h
$ printf 'e[0;31m color testn'; /bin/ls --color -l
color test
total 0
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
Still, all in red.
But, as soon as ls
needs to set a color (and then reset colors to the default used by the console), the color used from then on will be the console default.
$ printf 'e[0;31m color testn'; /bin/ls --color -la
color test
total 8
drwxr-xr-x 2 user user 4096 Feb 23 01:16 .
drwxr-x--- 7 user user 4096 Feb 23 01:15 ..
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
With the first three lines (up to the blue dot) printed in red.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499840%2finconsistent-color-output-from-ls-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It looks as if your prompt-string ($PS1
) is setting the bold attribute on characters to make the colors nicer, and not unsetting it. The output from ls
doesn't know about this, and does unset bold. So after the first color output of ls
, everything looks dimmer.
1
Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!
– Bill R
Feb 11 at 19:09
3
You can mark it accepted, then.
– Thomas Dickey
Feb 12 at 0:13
add a comment |
It looks as if your prompt-string ($PS1
) is setting the bold attribute on characters to make the colors nicer, and not unsetting it. The output from ls
doesn't know about this, and does unset bold. So after the first color output of ls
, everything looks dimmer.
1
Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!
– Bill R
Feb 11 at 19:09
3
You can mark it accepted, then.
– Thomas Dickey
Feb 12 at 0:13
add a comment |
It looks as if your prompt-string ($PS1
) is setting the bold attribute on characters to make the colors nicer, and not unsetting it. The output from ls
doesn't know about this, and does unset bold. So after the first color output of ls
, everything looks dimmer.
It looks as if your prompt-string ($PS1
) is setting the bold attribute on characters to make the colors nicer, and not unsetting it. The output from ls
doesn't know about this, and does unset bold. So after the first color output of ls
, everything looks dimmer.
answered Feb 11 at 0:48
Thomas DickeyThomas Dickey
53.7k5103175
53.7k5103175
1
Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!
– Bill R
Feb 11 at 19:09
3
You can mark it accepted, then.
– Thomas Dickey
Feb 12 at 0:13
add a comment |
1
Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!
– Bill R
Feb 11 at 19:09
3
You can mark it accepted, then.
– Thomas Dickey
Feb 12 at 0:13
1
1
Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!
– Bill R
Feb 11 at 19:09
Yep, that was it. Last color change in $PS1 set bold+white (1;37) -- Thanks!
– Bill R
Feb 11 at 19:09
3
3
You can mark it accepted, then.
– Thomas Dickey
Feb 12 at 0:13
You can mark it accepted, then.
– Thomas Dickey
Feb 12 at 0:13
add a comment |
The whole output of ls will be printed in the last active color. If ls
is called without color:
$ printf 'e[0;31m color testn'; /bin/ls
color test
filea fileb filec filed filee filef fileg fileh
will print the list of files in red.
Or, if there is no color change needed for ls, the last color will remain:
$ mkdir t1; cd t1; touch filea..h
$ printf 'e[0;31m color testn'; /bin/ls --color -l
color test
total 0
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
Still, all in red.
But, as soon as ls
needs to set a color (and then reset colors to the default used by the console), the color used from then on will be the console default.
$ printf 'e[0;31m color testn'; /bin/ls --color -la
color test
total 8
drwxr-xr-x 2 user user 4096 Feb 23 01:16 .
drwxr-x--- 7 user user 4096 Feb 23 01:15 ..
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
With the first three lines (up to the blue dot) printed in red.
add a comment |
The whole output of ls will be printed in the last active color. If ls
is called without color:
$ printf 'e[0;31m color testn'; /bin/ls
color test
filea fileb filec filed filee filef fileg fileh
will print the list of files in red.
Or, if there is no color change needed for ls, the last color will remain:
$ mkdir t1; cd t1; touch filea..h
$ printf 'e[0;31m color testn'; /bin/ls --color -l
color test
total 0
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
Still, all in red.
But, as soon as ls
needs to set a color (and then reset colors to the default used by the console), the color used from then on will be the console default.
$ printf 'e[0;31m color testn'; /bin/ls --color -la
color test
total 8
drwxr-xr-x 2 user user 4096 Feb 23 01:16 .
drwxr-x--- 7 user user 4096 Feb 23 01:15 ..
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
With the first three lines (up to the blue dot) printed in red.
add a comment |
The whole output of ls will be printed in the last active color. If ls
is called without color:
$ printf 'e[0;31m color testn'; /bin/ls
color test
filea fileb filec filed filee filef fileg fileh
will print the list of files in red.
Or, if there is no color change needed for ls, the last color will remain:
$ mkdir t1; cd t1; touch filea..h
$ printf 'e[0;31m color testn'; /bin/ls --color -l
color test
total 0
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
Still, all in red.
But, as soon as ls
needs to set a color (and then reset colors to the default used by the console), the color used from then on will be the console default.
$ printf 'e[0;31m color testn'; /bin/ls --color -la
color test
total 8
drwxr-xr-x 2 user user 4096 Feb 23 01:16 .
drwxr-x--- 7 user user 4096 Feb 23 01:15 ..
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
With the first three lines (up to the blue dot) printed in red.
The whole output of ls will be printed in the last active color. If ls
is called without color:
$ printf 'e[0;31m color testn'; /bin/ls
color test
filea fileb filec filed filee filef fileg fileh
will print the list of files in red.
Or, if there is no color change needed for ls, the last color will remain:
$ mkdir t1; cd t1; touch filea..h
$ printf 'e[0;31m color testn'; /bin/ls --color -l
color test
total 0
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
Still, all in red.
But, as soon as ls
needs to set a color (and then reset colors to the default used by the console), the color used from then on will be the console default.
$ printf 'e[0;31m color testn'; /bin/ls --color -la
color test
total 8
drwxr-xr-x 2 user user 4096 Feb 23 01:16 .
drwxr-x--- 7 user user 4096 Feb 23 01:15 ..
-rw-r--r-- 1 user user 0 Feb 23 01:16 filea
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileb
-rw-r--r-- 1 user user 0 Feb 23 01:16 filec
-rw-r--r-- 1 user user 0 Feb 23 01:16 filed
-rw-r--r-- 1 user user 0 Feb 23 01:16 filee
-rw-r--r-- 1 user user 0 Feb 23 01:16 filef
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileg
-rw-r--r-- 1 user user 0 Feb 23 01:16 fileh
With the first three lines (up to the blue dot) printed in red.
answered Feb 23 at 5:28
IsaacIsaac
12k11852
12k11852
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499840%2finconsistent-color-output-from-ls-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Wrt your question title: such coloring has nothing to do with the
ls
command itself.– Drew
Feb 11 at 2:32
FWIW, the closest you can get to this by messing with LS_COLORS is
LS_COLORS='rs=0;1' ls -l
, but it looks very different.– wjandrea
Feb 11 at 5:23
4
@Drew You only know that after investigating the problem. Obviously
ls
can change the color of its output.– pipe
Feb 11 at 10:50
@pipe: Nah, I know that from long before there was color. It need not provide color, even if recent versions of
ls
can provide color. ;-)– Drew
Feb 11 at 14:25