How to colourise hidden files in `ls` file listings?
LS_COLORS
environmental variable lets you decide on colours for different file types for GNU coreutil's ls
command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.
Is there any (other) way you can make ls
listings show hidden files in a different colour?
ls filenames colors
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
LS_COLORS
environmental variable lets you decide on colours for different file types for GNU coreutil's ls
command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.
Is there any (other) way you can make ls
listings show hidden files in a different colour?
ls filenames colors
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
This answer has more than you ever wanted to know aboutLS_COLORS
. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.
– terdon♦
Sep 23 '14 at 14:52
1
@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named*.hide
for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.
– mikeserv
Sep 23 '14 at 15:43
add a comment |
LS_COLORS
environmental variable lets you decide on colours for different file types for GNU coreutil's ls
command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.
Is there any (other) way you can make ls
listings show hidden files in a different colour?
ls filenames colors
LS_COLORS
environmental variable lets you decide on colours for different file types for GNU coreutil's ls
command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.
Is there any (other) way you can make ls
listings show hidden files in a different colour?
ls filenames colors
ls filenames colors
edited Sep 2 '17 at 14:50
Kusalananda
126k16239393
126k16239393
asked Sep 23 '14 at 14:18
Johnny BaloneyJohnny Baloney
1764
1764
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
This answer has more than you ever wanted to know aboutLS_COLORS
. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.
– terdon♦
Sep 23 '14 at 14:52
1
@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named*.hide
for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.
– mikeserv
Sep 23 '14 at 15:43
add a comment |
This answer has more than you ever wanted to know aboutLS_COLORS
. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.
– terdon♦
Sep 23 '14 at 14:52
1
@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named*.hide
for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.
– mikeserv
Sep 23 '14 at 15:43
This answer has more than you ever wanted to know about
LS_COLORS
. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.– terdon♦
Sep 23 '14 at 14:52
This answer has more than you ever wanted to know about
LS_COLORS
. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.– terdon♦
Sep 23 '14 at 14:52
1
1
@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named
*.hide
for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.– mikeserv
Sep 23 '14 at 15:43
@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named
*.hide
for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.– mikeserv
Sep 23 '14 at 15:43
add a comment |
2 Answers
2
active
oldest
votes
If you're only sorting by name, this might help:
alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$
However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.
add a comment |
If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"
If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS
does not natively support colorizing hidden files as it seems.
I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS
environment variable as a pseudo extension, then execute ls -la
and after that run dircolors
to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.
Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.
for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)
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%2f157058%2fhow-to-colourise-hidden-files-in-ls-file-listings%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
If you're only sorting by name, this might help:
alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$
However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.
add a comment |
If you're only sorting by name, this might help:
alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$
However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.
add a comment |
If you're only sorting by name, this might help:
alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$
However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.
If you're only sorting by name, this might help:
alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$
However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.
answered Sep 7 '15 at 11:32
goofygoofy
1
1
add a comment |
add a comment |
If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"
If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS
does not natively support colorizing hidden files as it seems.
I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS
environment variable as a pseudo extension, then execute ls -la
and after that run dircolors
to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.
Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.
for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)
add a comment |
If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"
If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS
does not natively support colorizing hidden files as it seems.
I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS
environment variable as a pseudo extension, then execute ls -la
and after that run dircolors
to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.
Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.
for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)
add a comment |
If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"
If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS
does not natively support colorizing hidden files as it seems.
I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS
environment variable as a pseudo extension, then execute ls -la
and after that run dircolors
to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.
Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.
for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)
If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| .[^/|'.].*"
If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS
does not natively support colorizing hidden files as it seems.
I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS
environment variable as a pseudo extension, then execute ls -la
and after that run dircolors
to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.
Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.
for h in $(ls -A | grep "^."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)
edited Sep 23 '14 at 16:59
answered Sep 23 '14 at 16:16
Michael OslMichael Osl
1245
1245
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%2f157058%2fhow-to-colourise-hidden-files-in-ls-file-listings%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
This answer has more than you ever wanted to know about
LS_COLORS
. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.– terdon♦
Sep 23 '14 at 14:52
1
@terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named
*.hide
for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.– mikeserv
Sep 23 '14 at 15:43