Sorting files and folders with underscore at the beginning












2














I use an underscore at the beginning of file and folder names to mark them as something "special". But this sorting doesn't work for the most programs under Linux. I tried LC_COLLATE=C ls and other locales but the results are something strange. Let's say I have these folders:



2
A
_F
G
K
S
x4


This is the sort order of ls. When I use LC_COLLATE=C ls, I have this:



2
A
G
K
S
_F
x4


I have this under Xubuntu 18.04 using the xfce-terminal-emulator on 2 machines.



What is wrong here?










share|improve this question




















  • 3




    How do you expect them to sort?
    – George Udosen
    Dec 22 '18 at 7:30






  • 1




    @GeorgeUdosen I think OP wants the special characters to placed first/ higher in list.
    – Sourav Ghosh
    Dec 22 '18 at 7:32








  • 1




    Even at that we are still guessing as OPs results could be any thing!
    – George Udosen
    Dec 22 '18 at 7:41










  • i want to sort the files/folders like dolphin (kde file manager) sorts them. all folder first, the all files. folders with underscore at top of al folders, the same with files with underscore at the beginning.
    – fmeier
    Jan 1 at 17:23
















2














I use an underscore at the beginning of file and folder names to mark them as something "special". But this sorting doesn't work for the most programs under Linux. I tried LC_COLLATE=C ls and other locales but the results are something strange. Let's say I have these folders:



2
A
_F
G
K
S
x4


This is the sort order of ls. When I use LC_COLLATE=C ls, I have this:



2
A
G
K
S
_F
x4


I have this under Xubuntu 18.04 using the xfce-terminal-emulator on 2 machines.



What is wrong here?










share|improve this question




















  • 3




    How do you expect them to sort?
    – George Udosen
    Dec 22 '18 at 7:30






  • 1




    @GeorgeUdosen I think OP wants the special characters to placed first/ higher in list.
    – Sourav Ghosh
    Dec 22 '18 at 7:32








  • 1




    Even at that we are still guessing as OPs results could be any thing!
    – George Udosen
    Dec 22 '18 at 7:41










  • i want to sort the files/folders like dolphin (kde file manager) sorts them. all folder first, the all files. folders with underscore at top of al folders, the same with files with underscore at the beginning.
    – fmeier
    Jan 1 at 17:23














2












2








2







I use an underscore at the beginning of file and folder names to mark them as something "special". But this sorting doesn't work for the most programs under Linux. I tried LC_COLLATE=C ls and other locales but the results are something strange. Let's say I have these folders:



2
A
_F
G
K
S
x4


This is the sort order of ls. When I use LC_COLLATE=C ls, I have this:



2
A
G
K
S
_F
x4


I have this under Xubuntu 18.04 using the xfce-terminal-emulator on 2 machines.



What is wrong here?










share|improve this question















I use an underscore at the beginning of file and folder names to mark them as something "special". But this sorting doesn't work for the most programs under Linux. I tried LC_COLLATE=C ls and other locales but the results are something strange. Let's say I have these folders:



2
A
_F
G
K
S
x4


This is the sort order of ls. When I use LC_COLLATE=C ls, I have this:



2
A
G
K
S
_F
x4


I have this under Xubuntu 18.04 using the xfce-terminal-emulator on 2 machines.



What is wrong here?







command-line xubuntu locale ls






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 22 '18 at 8:57









Zanna

50.2k13133241




50.2k13133241










asked Dec 22 '18 at 7:25









fmeier

111




111








  • 3




    How do you expect them to sort?
    – George Udosen
    Dec 22 '18 at 7:30






  • 1




    @GeorgeUdosen I think OP wants the special characters to placed first/ higher in list.
    – Sourav Ghosh
    Dec 22 '18 at 7:32








  • 1




    Even at that we are still guessing as OPs results could be any thing!
    – George Udosen
    Dec 22 '18 at 7:41










  • i want to sort the files/folders like dolphin (kde file manager) sorts them. all folder first, the all files. folders with underscore at top of al folders, the same with files with underscore at the beginning.
    – fmeier
    Jan 1 at 17:23














  • 3




    How do you expect them to sort?
    – George Udosen
    Dec 22 '18 at 7:30






  • 1




    @GeorgeUdosen I think OP wants the special characters to placed first/ higher in list.
    – Sourav Ghosh
    Dec 22 '18 at 7:32








  • 1




    Even at that we are still guessing as OPs results could be any thing!
    – George Udosen
    Dec 22 '18 at 7:41










  • i want to sort the files/folders like dolphin (kde file manager) sorts them. all folder first, the all files. folders with underscore at top of al folders, the same with files with underscore at the beginning.
    – fmeier
    Jan 1 at 17:23








