/bin/ls sorts differently than just ls Announcing the arrival of Valued Associate #679: Cesar...

Married in secret, can marital status in passport be changed at a later date?

Can I ask an author to send me his ebook?

How can I introduce the names of fantasy creatures to the reader?

Reflections in a Square

tikz: drawing arrow

Alternative to "rest in peace" (RIP)

Is this an antiquated or colloquial use of the possesive pronoun?

Does GDPR cover the collection of data by websites that crawl the web and resell user data

Is it OK if I do not take the receipt in Germany?

What helicopter has the most rotor blades?

Can 'non' with gerundive mean both lack of obligation and negative obligation?

Combining list in a Cartesian product format with addition operation?

Can gravitational waves pass through a black hole?

Magento 2 Editing phtml files in Production Mode

How do I overlay a PNG over two videos (one video overlays another) in one command using FFmpeg?

Is Vivien of the Wilds + Wilderness Reclimation a competitive combo?

Does Prince Arnaud cause someone holding the Princess to lose?

What is the evidence that custom checks in Northern Ireland are going to result in violence?

What kind of capacitor is this in the image?

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

Is my guitar’s action too high?

What's the connection between Mr. Nancy and fried chicken?

Determine the generator of an ideal of ring of integers

Why did Israel vote against lifting the American embargo on Cuba?



/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;
}







3















$ 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?










share|improve this question





























    3















    $ 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?










    share|improve this question

























      3












      3








      3








      $ 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?










      share|improve this question














      $ 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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Josh M.Josh M.

      65951227




      65951227






















          2 Answers
          2






          active

          oldest

          votes


















          6














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






          share|improve this answer
























          • 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.
            52 mins ago






          • 1





            @JoshM. Well, sorting should be done by ls itself, if possible. Sorting with sort is parsing, not recommended in general.

            – Kamil Maciorowski
            43 mins ago






          • 1





            @JoshM., rather than using /bin/ls, change your alias to what Tomak suggested and you will get the better behavior automatically.

            – John1024
            40 mins ago











          • @JoshM. You can also use ls for an unaliased ls or command ls for /bin/ls.

            – Freddy
            28 mins ago













          • Yes, @Freddy, very true. But, using alias ls='/bin/ls --color' is just a recipe for trouble.

            – John1024
            27 mins ago



















          1














          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$





          share|improve this answer
























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            6














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






            share|improve this answer
























            • 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.
              52 mins ago






            • 1





              @JoshM. Well, sorting should be done by ls itself, if possible. Sorting with sort is parsing, not recommended in general.

              – Kamil Maciorowski
              43 mins ago






            • 1





              @JoshM., rather than using /bin/ls, change your alias to what Tomak suggested and you will get the better behavior automatically.

              – John1024
              40 mins ago











            • @JoshM. You can also use ls for an unaliased ls or command ls for /bin/ls.

              – Freddy
              28 mins ago













            • Yes, @Freddy, very true. But, using alias ls='/bin/ls --color' is just a recipe for trouble.

              – John1024
              27 mins ago
















            6














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






            share|improve this answer
























            • 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.
              52 mins ago






            • 1





              @JoshM. Well, sorting should be done by ls itself, if possible. Sorting with sort is parsing, not recommended in general.

              – Kamil Maciorowski
              43 mins ago






            • 1





              @JoshM., rather than using /bin/ls, change your alias to what Tomak suggested and you will get the better behavior automatically.

              – John1024
              40 mins ago











            • @JoshM. You can also use ls for an unaliased ls or command ls for /bin/ls.

              – Freddy
              28 mins ago













            • Yes, @Freddy, very true. But, using alias ls='/bin/ls --color' is just a recipe for trouble.

              – John1024
              27 mins ago














            6












            6








            6







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






            share|improve this answer













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







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 1 hour ago









            TomekTomek

            44935




            44935













            • 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.
              52 mins ago






            • 1





              @JoshM. Well, sorting should be done by ls itself, if possible. Sorting with sort is parsing, not recommended in general.

              – Kamil Maciorowski
              43 mins ago






            • 1





              @JoshM., rather than using /bin/ls, change your alias to what Tomak suggested and you will get the better behavior automatically.

              – John1024
              40 mins ago











            • @JoshM. You can also use ls for an unaliased ls or command ls for /bin/ls.

              – Freddy
              28 mins ago













            • Yes, @Freddy, very true. But, using alias ls='/bin/ls --color' is just a recipe for trouble.

              – John1024
              27 mins 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.
              52 mins ago






            • 1





              @JoshM. Well, sorting should be done by ls itself, if possible. Sorting with sort is parsing, not recommended in general.

              – Kamil Maciorowski
              43 mins ago






            • 1





              @JoshM., rather than using /bin/ls, change your alias to what Tomak suggested and you will get the better behavior automatically.

              – John1024
              40 mins ago











            • @JoshM. You can also use ls for an unaliased ls or command ls for /bin/ls.

              – Freddy
              28 mins ago













            • Yes, @Freddy, very true. But, using alias ls='/bin/ls --color' is just a recipe for trouble.

              – John1024
              27 mins 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.
            52 mins 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.
            52 mins ago




            1




            1





            @JoshM. Well, sorting should be done by ls itself, if possible. Sorting with sort is parsing, not recommended in general.

            – Kamil Maciorowski
            43 mins ago





            @JoshM. Well, sorting should be done by ls itself, if possible. Sorting with sort is parsing, not recommended in general.

            – Kamil Maciorowski
            43 mins ago




            1




            1





            @JoshM., rather than using /bin/ls, change your alias to what Tomak suggested and you will get the better behavior automatically.

            – John1024
            40 mins ago





            @JoshM., rather than using /bin/ls, change your alias to what Tomak suggested and you will get the better behavior automatically.

            – John1024
            40 mins ago













            @JoshM. You can also use ls for an unaliased ls or command ls for /bin/ls.

            – Freddy
            28 mins ago







            @JoshM. You can also use ls for an unaliased ls or command ls for /bin/ls.

            – Freddy
            28 mins ago















            Yes, @Freddy, very true. But, using alias ls='/bin/ls --color' is just a recipe for trouble.

            – John1024
            27 mins ago





            Yes, @Freddy, very true. But, using alias ls='/bin/ls --color' is just a recipe for trouble.

            – John1024
            27 mins ago













            1














            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$





            share|improve this answer




























              1














              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$





              share|improve this answer


























                1












                1








                1







                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$





                share|improve this answer













                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$






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 37 mins ago









                FreddyFreddy

                3035




                3035






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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

                    Gersau Kjelder | Navigasjonsmeny46°59′0″N 8°31′0″E46°59′0″N...

                    Nässjö kommun Tettstader | Kjelder | NavigasjonsmenyeVIAFISNIGeoNamesMusicBrainz (area)

                    Kvitkval Innhaldsliste Taksonomi og utvikling | Utsjånad og levevis | Utbreiing | Åtferd |...