Sort directories before files and underscore first with ls
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When using 'ls' i want to sort directories first and then all files AND sort directories/files with underscore first. Here is an example:
_folder2
folder2
_file2
file
I can sort directories first with
ls --group-directories-first --color --ignore=lost+found
but the underscore at the beginning is ignored. Sorting underscore at the beginning works with
ls -d _* [!_]*
but both doesn't work together. I have tried a lot of combinations of the two commands, nothings works as i want it to work. sometimes the color is lost (whats important for me) or i have the subfolders and files of the directores instead of the folder name.
Also LC_COLLATE=C and LC_LOCALE=C doesn't work.
linux directory ls filenames
add a comment |
When using 'ls' i want to sort directories first and then all files AND sort directories/files with underscore first. Here is an example:
_folder2
folder2
_file2
file
I can sort directories first with
ls --group-directories-first --color --ignore=lost+found
but the underscore at the beginning is ignored. Sorting underscore at the beginning works with
ls -d _* [!_]*
but both doesn't work together. I have tried a lot of combinations of the two commands, nothings works as i want it to work. sometimes the color is lost (whats important for me) or i have the subfolders and files of the directores instead of the folder name.
Also LC_COLLATE=C and LC_LOCALE=C doesn't work.
linux directory ls filenames
LC_COLLATE=C ls --group-directories-first
should work as long as theLC_ALL
env var is not set.LC_ALL=C ls --group-directories-first
would always work but cause the error messages to be output in English.
– Stéphane Chazelas
Mar 7 at 13:53
No luck here. Don't work with LC_COLLATE=C or LC_ALL=C.
– fmeier
Mar 7 at 17:14
Note that it's notLC_ALL=C; ls ...
, it'sLC_ALL=C ls ...
(orLC_ALL=C; export LC_ALL; ls
, but that would mean setting the locale toC
for every command, not justls
), or withcsh
/tcsh
/fish
env LC_ALL=C ls ...
– Stéphane Chazelas
Mar 7 at 17:28
ls -d _* [!_]*
wouldn't make a difference becausels
still sorts the file list. You'd needls -Ud -- _* [!_]*
(assuming GNUls
) to disable that sorting.
– Stéphane Chazelas
Mar 7 at 17:32
add a comment |
When using 'ls' i want to sort directories first and then all files AND sort directories/files with underscore first. Here is an example:
_folder2
folder2
_file2
file
I can sort directories first with
ls --group-directories-first --color --ignore=lost+found
but the underscore at the beginning is ignored. Sorting underscore at the beginning works with
ls -d _* [!_]*
but both doesn't work together. I have tried a lot of combinations of the two commands, nothings works as i want it to work. sometimes the color is lost (whats important for me) or i have the subfolders and files of the directores instead of the folder name.
Also LC_COLLATE=C and LC_LOCALE=C doesn't work.
linux directory ls filenames
When using 'ls' i want to sort directories first and then all files AND sort directories/files with underscore first. Here is an example:
_folder2
folder2
_file2
file
I can sort directories first with
ls --group-directories-first --color --ignore=lost+found
but the underscore at the beginning is ignored. Sorting underscore at the beginning works with
ls -d _* [!_]*
but both doesn't work together. I have tried a lot of combinations of the two commands, nothings works as i want it to work. sometimes the color is lost (whats important for me) or i have the subfolders and files of the directores instead of the folder name.
Also LC_COLLATE=C and LC_LOCALE=C doesn't work.
linux directory ls filenames
linux directory ls filenames
edited Mar 7 at 13:47
Jeff Schaller♦
44.6k1162145
44.6k1162145
asked Mar 7 at 13:32
fmeierfmeier
393
393
LC_COLLATE=C ls --group-directories-first
should work as long as theLC_ALL
env var is not set.LC_ALL=C ls --group-directories-first
would always work but cause the error messages to be output in English.
– Stéphane Chazelas
Mar 7 at 13:53
No luck here. Don't work with LC_COLLATE=C or LC_ALL=C.
– fmeier
Mar 7 at 17:14
Note that it's notLC_ALL=C; ls ...
, it'sLC_ALL=C ls ...
(orLC_ALL=C; export LC_ALL; ls
, but that would mean setting the locale toC
for every command, not justls
), or withcsh
/tcsh
/fish
env LC_ALL=C ls ...
– Stéphane Chazelas
Mar 7 at 17:28
ls -d _* [!_]*
wouldn't make a difference becausels
still sorts the file list. You'd needls -Ud -- _* [!_]*
(assuming GNUls
) to disable that sorting.
– Stéphane Chazelas
Mar 7 at 17:32
add a comment |
LC_COLLATE=C ls --group-directories-first
should work as long as theLC_ALL
env var is not set.LC_ALL=C ls --group-directories-first
would always work but cause the error messages to be output in English.
– Stéphane Chazelas
Mar 7 at 13:53
No luck here. Don't work with LC_COLLATE=C or LC_ALL=C.
– fmeier
Mar 7 at 17:14
Note that it's notLC_ALL=C; ls ...
, it'sLC_ALL=C ls ...
(orLC_ALL=C; export LC_ALL; ls
, but that would mean setting the locale toC
for every command, not justls
), or withcsh
/tcsh
/fish
env LC_ALL=C ls ...
– Stéphane Chazelas
Mar 7 at 17:28
ls -d _* [!_]*
wouldn't make a difference becausels
still sorts the file list. You'd needls -Ud -- _* [!_]*
(assuming GNUls
) to disable that sorting.
– Stéphane Chazelas
Mar 7 at 17:32
LC_COLLATE=C ls --group-directories-first
should work as long as the LC_ALL
env var is not set. LC_ALL=C ls --group-directories-first
would always work but cause the error messages to be output in English.– Stéphane Chazelas
Mar 7 at 13:53
LC_COLLATE=C ls --group-directories-first
should work as long as the LC_ALL
env var is not set. LC_ALL=C ls --group-directories-first
would always work but cause the error messages to be output in English.– Stéphane Chazelas
Mar 7 at 13:53
No luck here. Don't work with LC_COLLATE=C or LC_ALL=C.
– fmeier
Mar 7 at 17:14
No luck here. Don't work with LC_COLLATE=C or LC_ALL=C.
– fmeier
Mar 7 at 17:14
Note that it's not
LC_ALL=C; ls ...
, it's LC_ALL=C ls ...
(or LC_ALL=C; export LC_ALL; ls
, but that would mean setting the locale to C
for every command, not just ls
), or with csh
/tcsh
/fish
env LC_ALL=C ls ...
– Stéphane Chazelas
Mar 7 at 17:28
Note that it's not
LC_ALL=C; ls ...
, it's LC_ALL=C ls ...
(or LC_ALL=C; export LC_ALL; ls
, but that would mean setting the locale to C
for every command, not just ls
), or with csh
/tcsh
/fish
env LC_ALL=C ls ...
– Stéphane Chazelas
Mar 7 at 17:28
ls -d _* [!_]*
wouldn't make a difference because ls
still sorts the file list. You'd need ls -Ud -- _* [!_]*
(assuming GNU ls
) to disable that sorting.– Stéphane Chazelas
Mar 7 at 17:32
ls -d _* [!_]*
wouldn't make a difference because ls
still sorts the file list. You'd need ls -Ud -- _* [!_]*
(assuming GNU ls
) to disable that sorting.– Stéphane Chazelas
Mar 7 at 17:32
add a comment |
0
active
oldest
votes
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%2f504919%2fsort-directories-before-files-and-underscore-first-with-ls%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f504919%2fsort-directories-before-files-and-underscore-first-with-ls%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
LC_COLLATE=C ls --group-directories-first
should work as long as theLC_ALL
env var is not set.LC_ALL=C ls --group-directories-first
would always work but cause the error messages to be output in English.– Stéphane Chazelas
Mar 7 at 13:53
No luck here. Don't work with LC_COLLATE=C or LC_ALL=C.
– fmeier
Mar 7 at 17:14
Note that it's not
LC_ALL=C; ls ...
, it'sLC_ALL=C ls ...
(orLC_ALL=C; export LC_ALL; ls
, but that would mean setting the locale toC
for every command, not justls
), or withcsh
/tcsh
/fish
env LC_ALL=C ls ...
– Stéphane Chazelas
Mar 7 at 17:28
ls -d _* [!_]*
wouldn't make a difference becausels
still sorts the file list. You'd needls -Ud -- _* [!_]*
(assuming GNUls
) to disable that sorting.– Stéphane Chazelas
Mar 7 at 17:32