Grouping hidden files and directories with ls

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












How can ls be flagged to sort .-prefixed hidden directories and files in groups so that its output is sorted as visible directories, hidden directories, visible files, then hidden files?



I currently have ls aliased to ls -lG --color --group-directories-first which groups directories first, but visible and hidden directories are mixed together.



Instead, the output of ls should be:



visibleDirectoryA
visibleDirectoryB
.hiddenDirectoryA
.hiddenDirectoryB
visibleFileA
visibleFileB
.hiddenFileA
.hiddenFileB






share|improve this question






















  • i can reproduce, with locale en_AU.UTF8. BTW, LANG=C ls .... fails to reproduce (and, in fact, will even sort a directory name like !foo before any of the .hidden directories - strict ascii value sort rather than a natural sort).
    – cas
    Jan 13 at 6:19











  • My locale output is LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
    – infosmith
    Jan 13 at 6:56















up vote
0
down vote

favorite












How can ls be flagged to sort .-prefixed hidden directories and files in groups so that its output is sorted as visible directories, hidden directories, visible files, then hidden files?



I currently have ls aliased to ls -lG --color --group-directories-first which groups directories first, but visible and hidden directories are mixed together.



Instead, the output of ls should be:



visibleDirectoryA
visibleDirectoryB
.hiddenDirectoryA
.hiddenDirectoryB
visibleFileA
visibleFileB
.hiddenFileA
.hiddenFileB






share|improve this question






















  • i can reproduce, with locale en_AU.UTF8. BTW, LANG=C ls .... fails to reproduce (and, in fact, will even sort a directory name like !foo before any of the .hidden directories - strict ascii value sort rather than a natural sort).
    – cas
    Jan 13 at 6:19











  • My locale output is LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
    – infosmith
    Jan 13 at 6:56













up vote
0
down vote

favorite









up vote
0
down vote

favorite











How can ls be flagged to sort .-prefixed hidden directories and files in groups so that its output is sorted as visible directories, hidden directories, visible files, then hidden files?



I currently have ls aliased to ls -lG --color --group-directories-first which groups directories first, but visible and hidden directories are mixed together.



Instead, the output of ls should be:



visibleDirectoryA
visibleDirectoryB
.hiddenDirectoryA
.hiddenDirectoryB
visibleFileA
visibleFileB
.hiddenFileA
.hiddenFileB






share|improve this question














How can ls be flagged to sort .-prefixed hidden directories and files in groups so that its output is sorted as visible directories, hidden directories, visible files, then hidden files?



I currently have ls aliased to ls -lG --color --group-directories-first which groups directories first, but visible and hidden directories are mixed together.



Instead, the output of ls should be:



visibleDirectoryA
visibleDirectoryB
.hiddenDirectoryA
.hiddenDirectoryB
visibleFileA
visibleFileB
.hiddenFileA
.hiddenFileB








share|improve this question













share|improve this question




share|improve this question








edited Jan 13 at 13:21









Jeff Schaller

31.8k848109




31.8k848109










asked Jan 13 at 5:38









infosmith

32




32











  • i can reproduce, with locale en_AU.UTF8. BTW, LANG=C ls .... fails to reproduce (and, in fact, will even sort a directory name like !foo before any of the .hidden directories - strict ascii value sort rather than a natural sort).
    – cas
    Jan 13 at 6:19











  • My locale output is LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
    – infosmith
    Jan 13 at 6:56

















  • i can reproduce, with locale en_AU.UTF8. BTW, LANG=C ls .... fails to reproduce (and, in fact, will even sort a directory name like !foo before any of the .hidden directories - strict ascii value sort rather than a natural sort).
    – cas
    Jan 13 at 6:19











  • My locale output is LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
    – infosmith
    Jan 13 at 6:56
















i can reproduce, with locale en_AU.UTF8. BTW, LANG=C ls .... fails to reproduce (and, in fact, will even sort a directory name like !foo before any of the .hidden directories - strict ascii value sort rather than a natural sort).
– cas
Jan 13 at 6:19





i can reproduce, with locale en_AU.UTF8. BTW, LANG=C ls .... fails to reproduce (and, in fact, will even sort a directory name like !foo before any of the .hidden directories - strict ascii value sort rather than a natural sort).
– cas
Jan 13 at 6:19













My locale output is LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
– infosmith
Jan 13 at 6:56





My locale output is LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
– infosmith
Jan 13 at 6:56











1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Use -v for natural sort. e.g.



ls -lG --color --group-directories-first -A -v


Note while they are sorted into their own "group", the .hidden directories will appear before the visible directories, not after them, because a . sorts lower than most other characters.






share|improve this answer






















    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416747%2fgrouping-hidden-files-and-directories-with-ls%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    Use -v for natural sort. e.g.



    ls -lG --color --group-directories-first -A -v


    Note while they are sorted into their own "group", the .hidden directories will appear before the visible directories, not after them, because a . sorts lower than most other characters.






    share|improve this answer


























      up vote
      2
      down vote



      accepted










      Use -v for natural sort. e.g.



      ls -lG --color --group-directories-first -A -v


      Note while they are sorted into their own "group", the .hidden directories will appear before the visible directories, not after them, because a . sorts lower than most other characters.






      share|improve this answer
























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        Use -v for natural sort. e.g.



        ls -lG --color --group-directories-first -A -v


        Note while they are sorted into their own "group", the .hidden directories will appear before the visible directories, not after them, because a . sorts lower than most other characters.






        share|improve this answer














        Use -v for natural sort. e.g.



        ls -lG --color --group-directories-first -A -v


        Note while they are sorted into their own "group", the .hidden directories will appear before the visible directories, not after them, because a . sorts lower than most other characters.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 13 at 6:57

























        answered Jan 13 at 6:08









        cas

        37.7k44393




        37.7k44393






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416747%2fgrouping-hidden-files-and-directories-with-ls%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay