Is there any option with 'ls' command that I see only the directories?












62















Sometimes, I need to check only the directories not files. Is there any option with the command ls? Or is there any utility for doing that?



EDIT: I'm using Mac OS X, and ls -d gives me . even though I have directories.










share|improve this question




















  • 3





    Can somebody explain why ls -d gives only . and why the */ must be added to the end to make it work?

    – cwd
    Oct 4 '11 at 2:49






  • 2





    @cwd If you don't specify any files, ls defaults to .. And -d means don't print the directory's contents, print the directory itself.

    – Mikel
    May 23 '12 at 14:52








  • 1





    @cwd try using ls -p it shows the / after the directory names. So */ is just a pattern which is matched against the directory name and / combo.

    – Pitt
    Oct 24 '12 at 15:55
















62















Sometimes, I need to check only the directories not files. Is there any option with the command ls? Or is there any utility for doing that?



EDIT: I'm using Mac OS X, and ls -d gives me . even though I have directories.










share|improve this question




















  • 3





    Can somebody explain why ls -d gives only . and why the */ must be added to the end to make it work?

    – cwd
    Oct 4 '11 at 2:49






  • 2





    @cwd If you don't specify any files, ls defaults to .. And -d means don't print the directory's contents, print the directory itself.

    – Mikel
    May 23 '12 at 14:52








  • 1





    @cwd try using ls -p it shows the / after the directory names. So */ is just a pattern which is matched against the directory name and / combo.

    – Pitt
    Oct 24 '12 at 15:55














62












62








62


20






Sometimes, I need to check only the directories not files. Is there any option with the command ls? Or is there any utility for doing that?



EDIT: I'm using Mac OS X, and ls -d gives me . even though I have directories.










share|improve this question
















Sometimes, I need to check only the directories not files. Is there any option with the command ls? Or is there any utility for doing that?



EDIT: I'm using Mac OS X, and ls -d gives me . even though I have directories.







ls utilities






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 21 '11 at 8:01









Tshepang

26.1k71186264




26.1k71186264










asked Sep 6 '10 at 1:14









prosseekprosseek

2,845113539




2,845113539








  • 3





    Can somebody explain why ls -d gives only . and why the */ must be added to the end to make it work?

    – cwd
    Oct 4 '11 at 2:49






  • 2





    @cwd If you don't specify any files, ls defaults to .. And -d means don't print the directory's contents, print the directory itself.

    – Mikel
    May 23 '12 at 14:52








  • 1





    @cwd try using ls -p it shows the / after the directory names. So */ is just a pattern which is matched against the directory name and / combo.

    – Pitt
    Oct 24 '12 at 15:55














  • 3





    Can somebody explain why ls -d gives only . and why the */ must be added to the end to make it work?

    – cwd
    Oct 4 '11 at 2:49






  • 2





    @cwd If you don't specify any files, ls defaults to .. And -d means don't print the directory's contents, print the directory itself.

    – Mikel
    May 23 '12 at 14:52








  • 1





    @cwd try using ls -p it shows the / after the directory names. So */ is just a pattern which is matched against the directory name and / combo.

    – Pitt
    Oct 24 '12 at 15:55








3




3





Can somebody explain why ls -d gives only . and why the */ must be added to the end to make it work?

– cwd
Oct 4 '11 at 2:49





Can somebody explain why ls -d gives only . and why the */ must be added to the end to make it work?

– cwd
Oct 4 '11 at 2:49




2




2





@cwd If you don't specify any files, ls defaults to .. And -d means don't print the directory's contents, print the directory itself.

– Mikel
May 23 '12 at 14:52







@cwd If you don't specify any files, ls defaults to .. And -d means don't print the directory's contents, print the directory itself.

– Mikel
May 23 '12 at 14:52






1




1





@cwd try using ls -p it shows the / after the directory names. So */ is just a pattern which is matched against the directory name and / combo.

– Pitt
Oct 24 '12 at 15:55





@cwd try using ls -p it shows the / after the directory names. So */ is just a pattern which is matched against the directory name and / combo.

– Pitt
Oct 24 '12 at 15:55










8 Answers
8






active

oldest

votes


















73














I know there is already a selected answer, but you can get the requested behavior with just ls:



ls -ld -- */


(Note that the '--' marks the end of parameters, preventing folder names beginning with a hyphen from being interpreted as further command options.)



