/bin/ls sorts differently than just ls Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Why does OS X Lion's terminal treat the PS1 prompt codes differently than Snow Leopard?Associating a renamed executable with our application fails on command line in WindowsWindows “tree” command sorts randomlyWhat is the different between “sudo su” and “sudo bash”?Kali Linux: Renaming files in binFile sorting confusionwhat is `ssh-agent bin/bash` and why I have to `ssh-add` everytimeusing awk on only files which START with 'xyz'SSH executes the command differentlyWhy does symlink to VLC break but but .bash_profile alias works?
Does traveling In The United States require a passport or can I use my green card if not a US citizen?
Why do C and C++ allow the expression (int) + 4*5?
Putting Ant-Man on house arrest
Do chord progressions usually move by fifths?
BV functions and wave equation
Network questions
Etymology of 見舞い
What helicopter has the most rotor blades?
Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?
Is there a way to convert Wolfram Language expression to string?
Can Deduction Guide have an explicit(bool) specifier?
xkeyval -- read keys from file
tabularx column has extra padding at right?
Reflections in a Square
Short story about an alien named Ushtu(?) coming from a future Earth, when ours was destroyed by a nuclear explosion
How to ask rejected full-time candidates to apply to teach individual courses?
When speaking, how do you change your mind mid-sentence?
Is it OK if I do not take the receipt in Germany?
Can I ask an author to send me his ebook?
How is an IPA symbol that lacks a name (e.g. ɲ) called?
Compiling and throwing simple dynamic exceptions at runtime for JVM
Determine the generator of an ideal of ring of integers
What is the definining line between a helicopter and a drone a person can ride in?
Are bags of holding fireproof?
/bin/ls sorts differently than just ls
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Why does OS X Lion's terminal treat the PS1 prompt codes differently than Snow Leopard?Associating a renamed executable with our application fails on command line in WindowsWindows “tree” command sorts randomlyWhat is the different between “sudo su” and “sudo bash”?Kali Linux: Renaming files in binFile sorting confusionwhat is `ssh-agent bin/bash` and why I have to `ssh-add` everytimeusing awk on only files which START with 'xyz'SSH executes the command differentlyWhy does symlink to VLC break but but .bash_profile alias works?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
$ ls |sort
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
xyz-0.0.1-1554323568.rpm
$ /bin/ls |sort
xyz-0.0.1-1554323568.rpm
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
$ which ls
alias ls='/bin/ls --color'
/bin/ls
Note that the sorting is different between the two commands (ls |sort
results in incorrect sorting). This must be due to the color flag, but why?
linux command-line bash unix
add a comment |
$ ls |sort
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
xyz-0.0.1-1554323568.rpm
$ /bin/ls |sort
xyz-0.0.1-1554323568.rpm
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
$ which ls
alias ls='/bin/ls --color'
/bin/ls
Note that the sorting is different between the two commands (ls |sort
results in incorrect sorting). This must be due to the color flag, but why?
linux command-line bash unix
add a comment |
$ ls |sort
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
xyz-0.0.1-1554323568.rpm
$ /bin/ls |sort
xyz-0.0.1-1554323568.rpm
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
$ which ls
alias ls='/bin/ls --color'
/bin/ls
Note that the sorting is different between the two commands (ls |sort
results in incorrect sorting). This must be due to the color flag, but why?
linux command-line bash unix
$ ls |sort
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
xyz-0.0.1-1554323568.rpm
$ /bin/ls |sort
xyz-0.0.1-1554323568.rpm
xyz-0.0.1-1554490900.rpm
xyz-0.0.1-1554745305.rpm
xyz-0.0.1-1554751021.rpm
xyz-0.0.1-1555513460.rpm
xyz-0.0.1-1555951745.rpm
$ which ls
alias ls='/bin/ls --color'
/bin/ls
Note that the sorting is different between the two commands (ls |sort
results in incorrect sorting). This must be due to the color flag, but why?
linux command-line bash unix
linux command-line bash unix
asked 5 hours ago
Josh M.Josh M.
66951227
66951227
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Do:
/bin/ls --color > file1
/bin/ls > file2
and compare content, you'll see the difference.
Aliasing ls
to /bin/ls --color=auto
is likely better idea, it will stop ls
from using color codes when not writing directly to terminal (like when piping to next program or writing to a file).
Thank you. I assume this is just a "known thing" and people understand ls + sorting should be done directly via/bin/ls
vs.ls
.
– Josh M.
4 hours ago
4
@JoshM. Well, sorting should be done byls
itself, if possible. Sorting withsort
is parsing, not recommended in general.
– Kamil Maciorowski
4 hours ago
2
@JoshM., rather than using/bin/ls
, change your alias to what Tomak suggested and you will get the better behavior automatically.
– John1024
4 hours ago
1
@JoshM. You can also usels
for an unaliasedls
orcommand ls
for/bin/ls
.
– Freddy
4 hours ago
2
Yes, @Freddy, very true. But, usingalias ls='/bin/ls --color'
is just a recipe for trouble.
– John1024
4 hours ago
add a comment |
In the sorted colored output ls|sort
, we can see that the last line xyz-0.0.1-1554323568.rpm
is the first line
of the non-colored output. The other lines are sorted equally.
If we have at a look at the colored escape codes (non-sorted), we can see that the first
line starts with a different escape code ^[[0m
. This is causing the wrong order when sorted (^[[01
before ^[[0m
).
$ /bin/ls --color xyz* | cat -A
^[[0m^[[01;31mxyz-0.0.1-1554323568.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554490900.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554745305.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554751021.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555513460.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555951745.rpm^[[0m$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "3"
;
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
);
);
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%2fsuperuser.com%2fquestions%2f1428322%2fbin-ls-sorts-differently-than-just-ls%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
Do:
/bin/ls --color > file1
/bin/ls > file2
and compare content, you'll see the difference.
Aliasing ls
to /bin/ls --color=auto
is likely better idea, it will stop ls
from using color codes when not writing directly to terminal (like when piping to next program or writing to a file).
Thank you. I assume this is just a "known thing" and people understand ls + sorting should be done directly via/bin/ls
vs.ls
.
– Josh M.
4 hours ago
4
@JoshM. Well, sorting should be done byls
itself, if possible. Sorting withsort
is parsing, not recommended in general.
– Kamil Maciorowski
4 hours ago
2
@JoshM., rather than using/bin/ls
, change your alias to what Tomak suggested and you will get the better behavior automatically.
– John1024
4 hours ago
1
@JoshM. You can also usels
for an unaliasedls
orcommand ls
for/bin/ls
.
– Freddy
4 hours ago
2
Yes, @Freddy, very true. But, usingalias ls='/bin/ls --color'
is just a recipe for trouble.
– John1024
4 hours ago
add a comment |
Do:
/bin/ls --color > file1
/bin/ls > file2
and compare content, you'll see the difference.
Aliasing ls
to /bin/ls --color=auto
is likely better idea, it will stop ls
from using color codes when not writing directly to terminal (like when piping to next program or writing to a file).
Thank you. I assume this is just a "known thing" and people understand ls + sorting should be done directly via/bin/ls
vs.ls
.
– Josh M.
4 hours ago
4
@JoshM. Well, sorting should be done byls
itself, if possible. Sorting withsort
is parsing, not recommended in general.
– Kamil Maciorowski
4 hours ago
2
@JoshM., rather than using/bin/ls
, change your alias to what Tomak suggested and you will get the better behavior automatically.
– John1024
4 hours ago
1
@JoshM. You can also usels
for an unaliasedls
orcommand ls
for/bin/ls
.
– Freddy
4 hours ago
2
Yes, @Freddy, very true. But, usingalias ls='/bin/ls --color'
is just a recipe for trouble.
– John1024
4 hours ago
add a comment |
Do:
/bin/ls --color > file1
/bin/ls > file2
and compare content, you'll see the difference.
Aliasing ls
to /bin/ls --color=auto
is likely better idea, it will stop ls
from using color codes when not writing directly to terminal (like when piping to next program or writing to a file).
Do:
/bin/ls --color > file1
/bin/ls > file2
and compare content, you'll see the difference.
Aliasing ls
to /bin/ls --color=auto
is likely better idea, it will stop ls
from using color codes when not writing directly to terminal (like when piping to next program or writing to a file).
answered 5 hours ago
TomekTomek
46935
46935
Thank you. I assume this is just a "known thing" and people understand ls + sorting should be done directly via/bin/ls
vs.ls
.
– Josh M.
4 hours ago
4
@JoshM. Well, sorting should be done byls
itself, if possible. Sorting withsort
is parsing, not recommended in general.
– Kamil Maciorowski
4 hours ago
2
@JoshM., rather than using/bin/ls
, change your alias to what Tomak suggested and you will get the better behavior automatically.
– John1024
4 hours ago
1
@JoshM. You can also usels
for an unaliasedls
orcommand ls
for/bin/ls
.
– Freddy
4 hours ago
2
Yes, @Freddy, very true. But, usingalias ls='/bin/ls --color'
is just a recipe for trouble.
– John1024
4 hours ago
add a comment |
Thank you. I assume this is just a "known thing" and people understand ls + sorting should be done directly via/bin/ls
vs.ls
.
– Josh M.
4 hours ago
4
@JoshM. Well, sorting should be done byls
itself, if possible. Sorting withsort
is parsing, not recommended in general.
– Kamil Maciorowski
4 hours ago
2
@JoshM., rather than using/bin/ls
, change your alias to what Tomak suggested and you will get the better behavior automatically.
– John1024
4 hours ago
1
@JoshM. You can also usels
for an unaliasedls
orcommand ls
for/bin/ls
.
– Freddy
4 hours ago
2
Yes, @Freddy, very true. But, usingalias ls='/bin/ls --color'
is just a recipe for trouble.
– John1024
4 hours ago
Thank you. I assume this is just a "known thing" and people understand ls + sorting should be done directly via
/bin/ls
vs. ls
.– Josh M.
4 hours ago
Thank you. I assume this is just a "known thing" and people understand ls + sorting should be done directly via
/bin/ls
vs. ls
.– Josh M.
4 hours ago
4
4
@JoshM. Well, sorting should be done by
ls
itself, if possible. Sorting with sort
is parsing, not recommended in general.– Kamil Maciorowski
4 hours ago
@JoshM. Well, sorting should be done by
ls
itself, if possible. Sorting with sort
is parsing, not recommended in general.– Kamil Maciorowski
4 hours ago
2
2
@JoshM., rather than using
/bin/ls
, change your alias to what Tomak suggested and you will get the better behavior automatically.– John1024
4 hours ago
@JoshM., rather than using
/bin/ls
, change your alias to what Tomak suggested and you will get the better behavior automatically.– John1024
4 hours ago
1
1
@JoshM. You can also use
ls
for an unaliased ls
or command ls
for /bin/ls
.– Freddy
4 hours ago
@JoshM. You can also use
ls
for an unaliased ls
or command ls
for /bin/ls
.– Freddy
4 hours ago
2
2
Yes, @Freddy, very true. But, using
alias ls='/bin/ls --color'
is just a recipe for trouble.– John1024
4 hours ago
Yes, @Freddy, very true. But, using
alias ls='/bin/ls --color'
is just a recipe for trouble.– John1024
4 hours ago
add a comment |
In the sorted colored output ls|sort
, we can see that the last line xyz-0.0.1-1554323568.rpm
is the first line
of the non-colored output. The other lines are sorted equally.
If we have at a look at the colored escape codes (non-sorted), we can see that the first
line starts with a different escape code ^[[0m
. This is causing the wrong order when sorted (^[[01
before ^[[0m
).
$ /bin/ls --color xyz* | cat -A
^[[0m^[[01;31mxyz-0.0.1-1554323568.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554490900.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554745305.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554751021.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555513460.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555951745.rpm^[[0m$
add a comment |
In the sorted colored output ls|sort
, we can see that the last line xyz-0.0.1-1554323568.rpm
is the first line
of the non-colored output. The other lines are sorted equally.
If we have at a look at the colored escape codes (non-sorted), we can see that the first
line starts with a different escape code ^[[0m
. This is causing the wrong order when sorted (^[[01
before ^[[0m
).
$ /bin/ls --color xyz* | cat -A
^[[0m^[[01;31mxyz-0.0.1-1554323568.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554490900.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554745305.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554751021.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555513460.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555951745.rpm^[[0m$
add a comment |
In the sorted colored output ls|sort
, we can see that the last line xyz-0.0.1-1554323568.rpm
is the first line
of the non-colored output. The other lines are sorted equally.
If we have at a look at the colored escape codes (non-sorted), we can see that the first
line starts with a different escape code ^[[0m
. This is causing the wrong order when sorted (^[[01
before ^[[0m
).
$ /bin/ls --color xyz* | cat -A
^[[0m^[[01;31mxyz-0.0.1-1554323568.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554490900.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554745305.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554751021.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555513460.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555951745.rpm^[[0m$
In the sorted colored output ls|sort
, we can see that the last line xyz-0.0.1-1554323568.rpm
is the first line
of the non-colored output. The other lines are sorted equally.
If we have at a look at the colored escape codes (non-sorted), we can see that the first
line starts with a different escape code ^[[0m
. This is causing the wrong order when sorted (^[[01
before ^[[0m
).
$ /bin/ls --color xyz* | cat -A
^[[0m^[[01;31mxyz-0.0.1-1554323568.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554490900.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554745305.rpm^[[0m$
^[[01;31mxyz-0.0.1-1554751021.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555513460.rpm^[[0m$
^[[01;31mxyz-0.0.1-1555951745.rpm^[[0m$
answered 4 hours ago
FreddyFreddy
3435
3435
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1428322%2fbin-ls-sorts-differently-than-just-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