3




3




How do you expect them to sort?
– George Udosen
Dec 22 '18 at 7:30




How do you expect them to sort?
– George Udosen
Dec 22 '18 at 7:30




1




1




@GeorgeUdosen I think OP wants the special characters to placed first/ higher in list.
– Sourav Ghosh
Dec 22 '18 at 7:32






@GeorgeUdosen I think OP wants the special characters to placed first/ higher in list.
– Sourav Ghosh
Dec 22 '18 at 7:32






1




1




Even at that we are still guessing as OPs results could be any thing!
– George Udosen
Dec 22 '18 at 7:41




Even at that we are still guessing as OPs results could be any thing!
– George Udosen
Dec 22 '18 at 7:41












i want to sort the files/folders like dolphin (kde file manager) sorts them. all folder first, the all files. folders with underscore at top of al folders, the same with files with underscore at the beginning.
– fmeier
Jan 1 at 17:23




i want to sort the files/folders like dolphin (kde file manager) sorts them. all folder first, the all files. folders with underscore at top of al folders, the same with files with underscore at the beginning.
– fmeier
Jan 1 at 17:23










2 Answers
2






active

oldest

votes


















1














You can sort files with leading underscores to the end with --sort=version or -v which is equivalent to sort -V (natural version sort) (which is most useful for sorting files with numbers).



$ ls -v1
2
A
G
K
S
x4
_F


Details on version sorting are in info ls... note that:



‘LC_COLLATE’ is ignored, which means ‘ls -v’ and ‘sort -V’ will
sort non-numeric prefixes as if the ‘LC_COLLATE’ locale category
was set to ‘C’.


Perhaps this is adequate for your purpose.