This will list all the non-hidden (unless you configure your shell's globs to expand them) directories in the current working directory where it is run (note that it also includes symbolic links to directories). To get all the subdirectories of some other folder, just try:



ls -ld /path/to/directory/*/


Note that the -l is optional.






share|improve this answer





















  • 4





    Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it.

    – gvkv
    Sep 6 '10 at 3:46











  • -d for dir, -l for long format. whats the purpose of -- ?

    – Dineshkumar
    Apr 17 '15 at 15:03













  • While this looks short and works for most cases, one may not want to use this approach when a true directory is needed, not a directory's symlink. So find is actually a good choice in that case.

    – biocyberman
    Jan 31 '17 at 20:59













  • find also has the advantage when the number of directories exceeds the maximum argument length.

    – Steven D
    Feb 1 '17 at 9:31











  • Working backwards, I just realised you can simply ignore anything with an extension: ls -alhF --ignore=*.*. Not sure how well this would handle 'hidden' folders, i.e. .myHiddenFolder

    – Timmah
    Nov 1 '17 at 0:46



















11














No, but a simple find command will do it:



find . -type d -depth 1


or grep



ls -F | grep /


You could then alias either one if necessary.






share|improve this answer





















  • 6





    On Ubuntu 14.04 it was -maxdepth 1. Also find wanted me to flip the order: find . -maxdepth 1 -type d

    – Brad Cupit
    Aug 28 '15 at 14:33











  • That ls -F | grep / solution works wonders! It seems to be the only one I can get to work on my FreeBSD machine. I think using Fish means that anything with */ may not work?

    – cjm
    Jul 27 '16 at 4:38











  • I've never worked with Fish so I'm not sure about that but the -F option can work wonders.

    – gvkv
    Jul 27 '16 at 13:21



















5














I like the tree utility to get an overview over the directory structure. It's available in MacPorts and all Linux distributions I've tried.



tree -d -L 2


That would show all directories, two levels deep.






share|improve this answer































    4














    I also needed to view hidden directories so have modified the suggestion above to fit my needs



    ls -ad */ .*





    share|improve this answer

































      0














      The easiest way is to type the following command. This works across most UNIX and Linux platforms and versions. You can skip the -F if you want, but it is the argument that adds the / to the end of the directory name. The -C argument captures only directory names - all of them in the current directory. If you want to see only directories and subdirectories in the current path, simply add the -R argument (ls -CFR).



      # ls -CF
      /dir1 /dir2 /dir3 /beaches /Work /Other





      share|improve this answer


























      • In all ls implementations I know and in the POSIX specification of ls, -C is to output in columns, not to skip non-directory files. In your example, the / are printed before the file names, which no ls implementation would do. With -F, / is appended to the file name for directory files.

        – Stéphane Chazelas
        Jun 21 '18 at 16:15





















      -1














      I think ls has a bug on Mac OS X. A workaround is to use grep... ls -l / | grep "^d"






      share|improve this answer



















      • 1





        It's nice to know I'm not the only person that uses the grep "^d" hack

        – Michael Mrozek
        Sep 6 '10 at 2:10








      • 6





        As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home

        – Steven D
        Sep 6 '10 at 2:11













      • Carats aren't special to the shell. You can just use ls -l / | grep ^d. If you are going to use quotes, since you don't need parameter expansion, make them single quotes. ls -l / | grep '^d'. Yes, I'm a pedant. But really, do this. :)

        – Wildcard
        Nov 1 '16 at 1:08



















      -1














      $ ls -p | grep /


      The -p flag will make ls add a slash (`/') after each filename if that file is a directory.






      share|improve this answer

































        -3














        ls -G


        this will show your directories in blue






        share|improve this answer





















        • 1





          Do you see only the directories when using this command ?

          – don_crissti
          Nov 1 '16 at 0:55













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


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f1645%2fis-there-any-option-with-ls-command-that-i-see-only-the-directories%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        8 Answers
        8






        active

        oldest

        votes








        8 Answers
        8






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        73














        I know there is already a selected answer, but you can get the requested behavior with just ls:



        ls -ld -- */


        (Note that the '--' marks the end of parameters, preventing folder names beginning with a hyphen from being interpreted as further command options.)



        This will list all the non-hidden (unless you configure your shell's globs to expand them) directories in the current working directory where it is run (note that it also includes symbolic links to directories). To get all the subdirectories of some other folder, just try:



        ls -ld /path/to/directory/*/


        Note that the -l is optional.






        share|improve this answer





















        • 4





          Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it.

          – gvkv
          Sep 6 '10 at 3:46











        • -d for dir, -l for long format. whats the purpose of -- ?

          – Dineshkumar
          Apr 17 '15 at 15:03













        • While this looks short and works for most cases, one may not want to use this approach when a true directory is needed, not a directory's symlink. So find is actually a good choice in that case.

          – biocyberman
          Jan 31 '17 at 20:59













        • find also has the advantage when the number of directories exceeds the maximum argument length.

          – Steven D
          Feb 1 '17 at 9:31











        • Working backwards, I just realised you can simply ignore anything with an extension: ls -alhF --ignore=*.*. Not sure how well this would handle 'hidden' folders, i.e. .myHiddenFolder

          – Timmah
          Nov 1 '17 at 0:46
















        73














        I know there is already a selected answer, but you can get the requested behavior with just ls:



        ls -ld -- */


        (Note that the '--' marks the end of parameters, preventing folder names beginning with a hyphen from being interpreted as further command options.)



        This will list all the non-hidden (unless you configure your shell's globs to expand them) directories in the current working directory where it is run (note that it also includes symbolic links to directories). To get all the subdirectories of some other folder, just try:



        ls -ld /path/to/directory/*/


        Note that the -l is optional.






        share|improve this answer





















        • 4





          Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it.

          – gvkv
          Sep 6 '10 at 3:46











        • -d for dir, -l for long format. whats the purpose of -- ?

          – Dineshkumar
          Apr 17 '15 at 15:03













        • While this looks short and works for most cases, one may not want to use this approach when a true directory is needed, not a directory's symlink. So find is actually a good choice in that case.

          – biocyberman
          Jan 31 '17 at 20:59













        • find also has the advantage when the number of directories exceeds the maximum argument length.

          – Steven D
          Feb 1 '17 at 9:31











        • Working backwards, I just realised you can simply ignore anything with an extension: ls -alhF --ignore=*.*. Not sure how well this would handle 'hidden' folders, i.e. .myHiddenFolder

          – Timmah
          Nov 1 '17 at 0:46














        73












        73








        73







        I know there is already a selected answer, but you can get the requested behavior with just ls:



        ls -ld -- */


        (Note that the '--' marks the end of parameters, preventing folder names beginning with a hyphen from being interpreted as further command options.)



        This will list all the non-hidden (unless you configure your shell's globs to expand them) directories in the current working directory where it is run (note that it also includes symbolic links to directories). To get all the subdirectories of some other folder, just try:



        ls -ld /path/to/directory/*/


        Note that the -l is optional.






        share|improve this answer















        I know there is already a selected answer, but you can get the requested behavior with just ls:



        ls -ld -- */


        (Note that the '--' marks the end of parameters, preventing folder names beginning with a hyphen from being interpreted as further command options.)



        This will list all the non-hidden (unless you configure your shell's globs to expand them) directories in the current working directory where it is run (note that it also includes symbolic links to directories). To get all the subdirectories of some other folder, just try:



        ls -ld /path/to/directory/*/


        Note that the -l is optional.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 21 '18 at 16:18









        Stéphane Chazelas

        306k57579933




        306k57579933










        answered Sep 6 '10 at 2:16









        Steven DSteven D

        32.4k798108




        32.4k798108








        • 4





          Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it.

          – gvkv
          Sep 6 '10 at 3:46











        • -d for dir, -l for long format. whats the purpose of -- ?

          – Dineshkumar
          Apr 17 '15 at 15:03













        • While this looks short and works for most cases, one may not want to use this approach when a true directory is needed, not a directory's symlink. So find is actually a good choice in that case.

          – biocyberman
          Jan 31 '17 at 20:59













        • find also has the advantage when the number of directories exceeds the maximum argument length.

          – Steven D
          Feb 1 '17 at 9:31











        • Working backwards, I just realised you can simply ignore anything with an extension: ls -alhF --ignore=*.*. Not sure how well this would handle 'hidden' folders, i.e. .myHiddenFolder

          – Timmah
          Nov 1 '17 at 0:46














        • 4





          Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it.

          – gvkv
          Sep 6 '10 at 3:46











        • -d for dir, -l for long format. whats the purpose of -- ?

          – Dineshkumar
          Apr 17 '15 at 15:03













        • While this looks short and works for most cases, one may not want to use this approach when a true directory is needed, not a directory's symlink. So find is actually a good choice in that case.

          – biocyberman
          Jan 31 '17 at 20:59













        • find also has the advantage when the number of directories exceeds the maximum argument length.

          – Steven D
          Feb 1 '17 at 9:31











        • Working backwards, I just realised you can simply ignore anything with an extension: ls -alhF --ignore=*.*. Not sure how well this would handle 'hidden' folders, i.e. .myHiddenFolder

          – Timmah
          Nov 1 '17 at 0:46








        4




        4





        Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it.

        – gvkv
        Sep 6 '10 at 3:46





        Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it.

        – gvkv
        Sep 6 '10 at 3:46













        -d for dir, -l for long format. whats the purpose of -- ?

        – Dineshkumar
        Apr 17 '15 at 15:03







        -d for dir, -l for long format. whats the purpose of -- ?

        – Dineshkumar
        Apr 17 '15 at 15:03















        While this looks short and works for most cases, one may not want to use this approach when a true directory is needed, not a directory's symlink. So find is actually a good choice in that case.

        – biocyberman
        Jan 31 '17 at 20:59







        While this looks short and works for most cases, one may not want to use this approach when a true directory is needed, not a directory's symlink. So find is actually a good choice in that case.

        – biocyberman
        Jan 31 '17 at 20:59















        find also has the advantage when the number of directories exceeds the maximum argument length.

        – Steven D
        Feb 1 '17 at 9:31





        find also has the advantage when the number of directories exceeds the maximum argument length.

        – Steven D
        Feb 1 '17 at 9:31













        Working backwards, I just realised you can simply ignore anything with an extension: ls -alhF --ignore=*.*. Not sure how well this would handle 'hidden' folders, i.e. .myHiddenFolder

        – Timmah
        Nov 1 '17 at 0:46





        Working backwards, I just realised you can simply ignore anything with an extension: ls -alhF --ignore=*.*. Not sure how well this would handle 'hidden' folders, i.e. .myHiddenFolder

        – Timmah
        Nov 1 '17 at 0:46













        11














        No, but a simple find command will do it:



        find . -type d -depth 1


        or grep



        ls -F | grep /


        You could then alias either one if necessary.






        share|improve this answer





















        • 6





          On Ubuntu 14.04 it was -maxdepth 1. Also find wanted me to flip the order: find . -maxdepth 1 -type d

          – Brad Cupit
          Aug 28 '15 at 14:33











        • That ls -F | grep / solution works wonders! It seems to be the only one I can get to work on my FreeBSD machine. I think using Fish means that anything with */ may not work?

          – cjm
          Jul 27 '16 at 4:38











        • I've never worked with Fish so I'm not sure about that but the -F option can work wonders.

          – gvkv
          Jul 27 '16 at 13:21
















        11














        No, but a simple find command will do it:



        find . -type d -depth 1


        or grep



        ls -F | grep /


        You could then alias either one if necessary.






        share|improve this answer





















        • 6





          On Ubuntu 14.04 it was -maxdepth 1. Also find wanted me to flip the order: find . -maxdepth 1 -type d

          – Brad Cupit
          Aug 28 '15 at 14:33











        • That ls -F | grep / solution works wonders! It seems to be the only one I can get to work on my FreeBSD machine. I think using Fish means that anything with */ may not work?

          – cjm
          Jul 27 '16 at 4:38











        • I've never worked with Fish so I'm not sure about that but the -F option can work wonders.

          – gvkv
          Jul 27 '16 at 13:21














        11












        11








        11







        No, but a simple find command will do it:



        find . -type d -depth 1


        or grep



        ls -F | grep /


        You could then alias either one if necessary.






        share|improve this answer















        No, but a simple find command will do it:



        find . -type d -depth 1


        or grep



        ls -F | grep /


        You could then alias either one if necessary.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 6 '10 at 1:26

























        answered Sep 6 '10 at 1:18









        gvkvgvkv

        2,3251817




        2,3251817








        • 6





          On Ubuntu 14.04 it was -maxdepth 1. Also find wanted me to flip the order: find . -maxdepth 1 -type d

          – Brad Cupit
          Aug 28 '15 at 14:33











        • That ls -F | grep / solution works wonders! It seems to be the only one I can get to work on my FreeBSD machine. I think using Fish means that anything with */ may not work?

          – cjm
          Jul 27 '16 at 4:38











        • I've never worked with Fish so I'm not sure about that but the -F option can work wonders.

          – gvkv
          Jul 27 '16 at 13:21














        • 6





          On Ubuntu 14.04 it was -maxdepth 1. Also find wanted me to flip the order: find . -maxdepth 1 -type d

          – Brad Cupit
          Aug 28 '15 at 14:33











        • That ls -F | grep / solution works wonders! It seems to be the only one I can get to work on my FreeBSD machine. I think using Fish means that anything with */ may not work?

          – cjm
          Jul 27 '16 at 4:38











        • I've never worked with Fish so I'm not sure about that but the -F option can work wonders.

          – gvkv
          Jul 27 '16 at 13:21








        6




        6





        On Ubuntu 14.04 it was -maxdepth 1. Also find wanted me to flip the order: find . -maxdepth 1 -type d

        – Brad Cupit
        Aug 28 '15 at 14:33





        On Ubuntu 14.04 it was -maxdepth 1. Also find wanted me to flip the order: find . -maxdepth 1 -type d

        – Brad Cupit
        Aug 28 '15 at 14:33













        That ls -F | grep / solution works wonders! It seems to be the only one I can get to work on my FreeBSD machine. I think using Fish means that anything with */ may not work?

        – cjm
        Jul 27 '16 at 4:38





        That ls -F | grep / solution works wonders! It seems to be the only one I can get to work on my FreeBSD machine. I think using Fish means that anything with */ may not work?

        – cjm
        Jul 27 '16 at 4:38













        I've never worked with Fish so I'm not sure about that but the -F option can work wonders.

        – gvkv
        Jul 27 '16 at 13:21





        I've never worked with Fish so I'm not sure about that but the -F option can work wonders.

        – gvkv
        Jul 27 '16 at 13:21











        5














        I like the tree utility to get an overview over the directory structure. It's available in MacPorts and all Linux distributions I've tried.



        tree -d -L 2


        That would show all directories, two levels deep.






        share|improve this answer




























          5














          I like the tree utility to get an overview over the directory structure. It's available in MacPorts and all Linux distributions I've tried.



          tree -d -L 2


          That would show all directories, two levels deep.






          share|improve this answer


























            5












            5








            5







            I like the tree utility to get an overview over the directory structure. It's available in MacPorts and all Linux distributions I've tried.



            tree -d -L 2


            That would show all directories, two levels deep.






            share|improve this answer













            I like the tree utility to get an overview over the directory structure. It's available in MacPorts and all Linux distributions I've tried.



            tree -d -L 2


            That would show all directories, two levels deep.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 6 '10 at 11:56









            Claes MogrenClaes Mogren

            1513




            1513























                4














                I also needed to view hidden directories so have modified the suggestion above to fit my needs



                ls -ad */ .*





                share|improve this answer






























                  4














                  I also needed to view hidden directories so have modified the suggestion above to fit my needs



                  ls -ad */ .*





                  share|improve this answer




























                    4












                    4








                    4







                    I also needed to view hidden directories so have modified the suggestion above to fit my needs



                    ls -ad */ .*





                    share|improve this answer















                    I also needed to view hidden directories so have modified the suggestion above to fit my needs



                    ls -ad */ .*






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 23 '12 at 11:30

























                    answered May 23 '12 at 8:27









                    Neil ChandlerNeil Chandler

                    412




                    412























                        0














                        The easiest way is to type the following command. This works across most UNIX and Linux platforms and versions. You can skip the -F if you want, but it is the argument that adds the / to the end of the directory name. The -C argument captures only directory names - all of them in the current directory. If you want to see only directories and subdirectories in the current path, simply add the -R argument (ls -CFR).



                        # ls -CF
                        /dir1 /dir2 /dir3 /beaches /Work /Other





                        share|improve this answer


























                        • In all ls implementations I know and in the POSIX specification of ls, -C is to output in columns, not to skip non-directory files. In your example, the / are printed before the file names, which no ls implementation would do. With -F, / is appended to the file name for directory files.

                          – Stéphane Chazelas
                          Jun 21 '18 at 16:15


















                        0














                        The easiest way is to type the following command. This works across most UNIX and Linux platforms and versions. You can skip the -F if you want, but it is the argument that adds the / to the end of the directory name. The -C argument captures only directory names - all of them in the current directory. If you want to see only directories and subdirectories in the current path, simply add the -R argument (ls -CFR).



                        # ls -CF
                        /dir1 /dir2 /dir3 /beaches /Work /Other





                        share|improve this answer


























                        • In all ls implementations I know and in the POSIX specification of ls, -C is to output in columns, not to skip non-directory files. In your example, the / are printed before the file names, which no ls implementation would do. With -F, / is appended to the file name for directory files.

                          – Stéphane Chazelas
                          Jun 21 '18 at 16:15
















                        0












                        0








                        0







                        The easiest way is to type the following command. This works across most UNIX and Linux platforms and versions. You can skip the -F if you want, but it is the argument that adds the / to the end of the directory name. The -C argument captures only directory names - all of them in the current directory. If you want to see only directories and subdirectories in the current path, simply add the -R argument (ls -CFR).



                        # ls -CF
                        /dir1 /dir2 /dir3 /beaches /Work /Other





                        share|improve this answer















                        The easiest way is to type the following command. This works across most UNIX and Linux platforms and versions. You can skip the -F if you want, but it is the argument that adds the / to the end of the directory name. The -C argument captures only directory names - all of them in the current directory. If you want to see only directories and subdirectories in the current path, simply add the -R argument (ls -CFR).



                        # ls -CF
                        /dir1 /dir2 /dir3 /beaches /Work /Other






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 8 mins ago









                        Jeff Schaller

                        41.7k1156133




                        41.7k1156133










                        answered Jun 21 '18 at 16:04









                        Willie LopezWillie Lopez

                        91




                        91













                        • In all ls implementations I know and in the POSIX specification of ls, -C is to output in columns, not to skip non-directory files. In your example, the / are printed before the file names, which no ls implementation would do. With -F, / is appended to the file name for directory files.

                          – Stéphane Chazelas
                          Jun 21 '18 at 16:15





















                        • In all ls implementations I know and in the POSIX specification of ls, -C is to output in columns, not to skip non-directory files. In your example, the / are printed before the file names, which no ls implementation would do. With -F, / is appended to the file name for directory files.

                          – Stéphane Chazelas
                          Jun 21 '18 at 16:15



















                        In all ls implementations I know and in the POSIX specification of ls, -C is to output in columns, not to skip non-directory files. In your example, the / are printed before the file names, which no ls implementation would do. With -F, / is appended to the file name for directory files.

                        – Stéphane Chazelas
                        Jun 21 '18 at 16:15







                        In all ls implementations I know and in the POSIX specification of ls, -C is to output in columns, not to skip non-directory files. In your example, the / are printed before the file names, which no ls implementation would do. With -F, / is appended to the file name for directory files.

                        – Stéphane Chazelas
                        Jun 21 '18 at 16:15













                        -1














                        I think ls has a bug on Mac OS X. A workaround is to use grep... ls -l / | grep "^d"






                        share|improve this answer



















                        • 1





                          It's nice to know I'm not the only person that uses the grep "^d" hack

                          – Michael Mrozek
                          Sep 6 '10 at 2:10








                        • 6





                          As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home

                          – Steven D
                          Sep 6 '10 at 2:11













                        • Carats aren't special to the shell. You can just use ls -l / | grep ^d. If you are going to use quotes, since you don't need parameter expansion, make them single quotes. ls -l / | grep '^d'. Yes, I'm a pedant. But really, do this. :)

                          – Wildcard
                          Nov 1 '16 at 1:08
















                        -1














                        I think ls has a bug on Mac OS X. A workaround is to use grep... ls -l / | grep "^d"






                        share|improve this answer



















                        • 1





                          It's nice to know I'm not the only person that uses the grep "^d" hack

                          – Michael Mrozek
                          Sep 6 '10 at 2:10








                        • 6





                          As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home

                          – Steven D
                          Sep 6 '10 at 2:11













                        • Carats aren't special to the shell. You can just use ls -l / | grep ^d. If you are going to use quotes, since you don't need parameter expansion, make them single quotes. ls -l / | grep '^d'. Yes, I'm a pedant. But really, do this. :)

                          – Wildcard
                          Nov 1 '16 at 1:08














                        -1












                        -1








                        -1







                        I think ls has a bug on Mac OS X. A workaround is to use grep... ls -l / | grep "^d"






                        share|improve this answer













                        I think ls has a bug on Mac OS X. A workaround is to use grep... ls -l / | grep "^d"







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Sep 6 '10 at 1:27









                        duffbeer703duffbeer703

                        1554




                        1554








                        • 1





                          It's nice to know I'm not the only person that uses the grep "^d" hack

                          – Michael Mrozek
                          Sep 6 '10 at 2:10








                        • 6





                          As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home

                          – Steven D
                          Sep 6 '10 at 2:11













                        • Carats aren't special to the shell. You can just use ls -l / | grep ^d. If you are going to use quotes, since you don't need parameter expansion, make them single quotes. ls -l / | grep '^d'. Yes, I'm a pedant. But really, do this. :)

                          – Wildcard
                          Nov 1 '16 at 1:08














                        • 1





                          It's nice to know I'm not the only person that uses the grep "^d" hack

                          – Michael Mrozek
                          Sep 6 '10 at 2:10








                        • 6





                          As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home

                          – Steven D
                          Sep 6 '10 at 2:11













                        • Carats aren't special to the shell. You can just use ls -l / | grep ^d. If you are going to use quotes, since you don't need parameter expansion, make them single quotes. ls -l / | grep '^d'. Yes, I'm a pedant. But really, do this. :)

                          – Wildcard
                          Nov 1 '16 at 1:08








                        1




                        1





                        It's nice to know I'm not the only person that uses the grep "^d" hack

                        – Michael Mrozek
                        Sep 6 '10 at 2:10







                        It's nice to know I'm not the only person that uses the grep "^d" hack

                        – Michael Mrozek
                        Sep 6 '10 at 2:10






                        6




                        6





                        As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home

                        – Steven D
                        Sep 6 '10 at 2:11







                        As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home

                        – Steven D
                        Sep 6 '10 at 2:11















                        Carats aren't special to the shell. You can just use ls -l / | grep ^d. If you are going to use quotes, since you don't need parameter expansion, make them single quotes. ls -l / | grep '^d'. Yes, I'm a pedant. But really, do this. :)

                        – Wildcard
                        Nov 1 '16 at 1:08





                        Carats aren't special to the shell. You can just use ls -l / | grep ^d. If you are going to use quotes, since you don't need parameter expansion, make them single quotes. ls -l / | grep '^d'. Yes, I'm a pedant. But really, do this. :)

                        – Wildcard
                        Nov 1 '16 at 1:08











                        -1














                        $ ls -p | grep /


                        The -p flag will make ls add a slash (`/') after each filename if that file is a directory.






                        share|improve this answer






























                          -1














                          $ ls -p | grep /


                          The -p flag will make ls add a slash (`/') after each filename if that file is a directory.






                          share|improve this answer




























                            -1












                            -1








                            -1







                            $ ls -p | grep /


                            The -p flag will make ls add a slash (`/') after each filename if that file is a directory.






                            share|improve this answer















                            $ ls -p | grep /


                            The -p flag will make ls add a slash (`/') after each filename if that file is a directory.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 30 '16 at 15:50









                            Kusalananda

                            131k17249409




                            131k17249409










                            answered Dec 30 '16 at 15:31









                            Jamin ShantiJamin Shanti

                            1




                            1























                                -3














                                ls -G


                                this will show your directories in blue






                                share|improve this answer





















                                • 1





                                  Do you see only the directories when using this command ?

                                  – don_crissti
                                  Nov 1 '16 at 0:55


















                                -3














                                ls -G


                                this will show your directories in blue






                                share|improve this answer





















                                • 1





                                  Do you see only the directories when using this command ?

                                  – don_crissti
                                  Nov 1 '16 at 0:55
















                                -3












                                -3








                                -3







                                ls -G


                                this will show your directories in blue






                                share|improve this answer















                                ls -G


                                this will show your directories in blue







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Nov 1 '16 at 1:25









                                Jeff Schaller

                                41.7k1156133




                                41.7k1156133










                                answered Nov 1 '16 at 0:44









                                user197967user197967

                                1




                                1








                                • 1





                                  Do you see only the directories when using this command ?

                                  – don_crissti
                                  Nov 1 '16 at 0:55
















                                • 1





                                  Do you see only the directories when using this command ?

                                  – don_crissti
                                  Nov 1 '16 at 0:55










                                1




                                1





                                Do you see only the directories when using this command ?

                                – don_crissti
                                Nov 1 '16 at 0:55







                                Do you see only the directories when using this command ?

                                – don_crissti
                                Nov 1 '16 at 0:55




















                                draft saved

                                draft discarded




















































                                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.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f1645%2fis-there-any-option-with-ls-command-that-i-see-only-the-directories%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

                                宮崎県

                                濃尾地震

                                シテ島