Professional Web Applications Themes

what command to show number of folders - Linux / Unix Administration

Hi ! Can anyone tell me what command line syntax I would type to find out how many directories are in my system. Regards Tony...

  1. #1

    Default what command to show number of folders

    Hi !

    Can anyone tell me what command line syntax I would type to find out how
    many directories are in my system.

    Regards

    Tony
    Tony Guest

  2. #2

    Default Re: what command to show number of folders

    On Tue, 24 Jan 2006 15:45:02 +0000, Tony <com> wrote: 

    That's kind of a meaningless thing to want to do, but I'd look at the
    'find' command and the 'wc' command.

    Is this just personal curiousity, or what's the goal here?

    Dave Guest

  3. #3

    Default Re: what command to show number of folders

    On Tue, 24 Jan 2006 15:45:02 +0000, Tony wrote: 

    As a super user:

    find /// -type d -print | grep -c ///

    That may take a long time.

    On a linux system you can know the number of directories in the
    ext2/ext3 filesystems with the "stats" debugfs command.

    echo stats | debugfs /dev/hda3 | grep Directories

    (if there's an ext2 filesystem on /dev/hda3) for instance.

    --
    Stephane
    Stephane Guest

  4. #4

    Default Re: what command to show number of folders

    Stephane Chazelas wrote: 
    >
    > As a super user:
    >
    > find /// -type d -print | grep -c ///[/ref]

    That is a unique solution, especially compared to:

    find / -type d -print | wc -l

    Or, if you must use grep:

    find / -type d -print | grep -c .

    - Logan
    Logan Guest

  5. #5

    Default Re: what command to show number of folders

    2006-01-24, 16:11(+00), Logan Shaw: 
    >>
    >> As a super user:
    >>
    >> find /// -type d -print | grep -c ///[/ref]
    >
    > That is a unique solution, especially compared to:
    >
    > find / -type d -print | wc -l[/ref]
    [...]

    Yours fails as the multiline file paths will count for
    several files.

    --
    Stéphane
    Stephane Guest

  6. #6

    Default Re: what command to show number of folders

    Stephane CHAZELAS wrote: 
    >> That is a unique solution, especially compared to:
    >>
    >> find / -type d -print | wc -l[/ref]
    > [...]
    >
    > Yours fails as the multiline file paths will count for
    > several files.[/ref]

    I suppose you're right. I don't know why anyone should want
    to create directories with newlines in the names, but I agree
    it is possible.

    - Logan
    Logan Guest

  7. #7

    Default Re: what command to show number of folders

    On Tue, 24 Jan 2006 16:40:46 +0000, Stephane CHAZELAS <invalid> wrote: 
     [/ref]
     

    Can you give an example of a "multiline file path" please? I'm not
    aware of such a thing.

    Dave Guest

  8. #8

    Default Re: what command to show number of folders

    Stephane CHAZELAS wrote: 
    >
    > Yours fails as the multiline file paths will count for
    > several files.[/ref]

    If someone's managing to create directories with newlines
    embedded inside the filename, they pretty much desire
    inaccurate data.

    For that matter using find to count the directories on the
    entire system gives a nearly meaningless number. Usefull
    on a system that should never have new dirs created
    but that's about it.

    Doug Guest

  9. #9

    Default Re: what command to show number of folders

    2006-01-24, 19:28(+00), Dave Hinz: 
    > [/ref]

    >
    > Can you give an example of a "multiline file path" please? I'm not
    > aware of such a thing.[/ref]

    mkdir 'My Holiday Pictures
    July 2005'

    The only forbidden byte in a file path is 0 (and 47 ('/' in
    ASCII) is the path component separator).

    --
    Stéphane
    Stephane Guest

  10. #10

    Default Re: what command to show number of folders

    On Tue, 24 Jan 2006 20:21:07 +0000, Stephane CHAZELAS <invalid> wrote: 
     [/ref]
     

    My, what an astonishingly unwise directory name. Who in their right
    mind would go out of their way do to such a thing?
     

    Well then, as someone else said, they deserve to get incorrect answers
    for this meaningless exercise.

    Dave Guest

  11. #11

    Default Re: what command to show number of folders

    Dave Hinz <net> writes:
     [/ref]
     

    *shrug* It's not their fault that a) management asked for some
    silly information and b) their users are evil.

    - Tim Skirvin (org)
    --
    http://www.killfile.org/~tskirvin/ Skirv's Homepage <FISH>< <*>
    http://www.killfile.org/~tskirvin/moderate/ Skirv's Moderation
    Tim Guest

  12. #12

    Default Re: what command to show number of folders

    2006-01-24, 20:37(+00), Dave Hinz: 
    > [/ref]

    >
    > My, what an astonishingly unwise directory name. Who in their right
    > mind would go out of their way do to such a thing?[/ref]

    One never knows, maybe people who don't know it may break poorly
    written scripts ;). See how many people started writing
    filenames with spaces when Microsoft removed their 8.3 filename
    limitations.

    There should be a couple of those on most machines I've used,
    left after some tests for some scripts I wrote.

    There are the cases of filenames created after someone
    inadvertently copy pasted a mail message at a shell prompt.

    If I paste:
     

    at a shell prompt, it will run the "sure?" command with its
    output redirected to a file called "Thats interesting\nYoure"

    --
    Stéphane
    Stephane Guest

  13. #13

    Default Re: what command to show number of folders

    On Tue, 24 Jan 2006 14:52:51 -0600, Tim Skirvin <org> wrote: [/ref]

    >
    > *shrug* It's not their fault that a) management asked for some
    > silly information and b) their users are evil.[/ref]

    In which case, the managers won't (a) know, (b) understand, or (c) care
    that the count is off by a few because someone created a strange
    directory name.

    Dave Guest

  14. #14

    Default Re: what command to show number of folders

    Stephane CHAZELAS wrote: [/ref]
    > [/ref][/ref]

    Probably better done by using a backslash to quote the NL.
     
    >
    > One never knows, maybe people who don't know it may break poorly
    > written scripts ;). See how many people started writing
    > filenames with spaces when Microsoft removed their 8.3 filename
    > limitations.[/ref]

    Which doesn't answer the question about who's in their right
    mind andwho isn't. I've had to deal with Mac and PC folks
    using PCNFS and such to share NFS. There's quite a mess
    trying to writes scripts that do the right thing to files with any
    of the types of quote characters. It's bad enough dealing with
    spaces and tabs, but ticks or newlines will break nearly any
    automation.
     
    >
    > at a shell prompt, it will run the "sure?" command with its
    > output redirected to a file called "Thats interesting\nYoure"[/ref]

    And then you'd need some amount of savvy to know how to delete
    it with "rm -i T*" or whatever. Sure. I've found plenty of sysadmins
    who don't bother deleting files that have backspaces or escape
    sequences or whatever in their names because so little is gained
    for the effort. Shrug.

    It still doesn't make it worth the effort to fix the find|wc command
    to returns an exactly correct number. For an exactly correct
    number you'll want a process that detects various types of
    inaccessable directories. Maybe you've unlinked a directory
    tree and haven't run fsck yet. Maybe you mounted a filesystem
    over a non-empty directory tree (I rather like a tiny /usr on some
    systems). There are several ways that find won't work. Another
    post mentioned fsdb or similar filesystem dumping tools for that.

    Doug Guest

  15. #15

    Default Re: what command to show number of folders

    Dave Hinz <net> writes:
     
    >> *shrug* It's not their fault that a) management asked for some
    >> silly information and b) their users are evil.[/ref]
    >In which case, the managers won't (a) know, (b) understand, or (c) care
    >that the count is off by a few because someone created a strange
    >directory name.[/ref]

    *shrug* Accuracy is always a nice thing, regardless. It seems
    like the original grep-based solution should be a nice thing to keep in my
    script toolbox.

    - Tim Skirvin (org)
    --
    http://www.killfile.org/~tskirvin/ Skirv's Homepage <FISH>< <*>
    http://www.killfile.org/~tskirvin/buttons/ Skirv's Buttons
    Tim Guest

  16. #16

    Default Re: what command to show number of folders

    On 2006-01-24, Doug Freyburger wrote: 
    >> [/ref]
    >
    > Probably better done by using a backslash to quote the NL.[/ref]

    Better not done at all, of course, but a backslash would add a
    backslash to the name of the directory.

    --
    Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence
    Chris Guest

  17. #17

    Default Re: what command to show number of folders

    Logan Shaw wrote: 
    > > [...]
    > > Yours fails as the multiline file paths will count for
    > > several files.[/ref]
    > I suppose you're right. I don't know why anyone should want
    > to create directories with newlines in the names, but I agree
    > it is possible.[/ref]

    Many users, most commonly by accident, manage to create quite
    interesting names for files and directories - including newlines,
    blanks, tabs, control characters, names starting with . or -, shell
    metacharacters, directory hierarchies so deep rm -rf fails to remove
    them (at least on some platforms), and other 'exciting' stuff.

    Michael Guest

  18. #18

    Default Re: what command to show number of folders

    Dave Hinz wrote: 
    >
    >
    > That's kind of a meaningless thing to want to do, but I'd look at the
    > 'find' command and the 'wc' command.
    >
    > Is this just personal curiousity, or what's the goal here?
    >[/ref]
    I have some backup software on my system that is giving errors. Tech
    support for the backup software have asked the question and I didn't
    know how to produce the answer.

    regards

    tony
    Tony Guest

  19. #19

    Default Re: what command to show number of folders

    2006-01-24, 13:45(-08), Doug Freyburger: 
    >> [/ref]
    >
    > Probably better done by using a backslash to quote the NL.[/ref]

    Not as long as your shell is Bourne like, or you want to include
    a backslash.
     
    >>
    >> One never knows, maybe people who don't know it may break poorly
    >> written scripts ;). See how many people started writing
    >> filenames with spaces when Microsoft removed their 8.3 filename
    >> limitations.[/ref]
    >
    > Which doesn't answer the question about who's in their right
    > mind andwho isn't. I've had to deal with Mac and PC folks
    > using PCNFS and such to share NFS. There's quite a mess
    > trying to writes scripts that do the right thing to files with any
    > of the types of quote characters. It's bad enough dealing with
    > spaces and tabs, but ticks or newlines will break nearly any
    > automation.[/ref]

    There's no reason why ticks should. It's true that newlines are
    a big problem. The system can cope with them but the user space
    applications often don't.
     
    >>
    >> at a shell prompt, it will run the "sure?" command with its
    >> output redirected to a file called "Thats interesting\nYoure"[/ref]
    >
    > And then you'd need some amount of savvy to know how to delete
    > it with "rm -i T*" or whatever.[/ref]

    ???

    With a proper shell, you type rm T<Tab>, which the shell should
    expand properly. Here with zsh, it does:

    $ rm Thats\ interesting'
    '\>\ Youre

    And if I start with rm "T<Tab>

    $ rm "Thats interesting 


    [...] 

    But what you are talking about are pathological cases, for which
    one can't do anything about. The UNIX API allows any user to
    create a filename with a newline, it's not supposed to allow a
    user to corrupt a filesystem.

    If find doesn't work because root doesn't have read access on a
    NFS shared filesystem (though find will report it) or because
    the file system is corrupted... then no other user space command
    will be able to read those directories either. So find will give
    the number of directories that can possibly be given.

    debugfs will give a different answer, but that answer will not
    necessarily be more useful.

    In any case, counting the multiline paths several time is a flaw
    in the script that calls find, not in find nor the filesystem.

    --
    Stéphane
    Stephane Guest

Similar Threads

  1. Does MS Access have a Show Columns SQL command
    By UpstateWeb in forum Coldfusion Database Access
    Replies: 1
    Last Post: October 26th, 04:49 PM
  2. Show all command in AICS
    By Isaiah_Sailer@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 2
    Last Post: June 14th, 01:58 PM
  3. Replies: 4
    Last Post: October 9th, 02:53 PM
  4. Folders associated with actions won't show Folder is Empty in XP
    By dave milbut in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 6
    Last Post: August 6th, 09:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139