share|improve this answer

















  • 1




    Just to mention that Dolphin (Kubuntu's file manager) sorts them, from top to bottom, like this: _F, 2, A, G, K, S, x4. It's using something called "Natural" sorting. I have a question on it here: askubuntu.com/questions/1040499/…
    – DK Bose
    Dec 22 '18 at 9:57






  • 1




    Cleaned up my answer.
    – DK Bose
    Dec 23 '18 at 6:52



















1














@Zanna's answer provides one solution. Another solution is this:



$ ls -lfr -1 _* [!_]*
_F
2
A
G
K
S
x4





share|improve this answer























  • This shows also all sub folders and files that are stored in the folder.
    – fmeier
    Jan 1 at 17:24











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1103748%2fsorting-files-and-folders-with-underscore-at-the-beginning%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









1














You can sort files with leading underscores to the end with --sort=version or -v which is equivalent to sort -V (natural version sort) (which is most useful for sorting files with numbers).



$ ls -v1
2
A
G
K
S
x4
_F


Details on version sorting are in info ls... note that:



‘LC_COLLATE’ is ignored, which means ‘ls -v’ and ‘sort -V’ will
sort non-numeric prefixes as if the ‘LC_COLLATE’ locale category
was set to ‘C’.


Perhaps this is adequate for your purpose.






share|improve this answer

















  • 1




    Just to mention that Dolphin (Kubuntu's file manager) sorts them, from top to bottom, like this: _F, 2, A, G, K, S, x4. It's using something called "Natural" sorting. I have a question on it here: askubuntu.com/questions/1040499/…
    – DK Bose
    Dec 22 '18 at 9:57






  • 1




    Cleaned up my answer.
    – DK Bose
    Dec 23 '18 at 6:52
















1














You can sort files with leading underscores to the end with --sort=version or -v which is equivalent to sort -V (natural version sort) (which is most useful for sorting files with numbers).



$ ls -v1
2
A
G
K
S
x4
_F


Details on version sorting are in info ls... note that:



‘LC_COLLATE’ is ignored, which means ‘ls -v’ and ‘sort -V’ will
sort non-numeric prefixes as if the ‘LC_COLLATE’ locale category
was set to ‘C’.


Perhaps this is adequate for your purpose.






share|improve this answer

















  • 1




    Just to mention that Dolphin (Kubuntu's file manager) sorts them, from top to bottom, like this: _F, 2, A, G, K, S, x4. It's using something called "Natural" sorting. I have a question on it here: askubuntu.com/questions/1040499/…
    – DK Bose
    Dec 22 '18 at 9:57






  • 1




    Cleaned up my answer.
    – DK Bose
    Dec 23 '18 at 6:52














1












1








1






You can sort files with leading underscores to the end with --sort=version or -v which is equivalent to sort -V (natural version sort) (which is most useful for sorting files with numbers).



$ ls -v1
2
A
G
K
S
x4
_F


Details on version sorting are in info ls... note that:



‘LC_COLLATE’ is ignored, which means ‘ls -v’ and ‘sort -V’ will
sort non-numeric prefixes as if the ‘LC_COLLATE’ locale category
was set to ‘C’.


Perhaps this is adequate for your purpose.






share|improve this answer












You can sort files with leading underscores to the end with --sort=version or -v which is equivalent to sort -V (natural version sort) (which is most useful for sorting files with numbers).



$ ls -v1
2
A
G
K
S
x4
_F


Details on version sorting are in info ls... note that:



‘LC_COLLATE’ is ignored, which means ‘ls -v’ and ‘sort -V’ will
sort non-numeric prefixes as if the ‘LC_COLLATE’ locale category
was set to ‘C’.


Perhaps this is adequate for your purpose.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 22 '18 at 8:57









Zanna

50.2k13133241




50.2k13133241








  • 1




    Just to mention that Dolphin (Kubuntu's file manager) sorts them, from top to bottom, like this: _F, 2, A, G, K, S, x4. It's using something called "Natural" sorting. I have a question on it here: askubuntu.com/questions/1040499/…
    – DK Bose
    Dec 22 '18 at 9:57






  • 1




    Cleaned up my answer.
    – DK Bose
    Dec 23 '18 at 6:52














  • 1




    Just to mention that Dolphin (Kubuntu's file manager) sorts them, from top to bottom, like this: _F, 2, A, G, K, S, x4. It's using something called "Natural" sorting. I have a question on it here: askubuntu.com/questions/1040499/…
    – DK Bose
    Dec 22 '18 at 9:57






  • 1




    Cleaned up my answer.
    – DK Bose
    Dec 23 '18 at 6:52








1




1




Just to mention that Dolphin (Kubuntu's file manager) sorts them, from top to bottom, like this: _F, 2, A, G, K, S, x4. It's using something called "Natural" sorting. I have a question on it here: askubuntu.com/questions/1040499/…
– DK Bose
Dec 22 '18 at 9:57




Just to mention that Dolphin (Kubuntu's file manager) sorts them, from top to bottom, like this: _F, 2, A, G, K, S, x4. It's using something called "Natural" sorting. I have a question on it here: askubuntu.com/questions/1040499/…
– DK Bose
Dec 22 '18 at 9:57




1




1




Cleaned up my answer.
– DK Bose
Dec 23 '18 at 6:52




Cleaned up my answer.
– DK Bose
Dec 23 '18 at 6:52













1














@Zanna's answer provides one solution. Another solution is this:



$ ls -lfr -1 _* [!_]*
_F
2
A
G
K
S
x4





share|improve this answer























  • This shows also all sub folders and files that are stored in the folder.
    – fmeier
    Jan 1 at 17:24
















1














@Zanna's answer provides one solution. Another solution is this:



$ ls -lfr -1 _* [!_]*
_F
2
A
G
K
S
x4





share|improve this answer























  • This shows also all sub folders and files that are stored in the folder.
    – fmeier
    Jan 1 at 17:24














1












1








1






@Zanna's answer provides one solution. Another solution is this:



$ ls -lfr -1 _* [!_]*
_F
2
A
G
K
S
x4





share|improve this answer














@Zanna's answer provides one solution. Another solution is this:



$ ls -lfr -1 _* [!_]*
_F
2
A
G
K
S
x4






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 23 '18 at 6:51

























answered Dec 23 '18 at 5:00









DK Bose

13.1k123983




13.1k123983












  • This shows also all sub folders and files that are stored in the folder.
    – fmeier
    Jan 1 at 17:24


















  • This shows also all sub folders and files that are stored in the folder.
    – fmeier
    Jan 1 at 17:24
















This shows also all sub folders and files that are stored in the folder.
– fmeier
Jan 1 at 17:24




This shows also all sub folders and files that are stored in the folder.
– fmeier
Jan 1 at 17:24


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • 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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1103748%2fsorting-files-and-folders-with-underscore-at-the-beginning%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

Mangá

 ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